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