diff --git a/WindowManager.lua b/WindowManager.lua index 6149430..98e2148 100644 --- a/WindowManager.lua +++ b/WindowManager.lua @@ -211,8 +211,8 @@ function obj.rescueWindowsToLaptop() if f.w > maxFrame.w then f.w = maxFrame.w - 100 end if f.h > maxFrame.h then f.h = maxFrame.h - 100 end - f.x = maxFrame.x + 50 + staggerOffset - f.y = maxFrame.y + 50 + staggerOffset + f.x = maxFrame.x + staggerOffset + f.y = maxFrame.y + staggerOffset win:setFrame(f, 0) staggerOffset = staggerOffset + 30 @@ -276,7 +276,9 @@ obj.powerWatcher = hs.caffeinate.watcher.new(function(event) elseif event == hs.caffeinate.watcher.systemDidWake or event == hs.caffeinate.watcher.screensDidWake or event == hs.caffeinate.watcher.screensDidUnlock then log("POWER: Wake event.") obj.saveCountdown = obj.saveInterval - obj.isMenuUpdating = false -- Explicitly clean guard flag upon waking up + obj.isMenuUpdating = false + obj.isTransitioning = false + obj.isRestoring = false -- Safely start timers up only after wakeup initialization if obj.autoSaveTimer then obj.autoSaveTimer:start() end @@ -294,9 +296,13 @@ obj.powerWatcher = hs.caffeinate.watcher.new(function(event) obj.wakeTimer = nil end) else - log("WAKE SKIP: Single screen detected. Syncing count only.") - obj.isTransitioning = false - obj.isRestoring = false + -- Only run rescue if the state actually dropped from multi-monitor down to single monitor during sleep + if obj.lastScreenCount > 1 then + log("WAKE ACTIVATE: Screen count dropped from " .. obj.lastScreenCount .. " to 1 during sleep. Running rescue.") + obj.rescueWindowsToLaptop() + else + log("WAKE SKIP: Woke up on single screen, matched previous state. No rescue needed.") + end obj.lastScreenCount = currentScreens updateMenu() end