From 60a900be28adea31d0a17b792219f3773250ca25 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Sun, 22 Mar 2026 12:09:22 -0400 Subject: [PATCH] wmaker: make sure reloaded saved window position is in visible space This patch is checking if the session saved window positions fall in dead space, for example when a monitor no longer exists. If it's the case the window position is moved to the nearest active head. --- src/window.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/window.c b/src/window.c index 78b2271c..10949aa3 100644 --- a/src/window.c +++ b/src/window.c @@ -1051,8 +1051,28 @@ WWindow *wManageWindow(WScreen *scr, Window window) Bool dontBring = False; if (win_state && win_state->state->w > 0) { + WMRect rect; + int head, flags; + x = win_state->state->x; y = win_state->state->y; + + /* If the saved position falls in dead space (for example a monitor that no longer + * exists), clamp the window to the nearest active head. */ + rect.pos.x = x; + rect.pos.y = y; + rect.size.width = width; + rect.size.height = height; + + head = wGetRectPlacementInfo(scr, rect, &flags); + if (flags & XFLAG_DEAD) { + rect = wGetRectForHead(scr, head); + + x = rect.pos.x + (x * rect.size.width) / scr->scr_width; + y = rect.pos.y + (y * rect.size.height) / scr->scr_height; + + wScreenBringInside(scr, &x, &y, width, height); + } } else if ((wwin->transient_for == None || wPreferences.window_placement != WPM_MANUAL) && !scr->flags.startup && !wwin->flags.miniaturized