x11: SDL_SetWindowPosition should try to wait for the window manager. Wait up to 100 milliseconds, since the window manager might alter or outright veto the window change...or not respond at all. In a well-functioning system, though, this should help make sure that SDL_SetWindowPosition's results match reality. Fixes Bugzilla #4646.
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
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 554da06..aae6925 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -809,20 +809,36 @@ X11_SetWindowPosition(_THIS, SDL_Window * window)
Window childReturn, root, parent;
Window* children;
XWindowAttributes attrs;
+ int orig_x, orig_y;
+ Uint32 timeout;
- /*Attempt to move the window*/
- X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
X11_XSync(display, False);
-
- /*If the window is not moved, then the coordinates on the window structure are out of sync, so we
- update them here. */
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,
- &window->x, &window->y,
- &childReturn);
+ X11_XTranslateCoordinates(display, parent, DefaultRootWindow(display),
+ attrs.x, attrs.y, &orig_x, &orig_y, &childReturn);
+
+ /*Attempt to move the window*/
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+
+ /* Wait a brief time to see if the window manager decided to let this move happen.
+ If the window changes at all, even to an unexpected value, we break out. */
+ timeout = SDL_GetTicks() + 100;
+ do {
+ int x, y;
+ X11_XSync(display, False);
+ X11_XGetWindowAttributes(display, data->xwindow, &attrs);
+ X11_XTranslateCoordinates(display, parent, DefaultRootWindow(display),
+ attrs.x, attrs.y, &x, &y, &childReturn);
+
+ if ((x != orig_x) || (y != orig_y)) {
+ window->x = x;
+ window->y = y;
+ break; /* window moved, time to go. */
+ }
+
+ SDL_Delay(10);
+ } while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout));
}
void