From a71b2f0a9331e47db6969751745a4f313692a674 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 6 Nov 2025 19:01:50 -0500
Subject: [PATCH] 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.
---
src/video/x11/SDL_x11window.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index b78cca9080985..375d471a19e4a 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -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);