diff --git a/macos/Sources/Features/Command Palette/TerminalCommandPalette.swift b/macos/Sources/Features/Command Palette/TerminalCommandPalette.swift index affbc4ddc..57a76dd43 100644 --- a/macos/Sources/Features/Command Palette/TerminalCommandPalette.swift +++ b/macos/Sources/Features/Command Palette/TerminalCommandPalette.swift @@ -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: diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 36dc5f93c..98e3b87f9 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -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? { diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index c06287087..65e91ce83 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -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 diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index 366bb8113..30d5573df 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -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