x11: Attempt to wait for SDL_MaximizeWindow to complete before returning. Fixes #7070.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 5b575f2..dd93514 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -1263,8 +1263,25 @@ static void SetWindowMaximized(_THIS, SDL_Window *window, SDL_bool maximized)
}
if (X11_IsWindowMapped(_this, window)) {
+ /* !!! FIXME: most of this waiting code is copy/pasted from elsewhere. */
+ int (*prev_handler)(Display *, XErrorEvent *) = NULL;
+ XWindowAttributes attrs;
+ Window childReturn, root, parent;
+ Window *children;
+ unsigned int childCount;
+ int orig_w, orig_h, orig_x, orig_y;
+ int x, y;
+ Uint64 timeout;
XEvent e;
+ X11_XSync(display, False);
+ X11_XQueryTree(display, data->xwindow, &root, &parent, &children, &childCount);
+ X11_XGetWindowAttributes(display, data->xwindow, &attrs);
+ X11_XTranslateCoordinates(display, parent, DefaultRootWindow(display),
+ attrs.x, attrs.y, &orig_x, &orig_y, &childReturn);
+ orig_w = attrs.width;
+ orig_h = attrs.height;
+
SDL_zero(e);
e.xany.type = ClientMessage;
e.xclient.message_type = _NET_WM_STATE;
@@ -1278,6 +1295,40 @@ static void SetWindowMaximized(_THIS, SDL_Window *window, SDL_bool maximized)
X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
+
+ /* Wait a brief time to see if the window manager decided to let this happen.
+ If the window changes at all, even to an unexpected value, we break out. */
+ X11_XSync(display, False);
+ prev_handler = X11_XSetErrorHandler(X11_CatchAnyError);
+
+ timeout = SDL_GetTicks64() + 1000;
+ while (SDL_TRUE) {
+ caught_x11_error = SDL_FALSE;
+ X11_XSync(display, False);
+ X11_XGetWindowAttributes(display, data->xwindow, &attrs);
+ X11_XTranslateCoordinates(display, parent, DefaultRootWindow(display),
+ attrs.x, attrs.y, &x, &y, &childReturn);
+
+ if (!caught_x11_error) {
+ if ((x != orig_x) || (y != orig_y) || (attrs.width != orig_w) || (attrs.height != orig_h)) {
+ break; /* window changed, time to go. */
+ }
+ }
+
+ if (SDL_GetTicks64() >= timeout) {
+ break;
+ }
+
+ SDL_Delay(10);
+ }
+
+ if (!caught_x11_error) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, attrs.width, attrs.height);
+ }
+
+ X11_XSetErrorHandler(prev_handler);
+ caught_x11_error = SDL_FALSE;
} else {
X11_SetNetWMState(_this, data->xwindow, window->flags);
}