x11: Wait a bit in SDL_SetWindowSize() to see if window manager vetoed change.
authorRyan C. Gordon
Mon, 17 Feb 2020 16:11:18 -0500
changeset 13535dbcccb065928
parent 13534 24e8a27fa627
child 13536 4ba421b1e88f
x11: Wait a bit in SDL_SetWindowSize() to see if window manager vetoed change.

Same idea as the fix for Bugzilla #4646.

Fixes Bugzilla #4727.
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11window.c	Mon Feb 17 15:02:37 2020 -0500
     1.2 +++ b/src/video/x11/SDL_x11window.c	Mon Feb 17 16:11:18 2020 -0500
     1.3 @@ -910,6 +910,14 @@
     1.4  {
     1.5      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     1.6      Display *display = data->videodata->display;
     1.7 +    XWindowAttributes attrs;
     1.8 +    int orig_w, orig_h;
     1.9 +    Uint32 timeout;
    1.10 +
    1.11 +    X11_XSync(display, False);
    1.12 +    X11_XGetWindowAttributes(display, data->xwindow, &attrs);
    1.13 +    orig_w = attrs.width;
    1.14 +    orig_h = attrs.height;
    1.15  
    1.16      if (SDL_IsShapedWindow(window)) {
    1.17          X11_ResizeWindowShape(window);
    1.18 @@ -953,7 +961,27 @@
    1.19          X11_XResizeWindow(display, data->xwindow, window->w, window->h);
    1.20      }
    1.21  
    1.22 -    X11_XFlush(display);
    1.23 +    /* Wait a brief time to see if the window manager decided to let this resize happen.
    1.24 +       If the window changes at all, even to an unexpected value, we break out. */
    1.25 +    timeout = SDL_GetTicks() + 100;
    1.26 +    while (SDL_TRUE) {
    1.27 +        X11_XSync(display, False);
    1.28 +        X11_XGetWindowAttributes(display, data->xwindow, &attrs);
    1.29 +
    1.30 +        if ((attrs.width != orig_w) || (attrs.height != orig_h)) {
    1.31 +            window->w = attrs.width;
    1.32 +            window->h = attrs.height;
    1.33 +            break;  /* window changed, time to go. */
    1.34 +        } else if ((attrs.width == window->w) && (attrs.height == window->h)) {
    1.35 +            break;  /* we're at the place we wanted to be anyhow, drop out. */
    1.36 +        }
    1.37 +
    1.38 +        if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
    1.39 +            break;
    1.40 +        }
    1.41 +
    1.42 +        SDL_Delay(10);
    1.43 +    }
    1.44  }
    1.45  
    1.46  int