Fixed bug 1526 - X11 - XUnmapWindow should not be called directly
authorSam Lantinga <slouken@libsdl.org>
Sat, 27 Jul 2013 00:49:34 -0700
changeset 7522 b186724247dd
parent 7521 03bca9a4180d
child 7523 9e9ab1dc3811
Fixed bug 1526 - X11 - XUnmapWindow should not be called directly driedfruit In X11_HideWindow, we call XUnmapWindow to unmap. According to ICCCN2.0, this should never happen, and XWithdrawWindow should be called instead. http://www.tronche.com/gui/x/icccm/sec-4.html#s-4.1.4 "The reason for requiring the client to send a synthetic UnmapNotify event is to ensure that the window manager gets some notification of the client's desire to change state, ***even though the window may already be unmapped when the desire is expressed***." Additionally, this can be observed at http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/Withdraw.c#n65 Failure to comply leads to "MapNotify" event never appearing on non-reparenting WMs after subsequent show-hide-show requests. (I'm currently observing this behavior, thus my bug report).
src/video/x11/SDL_x11messagebox.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11window.c
--- a/src/video/x11/SDL_x11messagebox.c	Fri Jul 26 13:30:24 2013 -0700
+++ b/src/video/x11/SDL_x11messagebox.c	Sat Jul 27 00:49:34 2013 -0700
@@ -78,11 +78,11 @@
     const char *text;                   /* Text for this line */
 } TextLineData;
 
-typedef struct SDL_MessageBoxDataX11 {
-    XFontSet font_set;                  /* for UTF-8 systems */
-    XFontStruct *font_struct;            /* Latin1 (ASCII) fallback. */
+typedef struct SDL_MessageBoxDataX11
+{
+    Display *display;
+    int screen;
     Window window;
-    Display *display;
     long event_mask;
     Atom wm_protocols;
     Atom wm_delete_message;
@@ -90,6 +90,8 @@
     int dialog_width;                   /* Dialog box width. */
     int dialog_height;                  /* Dialog box height. */
 
+    XFontSet font_set;                  /* for UTF-8 systems */
+    XFontStruct *font_struct;           /* Latin1 (ASCII) fallback. */
     int xtext, ytext;                   /* Text position to start drawing at. */
     int numlines;                       /* Count of Text lines. */
     int text_height;                    /* Height for text lines. */
@@ -347,7 +349,7 @@
 
     if ( data->display ) {
         if ( data->window != None ) {
-            XUnmapWindow( data->display, data->window );
+            XWithdrawWindow( data->display, data->window, data->screen );
             XDestroyWindow( data->display, data->window );
             data->window = None;
         }
@@ -369,7 +371,12 @@
     const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
 
     if ( messageboxdata->window ) {
+        SDL_DisplayData *displaydata =
+            (SDL_DisplayData *) SDL_GetDisplayForWindow(messageboxdata->window)->driverdata;
         windowdata = (SDL_WindowData *)messageboxdata->window->driverdata;
+        data->screen = displaydata->screen;
+    } else {
+        data->screen = DefaultScreen( display );
     }
 
     data->event_mask = ExposureMask |
@@ -378,7 +385,7 @@
     wnd_attr.event_mask = data->event_mask;
 
     data->window = XCreateWindow(
-                       display, DefaultRootWindow( display ),
+                       display, RootWindow(display, data->screen),
                        0, 0,
                        data->dialog_width, data->dialog_height,
                        0, CopyFromParent, InputOutput, CopyFromParent,
@@ -406,11 +413,10 @@
         XGetWindowAttributes(display, windowdata->xwindow, &attrib);
         x = attrib.x + ( attrib.width - data->dialog_width ) / 2;
         y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
-        XTranslateCoordinates(display, windowdata->xwindow, DefaultRootWindow( display ), x, y, &x, &y, &dummy);
+        XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
     } else {
-        int screen = DefaultScreen( display );
-        x = ( DisplayWidth( display, screen ) - data->dialog_width ) / 2;
-        y = ( DisplayHeight( display, screen ) - data->dialog_height ) / 3 ;
+        x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
+        y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
     }
     XMoveWindow( display, data->window, x, y );
 
--- a/src/video/x11/SDL_x11sym.h	Fri Jul 26 13:30:24 2013 -0700
+++ b/src/video/x11/SDL_x11sym.h	Sat Jul 27 00:49:34 2013 -0700
@@ -125,9 +125,9 @@
 SDL_X11_SYM(int,XUngrabServer,(Display* a),(a),return)
 SDL_X11_SYM(int,XUninstallColormap,(Display* a,Colormap b),(a,b),return)
 SDL_X11_SYM(int,XUnloadFont,(Display* a,Font b),(a,b),return)
-SDL_X11_SYM(int,XUnmapWindow,(Display* a,Window b),(a,b),return)
 SDL_X11_SYM(int,XWarpPointer,(Display* a,Window b,Window c,int d,int e,unsigned int f,unsigned int g,int h,int i),(a,b,c,d,e,f,g,h,i),return)
 SDL_X11_SYM(int,XWindowEvent,(Display* a,Window b,long c,XEvent* d),(a,b,c,d),return)
+SDL_X11_SYM(Status,XWithdrawWindow,(Display* a,Window b,int c),(a,b,c),return)
 SDL_X11_SYM(VisualID,XVisualIDFromVisual,(Visual* a),(a),return)
 #if SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY
 SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f),(a,b,c,d,e,f),return)
--- a/src/video/x11/SDL_x11window.c	Fri Jul 26 13:30:24 2013 -0700
+++ b/src/video/x11/SDL_x11window.c	Sat Jul 27 00:49:34 2013 -0700
@@ -853,11 +853,12 @@
 X11_HideWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->videodata->display;
     XEvent event;
 
     if (X11_IsWindowMapped(_this, window)) {
-        XUnmapWindow(display, data->xwindow);
+        XWithdrawWindow(display, data->xwindow, displaydata->screen);
         /* Blocking wait for "UnmapNotify" event */
         XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
         XFlush(display);
@@ -1146,7 +1147,7 @@
     SetWindowBordered(display, screen, data->xwindow,
                       (window->flags & SDL_WINDOW_BORDERLESS) == 0);
 
-    XUnmapWindow(display, fswindow);
+    XWithdrawWindow(display, fswindow, screen);
 
     /* Wait to be unmapped. */
     XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&fswindow);