[SDL] Problem filtering events (from another application's thread?)
Eric Kort
eric.kort at vai.org
Mon Jun 5 19:31:59 PDT 2006
I think I figured out my problem...I have no main event loop (pretty
obvious in retrospect)! So the events were getting queued up, and I
could access them with SDL_PollEvent the next time the user entered a
command from my library. Since I wanted real time event processing for
repaints, resizes, etc., I created a separate event processing thread
with SDL_CreateThread which polls for events and is started by my
sdlOpen function. This thread then runs along side R's application
thread and catches events in real time.
-Eric
On Mon, 2006-06-05 at 17:16 -0400, Kort, Eric wrote:
> Hello. I am trying to write an image viewer library for the R framework
> (www.r-project.org) based on SDL (which I call "rsdl"). (R has rich
> graphics plotting capabilities, but rendering large-ish images is quite
> slow).
>
> I am able to display an image loaded in R in an SDL window without any
> problem. This is via a shared library which R loads (when I load my
> rsdl library within R), containing the SDL related code ("rsdl.so"). My
> problem is that I am not able to filter events. From within R I call an
> sdl.open() function which in turn calls the sdlOpen symbol defined in
> the shared library. The sdlOpen function creates the SDL window, and
> installs an event filter like this:
>
> ...
> screen = SDL_SetVideoMode(INTEGER(w)[0], INTEGER(h)[0], 32,
>
> SDL_SWSURFACE|SDL_ANYFORMAT|SDL_RESIZABLE);
> SDL_EventState(SDL_KEYDOWN, SDL_IGNORE);
> SDL_EventState(SDL_KEYUP, SDL_IGNORE);
> SDL_EventState(SDL_VIDEORESIZE, SDL_ENABLE);
> printf("events enabled...\n");
> SDL_SetEventFilter((SDL_EventFilter)filterEvents);
> ...
>
> But the filter never gets (visibly) triggered. Here is my filter:
>
> int filterEvents(SDL_Event *event) {
> printf("Caught Event...");
> if (event->type == SDL_VIDEOEXPOSE) {
> printf("Screen needs refresh...");
> SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
> return(0);
> }
> if (event->type == SDL_VIDEORESIZE) {
> printf("Resizing...");
> if (paint)
> repaint();
> SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
> return(0);
> }
> return(1);
> }
>
> When I click in the window or resize it, I never see the "Caught event"
> message, and it is apparent from subsequent rendering that the program
> still thinks the window is its original size.
>
> My sense is that the problem is that the window was created from another
> thread (R's thread), and I am not able to filter events from that
> thread. Is it apparent to anyone how I might work around this?
>
> Thanks,
> Eric
>
> This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message. Thank you.
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message. Thank you.
More information about the SDL
mailing list