Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}
NSWindow.allowsAutomaticWindowTabbing = false
// Disable macOS system window restoration to prevent duplicate windows
// when external displays are disconnected/reconnected (#1802).
// The app uses its own SessionPersistenceStore for window state.
UserDefaults.standard.set(false, forKey: "NSQuitAlwaysKeepsWindows")
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
disableNativeTabbingShortcut()
ensureApplicationIcon()
if !isRunningUnderXCTest {
Expand Down Expand Up @@ -3304,6 +3308,21 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
}
}
lifecycleSnapshotObservers.append(didWakeObserver)

// When an external display is disconnected/reconnected, macOS can trigger
// window restoration that creates duplicate windows (#1802). Save a snapshot
// so the session state stays consistent after the display topology change.
let screenChangeObserver = NotificationCenter.default.addObserver(
forName: NSApplication.didChangeScreenParametersNotification,
object: nil,
queue: .main
) { [weak self] _ in
Task { @MainActor [weak self] in
guard let self, !self.isTerminatingApp else { return }
_ = self.saveSessionSnapshot(includeScrollback: false)
}
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
}
lifecycleSnapshotObservers.append(screenChangeObserver)
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
}

private func socketListenerConfigurationIfEnabled() -> (mode: SocketControlMode, path: String)? {
Expand Down Expand Up @@ -3735,6 +3754,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
sidebarSelectionState: SidebarSelectionState
) {
tabManager.window = window
// Prevent macOS from restoring this window on display reconfiguration (#1802).
Comment thread
elvistranhere marked this conversation as resolved.
Resolved
window.isRestorable = false

let key = ObjectIdentifier(window)
#if DEBUG
Expand Down