diff -ur old/src/video/x11/SDL_x11modes.c new/src/video/x11/SDL_x11modes.c --- old/src/video/x11/SDL_x11modes.c 2009-10-13 10:07:15.000000000 +1100 +++ new/src/video/x11/SDL_x11modes.c 2011-07-14 16:28:43.000000000 +1000 @@ -315,22 +315,30 @@ *h = DisplayHeight(SDL_Display, SDL_Screen); } +static Bool isMapNotify(Display *dpy, XEvent *ev, XPointer win) +{ + return ev->type == MapNotify && ev->xmap.window == *((Window*)win); +} + +static Bool isUnmapNotify(Display *dpy, XEvent *ev, XPointer win) +{ + return ev->type == UnmapNotify && ev->xunmap.window == *((Window*)win); +} + /* Called after mapping a window - waits until the window is mapped */ void X11_WaitMapped(_THIS, Window win) { XEvent event; - do { - XMaskEvent(SDL_Display, StructureNotifyMask, &event); - } while ( (event.type != MapNotify) || (event.xmap.event != win) ); + /* We use XIfEvent because XWindowEvent takes a mask rather than a type, + * and XCheckTypedWindowEvent doesn't block */ + XIfEvent(SDL_Display, &event, &isMapNotify, (XPointer) &win); } /* Called after unmapping a window - waits until the window is unmapped */ void X11_WaitUnmapped(_THIS, Window win) { XEvent event; - do { - XMaskEvent(SDL_Display, StructureNotifyMask, &event); - } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) ); + XIfEvent(SDL_Display, &event, &isUnmapNotify, (XPointer) &win); } static void move_cursor_to(_THIS, int x, int y) diff -ur old/src/video/x11/SDL_x11sym.h new/src/video/x11/SDL_x11sym.h --- old/src/video/x11/SDL_x11sym.h 2009-10-13 10:07:15.000000000 +1100 +++ new/src/video/x11/SDL_x11sym.h 2011-07-13 20:46:24.000000000 +1000 @@ -62,6 +62,7 @@ SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return) SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return) SDL_X11_SYM(Status,XIconifyWindow,(Display* a,Window b,int c),(a,b,c),return) +SDL_X11_SYM(int,XIfEvent,(Display* a,XEvent *b,Bool (*c)(Display*,XEvent*,XPointer),XPointer d),(a,b,c,d),return) SDL_X11_SYM(int,XInstallColormap,(Display* a,Colormap b),(a,b),return) SDL_X11_SYM(KeyCode,XKeysymToKeycode,(Display* a,KeySym b),(a,b),return) SDL_X11_SYM(Atom,XInternAtom,(Display* a,_Xconst char* b,Bool c),(a,b,c),return)