From 13f776d483d5120e6b7fab7b04ed2fd5894e77e6 Mon Sep 17 00:00:00 2001 From: Aaron Ruan Date: Mon, 28 Apr 2025 10:20:29 +0800 Subject: [PATCH] Rename maximize notification and refine handler --- .../Terminal/BaseTerminalController.swift | 16 +++++++++------- macos/Sources/Ghostty/Ghostty.App.swift | 2 +- macos/Sources/Ghostty/Package.swift | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 59cef503d..d6b0433ac 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -117,8 +117,8 @@ class BaseTerminalController: NSWindowController, object: nil) center.addObserver( self, - selector: #selector(toggleMaximize), - name: .ghosttyToggleMaximize, + selector: #selector(ghosttyMaximizeDidToggle(_:)), + name: .ghosttyMaximizeDidToggle, object: nil) // Listen for local events that we need to know of outside of @@ -239,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? { @@ -553,11 +560,6 @@ class BaseTerminalController: NSWindowController, window.performClose(sender) } - @IBAction func toggleMaximize(_ sender: Any) { - guard let window = window else { return } - window.zoom(self) - } - @IBAction func splitRight(_ sender: Any) { guard let surface = focusedSurface?.surface else { return } ghostty.split(surface: surface, direction: GHOSTTY_SPLIT_DIRECTION_RIGHT) diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index e72acc05e..f7f5f475c 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -783,7 +783,7 @@ extension Ghostty { guard let surface = target.target.surface else { return } guard let surfaceView = self.surfaceView(from: surface) else { return } NotificationCenter.default.post( - name: .ghosttyToggleMaximize, + name: .ghosttyMaximizeDidToggle, object: surfaceView ) diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index ee0073aa1..80223776c 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -259,7 +259,7 @@ extension Notification.Name { static let ghosttyCommandPaletteDidToggle = Notification.Name("com.mitchellh.ghostty.commandPaletteDidToggle") /// Toggle maximize of current window - static let ghosttyToggleMaximize = Notification.Name("com.mitchellh.ghostty.toggleMaximize") + static let ghosttyMaximizeDidToggle = Notification.Name("com.mitchellh.ghostty.maximizeDidToggle") } // NOTE: I am moving all of these to Notification.Name extensions over time. This