Using select() on X11 display?

in our “new” case (i.e. current software architecture), only one
thread is talking to the display (X or XIL or SDL or …). We call
it the display thread. The thread in which we were doing the select and
listening
for display events is another thread. select is done using the fd
corresponding to the Display that was opened by the display thread.

Be the thread that will actually READ the X event is the display thread.
The select only listen to the fd, and if there is something to read,
the select exist and the display thread is notified, so it works…

Got it. Okay, you can actually do this using the current SDL API.
It’s only supported on X11, but that shouldn’t be a problem for you.

#include “SDL_syswm.h”

static int x11_fd;

/* After initializing SDL… */
SDL_SysWMinfo info;

/* Grab the window manager specific information */
SDL_VERSION(&info.version);
if ( SDL_GetWMInfo(&info) < 0 ) {
return(-1);
}
x11_fd = ConnectionNumber(info.display);

/* Now you can call select() on x11_fd */

Note that select() will return ready for every unhandled X11 protocol
transaction. SDL_GetWMInfo() should be thread-safe as well.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/