Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow() release-2.0.0
authorSam Lantinga <slouken@libsdl.org>
Sun, 11 Aug 2013 19:56:43 -0700
changeset 7632 d6a8fa507a45
parent 7631 9fcda7425ccc
child 7633 171a7ab71f28
child 8477 ad08f0d710f3
Fixed bug 2027 - Full-screen appears to be broken - hang in SDL_DestroyWindow()

Rainer Deyke

I'm running Linux Mint 15 with the Cinnamon window manager. SDL_DestroyWindow consistently locks up for me when the window if fullscreen.
src/video/x11/SDL_x11window.c
--- a/src/video/x11/SDL_x11window.c	Sat Aug 10 23:21:06 2013 +0200
+++ b/src/video/x11/SDL_x11window.c	Sun Aug 11 19:56:43 2013 -0700
@@ -59,6 +59,21 @@
     return ev->type == ConfigureNotify && ev->xconfigure.window == *((Window*)win);
 }
 
+/*
+static Bool
+XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
+{
+    Uint32 start = SDL_GetTicks();
+
+    while (!XCheckIfEvent(display, event_return, predicate, arg)) {
+        if ((SDL_GetTicks() - start) >= timeoutMS) {
+            return False;
+        }
+    }
+    return True;
+}
+*/
+
 static SDL_bool
 X11_IsWindowLegacyFullscreen(_THIS, SDL_Window * window)
 {
@@ -1150,6 +1165,9 @@
     XReparentWindow(display, data->xwindow, data->fswindow,
                     (rect.w - window->w) / 2, (rect.h - window->h) / 2);
 
+    /* Move the mouse to the upper left to make sure it's on-screen */
+    XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+
     /* Center mouse in the fullscreen window. */
     rect.x += (rect.w / 2);
     rect.y += (rect.h / 2);
@@ -1190,8 +1208,9 @@
     XReparentWindow(display, data->xwindow, root, window->x, window->y);
 
     /* flush these events so they don't confuse normal event handling */
-    XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
-    XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+    XSync(display, False);
+    XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
 
     SetWindowBordered(display, screen, data->xwindow,
                       (window->flags & SDL_WINDOW_BORDERLESS) == 0);