mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
macOS: save frame only if the window is visible
This commit is contained in:
@@ -1171,27 +1171,21 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
||||
self.fixTabBar()
|
||||
|
||||
// Whenever we move save our last position for the next start.
|
||||
if let window {
|
||||
LastWindowPosition.shared.save(window)
|
||||
}
|
||||
LastWindowPosition.shared.save(window)
|
||||
}
|
||||
|
||||
override func windowDidResize(_ notification: Notification) {
|
||||
super.windowDidResize(notification)
|
||||
|
||||
// Whenever we resize save our last position and size for the next start.
|
||||
if let window {
|
||||
LastWindowPosition.shared.save(window)
|
||||
}
|
||||
LastWindowPosition.shared.save(window)
|
||||
}
|
||||
|
||||
func windowDidBecomeMain(_ notification: Notification) {
|
||||
// Whenever we get focused, use that as our last window position for
|
||||
// restart. This differs from Terminal.app but matches iTerm2 behavior
|
||||
// and I think its sensible.
|
||||
if let window {
|
||||
LastWindowPosition.shared.save(window)
|
||||
}
|
||||
LastWindowPosition.shared.save(window)
|
||||
|
||||
// Remember our last main
|
||||
Self.lastMain = self
|
||||
|
||||
@@ -6,10 +6,17 @@ class LastWindowPosition {
|
||||
|
||||
private let positionKey = "NSWindowLastPosition"
|
||||
|
||||
func save(_ window: NSWindow) {
|
||||
@discardableResult
|
||||
func save(_ window: NSWindow?) -> Bool {
|
||||
// We should only save the frame if the window is visible.
|
||||
// This avoids overriding the previously saved one
|
||||
// with the wrong one when window decorations change while creating,
|
||||
// e.g. adding a toolbar affects the window's frame.
|
||||
guard let window, window.isVisible else { return false }
|
||||
let frame = window.frame
|
||||
let rect = [frame.origin.x, frame.origin.y, frame.size.width, frame.size.height]
|
||||
UserDefaults.standard.set(rect, forKey: positionKey)
|
||||
return true
|
||||
}
|
||||
|
||||
func restore(_ window: NSWindow) -> Bool {
|
||||
|
||||
Reference in New Issue
Block a user