From 13eb8ac6e20a6e4b3d6cdde5eea8303b9eee2b0c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Sep 2024 15:29:47 -0700 Subject: [PATCH] macos: ability to interrupt animation, track it in menu --- macos/Sources/App/macOS/AppDelegate.swift | 2 ++ .../QuickTerminal/QuickTerminalController.swift | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 3686f7fb8..ad4c9bbda 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -558,5 +558,7 @@ class AppDelegate: NSObject, guard let quickController = self.quickController else { return } quickController.toggle() + + self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off } } } diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift index 5025e725c..979af1fca 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift @@ -10,6 +10,9 @@ class QuickTerminalController: BaseTerminalController { /// The position for the quick terminal. let position: QuickTerminalPosition + /// The current state of the quick terminal + private(set) var visible: Bool = false + init(_ ghostty: Ghostty.App, position: QuickTerminalPosition = .top, baseConfig base: Ghostty.SurfaceConfiguration? = nil, @@ -76,8 +79,7 @@ class QuickTerminalController: BaseTerminalController { // MARK: Methods func toggle() { - guard let window = self.window else { return } - if (window.alphaValue > 0) { + if (visible) { animateOut() } else { animateIn() @@ -87,6 +89,10 @@ class QuickTerminalController: BaseTerminalController { func animateIn() { guard let window = self.window else { return } + // Set our visibility state + guard !visible else { return } + visible = true + // Animate the window in animateWindowIn(window: window, from: position) @@ -100,6 +106,11 @@ class QuickTerminalController: BaseTerminalController { func animateOut() { guard let window = self.window else { return } + + // Set our visibility state + guard visible else { return } + visible = false + animateWindowOut(window: window, to: position) }