Fixed issue with tiling window managers (bug 1246)
authorSam Lantinga <slouken@libsdl.org>
Thu, 21 Jun 2012 09:58:22 -0400
changeset 6336 6e6163b6ba69
parent 6335 fbb84f5b985f
child 6337 3c91a153f398
Fixed issue with tiling window managers (bug 1246) Patch contributed by Driedfruit - thanks!
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11window.c
--- a/src/video/x11/SDL_x11sym.h	Wed Jun 20 11:25:40 2012 -0300
+++ b/src/video/x11/SDL_x11sym.h	Thu Jun 21 09:58:22 2012 -0400
@@ -59,6 +59,7 @@
 SDL_X11_SYM(int,XGetWindowProperty,(Display* a,Window b,Atom c,long d,long e,Bool f,Atom g,Atom* h,int* i,unsigned long* j,unsigned long *k,unsigned char **l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
 SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
 SDL_X11_SYM(Status,XGetWMNormalHints,(Display *a,Window b, XSizeHints *c, long *d),(a,b,c,d),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,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(int,XGrabServer,(Display* a),(a),return)
--- a/src/video/x11/SDL_x11window.c	Wed Jun 20 11:25:40 2012 -0300
+++ b/src/video/x11/SDL_x11window.c	Thu Jun 21 09:58:22 2012 -0400
@@ -765,13 +765,27 @@
     XFlush(display);
 }
 
+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);
+}
+
 void
 X11_ShowWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
+    XEvent event;
 
     XMapRaised(display, data->xwindow);
+    /* Blocking wait for "MapNotify" event.
+     * We use XIfEvent because XWindowEvent takes a mask rather than a type, 
+     * and XCheckTypedWindowEvent doesn't block */
+    XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
     XFlush(display);
 }
 
@@ -780,8 +794,11 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
+    XEvent event;
 
     XUnmapWindow(display, data->xwindow);
+    /* Blocking wait for "UnmapNotify" event */
+    XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);    
     XFlush(display);
 }