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 7632d6a8fa507a45
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
     1.1 --- a/src/video/x11/SDL_x11window.c	Sat Aug 10 23:21:06 2013 +0200
     1.2 +++ b/src/video/x11/SDL_x11window.c	Sun Aug 11 19:56:43 2013 -0700
     1.3 @@ -59,6 +59,21 @@
     1.4      return ev->type == ConfigureNotify && ev->xconfigure.window == *((Window*)win);
     1.5  }
     1.6  
     1.7 +/*
     1.8 +static Bool
     1.9 +XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
    1.10 +{
    1.11 +    Uint32 start = SDL_GetTicks();
    1.12 +
    1.13 +    while (!XCheckIfEvent(display, event_return, predicate, arg)) {
    1.14 +        if ((SDL_GetTicks() - start) >= timeoutMS) {
    1.15 +            return False;
    1.16 +        }
    1.17 +    }
    1.18 +    return True;
    1.19 +}
    1.20 +*/
    1.21 +
    1.22  static SDL_bool
    1.23  X11_IsWindowLegacyFullscreen(_THIS, SDL_Window * window)
    1.24  {
    1.25 @@ -1150,6 +1165,9 @@
    1.26      XReparentWindow(display, data->xwindow, data->fswindow,
    1.27                      (rect.w - window->w) / 2, (rect.h - window->h) / 2);
    1.28  
    1.29 +    /* Move the mouse to the upper left to make sure it's on-screen */
    1.30 +    XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
    1.31 +
    1.32      /* Center mouse in the fullscreen window. */
    1.33      rect.x += (rect.w / 2);
    1.34      rect.y += (rect.h / 2);
    1.35 @@ -1190,8 +1208,9 @@
    1.36      XReparentWindow(display, data->xwindow, root, window->x, window->y);
    1.37  
    1.38      /* flush these events so they don't confuse normal event handling */
    1.39 -    XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
    1.40 -    XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
    1.41 +    XSync(display, False);
    1.42 +    XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
    1.43 +    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
    1.44  
    1.45      SetWindowBordered(display, screen, data->xwindow,
    1.46                        (window->flags & SDL_WINDOW_BORDERLESS) == 0);