Rename maximize notification and refine handler

This commit is contained in:
Aaron Ruan
2025-04-28 10:20:29 +08:00
parent 1ec3e331de
commit 13f776d483
3 changed files with 11 additions and 9 deletions

View File

@@ -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)

View File

@@ -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
)

View File

@@ -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