diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 7caa04659..ad48e24de 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -753,6 +753,16 @@ class AppDelegate: NSObject, quickController.toggle() } + @IBAction func returnToDefaultSize(_ sender: Any) { + guard let window = NSApp.keyWindow else { return } + let currentOrigin = window.frame.origin + let newFrame = NSRect( + origin: currentOrigin, + size: WindowConfig.defaultSize + ) + window.setFrame(newFrame, display: true) + } + /// Toggles visibility of all Ghosty Terminal windows. When hidden, activates Ghostty as the frontmost application @IBAction func toggleVisibility(_ sender: Any) { // If we have focus, then we hide all windows. @@ -804,6 +814,10 @@ class AppDelegate: NSObject, } } + private enum WindowConfig { + static let defaultSize = CGSize(width: 800, height: 600) + } + private struct ToggleVisibilityState { let hiddenWindows: [Weak] let keyWindow: Weak? @@ -833,3 +847,23 @@ class AppDelegate: NSObject, } } } + +extension AppDelegate: NSMenuItemValidation { + func validateMenuItem(_ item: NSMenuItem) -> Bool { + switch item.action { + case #selector(returnToDefaultSize): + guard let focusedWindow = NSApp.keyWindow else { + return false + } + if focusedWindow.styleMask.contains(.fullScreen) { + return false + } + if focusedWindow.frame.size == WindowConfig.defaultSize { + return false + } + return true + default: + return true + } + } +} diff --git a/macos/Sources/App/macOS/MainMenu.xib b/macos/Sources/App/macOS/MainMenu.xib index 8ad57c4a5..94ced4890 100644 --- a/macos/Sources/App/macOS/MainMenu.xib +++ b/macos/Sources/App/macOS/MainMenu.xib @@ -388,6 +388,13 @@ + + + + + + +