Add hiding toggle, hook up to menu / shortcut

This commit is contained in:
Roland Peelen
2024-09-30 19:54:41 +02:00
committed by Mitchell Hashimoto
parent 24ba1a6100
commit 4aac4ecd98
3 changed files with 46 additions and 2 deletions

View File

@ -86,6 +86,9 @@ class AppDelegate: NSObject,
return ProcessInfo.processInfo.systemUptime - applicationLaunchTime return ProcessInfo.processInfo.systemUptime - applicationLaunchTime
} }
/// Tracks whether the application is currently visible
private var isVisible: Bool = true
override init() { override init() {
terminalManager = TerminalManager(ghostty) terminalManager = TerminalManager(ghostty)
updaterController = SPUStandardUpdaterController( updaterController = SPUStandardUpdaterController(
@ -251,6 +254,7 @@ class AppDelegate: NSObject,
// Ghostty will validate as well but we can avoid creating an entirely new // Ghostty will validate as well but we can avoid creating an entirely new
// surface by doing our own validation here. We can also show a useful error // surface by doing our own validation here. We can also show a useful error
// this way. // this way.
var isDirectory = ObjCBool(true) var isDirectory = ObjCBool(true)
guard FileManager.default.fileExists(atPath: filename, isDirectory: &isDirectory) else { return false } guard FileManager.default.fileExists(atPath: filename, isDirectory: &isDirectory) else { return false }
@ -315,6 +319,7 @@ class AppDelegate: NSObject,
syncMenuShortcut(action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize) syncMenuShortcut(action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize)
syncMenuShortcut(action: "reset_font_size", menuItem: self.menuResetFontSize) syncMenuShortcut(action: "reset_font_size", menuItem: self.menuResetFontSize)
syncMenuShortcut(action: "toggle_quick_terminal", menuItem: self.menuQuickTerminal) syncMenuShortcut(action: "toggle_quick_terminal", menuItem: self.menuQuickTerminal)
syncMenuShortcut(action: "toggle_visibility", menuItem: self.menuQuickTerminal)
syncMenuShortcut(action: "inspector:toggle", menuItem: self.menuTerminalInspector) syncMenuShortcut(action: "inspector:toggle", menuItem: self.menuTerminalInspector)
syncMenuShortcut(action: "toggle_secure_input", menuItem: self.menuSecureInput) syncMenuShortcut(action: "toggle_secure_input", menuItem: self.menuSecureInput)
@ -564,4 +569,27 @@ class AppDelegate: NSObject,
self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off } self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off }
} }
/// Toggles the visibility of all Ghostty windows
@IBAction func toggleVisibility(_ sender: Any) {
let configurationErrorsWindow = ConfigurationErrorsController.sharedInstance.window
if isVisible {
// Hide all windows
for window in NSApp.windows {
if window !== configurationErrorsWindow {
window.orderOut(nil)
}
}
} else {
// Show all windows
for window in NSApp.windows {
if window !== configurationErrorsWindow {
window.makeKeyAndOrderFront(nil)
}
}
NSApp.activate(ignoringOtherApps: true)
}
isVisible.toggle()
}
} }

View File

@ -217,10 +217,16 @@
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="L3L-I8-sqk"/> <menuItem isSeparatorItem="YES" id="L3L-I8-sqk"/>
<menuItem title="Quick Terminal" id="kvF-d2-JsP"> <menuItem title="Toggle Visibility" id="kvF-d2-JsP">
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<connections> <connections>
<action selector="toggleQuickTerminal:" target="bbz-4X-AYv" id="gm3-mk-l8N"/> <action selector="toggleVisibility" target="bbz-4X-AYv" id="RhV-3i-Xjz"/>
</connections>
</menuItem>
<menuItem title="Quick Terminal" id="1pv-LF-NBJ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleQuickTerminal:" target="bbz-4X-AYv" id="qDV-sz-Agc"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="bC9-n9-RbJ"/> <menuItem isSeparatorItem="YES" id="bC9-n9-RbJ"/>

View File

@ -490,6 +490,9 @@ extension Ghostty {
case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL: case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL:
toggleQuickTerminal(app, target: target) toggleQuickTerminal(app, target: target)
case GHOSTTY_ACTION_TOGGLE_VISIBILITY:
toggleVisibility(app, target: target)
case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS: case GHOSTTY_ACTION_CLOSE_ALL_WINDOWS:
fallthrough fallthrough
case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW: case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW:
@ -630,6 +633,13 @@ extension Ghostty {
} }
} }
private static func toggleVisibility(
_ app: ghostty_app_t,
target: ghostty_target_s) {
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { return }
appDelegate.toggleVisibility(self)
}
private static func gotoTab( private static func gotoTab(
_ app: ghostty_app_t, _ app: ghostty_app_t,
target: ghostty_target_s, target: ghostty_target_s,