mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
"Return to Default Size" implementation
Added support for "Return To Default Size"
This commit is contained in:

committed by
Mitchell Hashimoto

parent
9681009650
commit
f73c1a2c59
@ -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<NSWindow>]
|
||||
let keyWindow: Weak<NSWindow>?
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,6 +388,13 @@
|
||||
</menu>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="dgt-Tx-d4e"/>
|
||||
<menuItem title="Return To Default Size" id="Gbx-Vi-OGC" userLabel="Return To Default Size">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="returnToDefaultSize:" target="-1" id="Bpt-GO-UU1"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="CpM-rI-Sc1"/>
|
||||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
|
Reference in New Issue
Block a user