x11: Only correct placement for border offset on the initial window mapping

Correcting it when it is subsequently hidden and re-mapped will cause the position to be double offset by the size of the borders.
This commit is contained in:
Frank Praznik
2025-11-06 19:01:50 -05:00
parent 2a873be9cd
commit a71b2f0a93

View File

@@ -1550,6 +1550,11 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool set_position = false;
XEvent event;
// If the window was previously shown, pump events to avoid possible positioning issues.
if (data->was_shown) {
X11_PumpEvents(_this);
}
if (SDL_WINDOW_IS_POPUP(window)) {
// Update the position in case the parent moved while we were hidden
X11_ConstrainPopup(window, true);
@@ -1592,14 +1597,12 @@ void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
if (set_position) {
// Apply the window position, accounting for offsets due to the borders appearing.
const int tx = data->pending_position ? window->pending.x : window->x;
const int ty = data->pending_position ? window->pending.y : window->y;
// Apply the window position, accounting for offsets due to the borders appearing, but only when initially mapping.
const int tx = (data->pending_position ? window->pending.x : window->x) - (data->was_shown ? 0 : data->border_left);
const int ty = (data->pending_position ? window->pending.y : window->y) - (data->was_shown ? 0 : data->border_top);
int x, y;
SDL_RelativeToGlobalForWindow(window,
tx - data->border_left, ty - data->border_top,
&x, &y);
SDL_RelativeToGlobalForWindow(window, tx, ty, &x, &y);
data->pending_position = false;
X11_XMoveWindow(display, data->xwindow, x, y);