mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-05 19:08:17 +00:00
Refactor toggleMaximize to use notifications
This commit is contained in:
@@ -807,12 +807,6 @@ class AppDelegate: NSObject,
|
||||
setSecureInput(.toggle)
|
||||
}
|
||||
|
||||
@IBAction func toggleMaximize(_ sender: Any) {
|
||||
if NSApp.isActive, let keyWindow = NSApp.keyWindow {
|
||||
keyWindow.zoom(self)
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func toggleQuickTerminal(_ sender: Any) {
|
||||
if quickController == nil {
|
||||
quickController = QuickTerminalController(
|
||||
|
@@ -115,6 +115,11 @@ class BaseTerminalController: NSWindowController,
|
||||
selector: #selector(ghosttyCommandPaletteDidToggle(_:)),
|
||||
name: .ghosttyCommandPaletteDidToggle,
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(toggleMaximize),
|
||||
name: .ghosttyToggleMaximize,
|
||||
object: nil)
|
||||
|
||||
// Listen for local events that we need to know of outside of
|
||||
// single surface handlers.
|
||||
@@ -548,6 +553,11 @@ 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)
|
||||
|
@@ -774,8 +774,23 @@ extension Ghostty {
|
||||
_ app: ghostty_app_t,
|
||||
target: ghostty_target_s
|
||||
) {
|
||||
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { return }
|
||||
appDelegate.toggleMaximize(self)
|
||||
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: .ghosttyToggleMaximize,
|
||||
object: surfaceView
|
||||
)
|
||||
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
}
|
||||
}
|
||||
|
||||
private static func toggleVisibility(
|
||||
|
@@ -257,6 +257,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 ghosttyToggleMaximize = Notification.Name("com.mitchellh.ghostty.toggleMaximize")
|
||||
}
|
||||
|
||||
// NOTE: I am moving all of these to Notification.Name extensions over time. This
|
||||
|
Reference in New Issue
Block a user