diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index c1681338a..16aff39a9 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -512,20 +512,23 @@ class BaseTerminalController: NSWindowController, // For fullscreen windows with tabs, force a relayout on all tabs. // After a monitor disconnect, the window frames become stale. Cycling - // through tabs fixes this, so we simulate that by ordering each window. + // through tabs fixes this, so we simulate that by changing the selected tab. if window.styleMask.contains(.fullScreen) { if let tabGroup = window.tabGroup, tabGroup.windows.count > 1 { DispatchQueue.main.async { - // Remember the current main window - let currentMain = window - - // Briefly make each background tab key to trigger layout recalculation - for tabWindow in tabGroup.windows where tabWindow != currentMain { - tabWindow.makeKeyAndOrderFront(nil) + // Remember the current selected window + let originalSelected = tabGroup.selectedWindow + + // Briefly select each tab to trigger layout recalculation + // Only cycle through tabs that have the fullscreen style mask + for tabWindow in tabGroup.windows where tabWindow != originalSelected && tabWindow.styleMask.contains(.fullScreen) { + tabGroup.selectedWindow = tabWindow + } + + // Restore the original selection + if let originalSelected { + tabGroup.selectedWindow = originalSelected } - - // Restore the original window as key - currentMain.makeKeyAndOrderFront(nil) } } return