feat: implement toggleMaximize for macOS (#7191)

Resolve #7030
pull/7283/head
Mitchell Hashimoto 2025-05-06 13:43:57 -07:00 committed by GitHub
commit 732500b418
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 1 deletions

View File

@ -29,7 +29,6 @@ struct TerminalCommandPaletteView: View {
let key = String(cString: c.action_key)
switch (key) {
case "toggle_tab_overview",
"toggle_maximize",
"toggle_window_decorations":
return false
default:

View File

@ -115,6 +115,11 @@ class BaseTerminalController: NSWindowController,
selector: #selector(ghosttyCommandPaletteDidToggle(_:)),
name: .ghosttyCommandPaletteDidToggle,
object: nil)
center.addObserver(
self,
selector: #selector(ghosttyMaximizeDidToggle(_:)),
name: .ghosttyMaximizeDidToggle,
object: nil)
// Listen for local events that we need to know of outside of
// single surface handlers.
@ -234,6 +239,13 @@ class BaseTerminalController: NSWindowController,
toggleCommandPalette(nil)
}
@objc private func ghosttyMaximizeDidToggle(_ notification: Notification) {
guard let window else { return }
guard let surfaceView = notification.object as? Ghostty.SurfaceView else { return }
guard surfaceTree?.contains(view: surfaceView) ?? false else { return }
window.zoom(nil)
}
// MARK: Local Events
private func localEventHandler(_ event: NSEvent) -> NSEvent? {

View File

@ -526,6 +526,9 @@ extension Ghostty {
case GHOSTTY_ACTION_TOGGLE_COMMAND_PALETTE:
toggleCommandPalette(app, target: target)
case GHOSTTY_ACTION_TOGGLE_MAXIMIZE:
toggleMaximize(app, target: target)
case GHOSTTY_ACTION_TOGGLE_QUICK_TERMINAL:
toggleQuickTerminal(app, target: target)
@ -770,6 +773,29 @@ extension Ghostty {
}
}
private static func toggleMaximize(
_ app: ghostty_app_t,
target: ghostty_target_s
) {
switch (target.tag) {
case GHOSTTY_TARGET_APP:
Ghostty.logger.warning("toggle maximize does nothing with an app target")
return
case GHOSTTY_TARGET_SURFACE:
guard let surface = target.target.surface else { return }
guard let surfaceView = self.surfaceView(from: surface) else { return }
NotificationCenter.default.post(
name: .ghosttyMaximizeDidToggle,
object: surfaceView
)
default:
assertionFailure()
}
}
private static func toggleVisibility(
_ app: ghostty_app_t,
target: ghostty_target_s

View File

@ -279,6 +279,9 @@ extension Notification.Name {
/// Ring the bell
static let ghosttyBellDidRing = Notification.Name("com.mitchellh.ghostty.ghosttyBellDidRing")
static let ghosttyCommandPaletteDidToggle = Notification.Name("com.mitchellh.ghostty.commandPaletteDidToggle")
/// Toggle maximize of current window
static let ghosttyMaximizeDidToggle = Notification.Name("com.mitchellh.ghostty.maximizeDidToggle")
}
// NOTE: I am moving all of these to Notification.Name extensions over time. This