mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-21 17:21:52 +00:00
macos: address quick terminal basic functionality with new API
This commit is contained in:
@@ -61,6 +61,12 @@ class QuickTerminalController: BaseTerminalController {
|
||||
selector: #selector(ghosttyConfigDidChange(_:)),
|
||||
name: .ghosttyConfigDidChange,
|
||||
object: nil)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(closeWindow(_:)),
|
||||
name: .ghosttyCloseWindow,
|
||||
object: nil
|
||||
)
|
||||
center.addObserver(
|
||||
self,
|
||||
selector: #selector(onNewTab),
|
||||
@@ -198,16 +204,38 @@ class QuickTerminalController: BaseTerminalController {
|
||||
|
||||
// If our surface tree is nil then we animate the window out.
|
||||
if (to.isEmpty) {
|
||||
// Save the current window frame before animating out. This preserves
|
||||
// the user's preferred window size and position for when the quick
|
||||
// terminal is reactivated with a new surface. Without this, SwiftUI
|
||||
// would reset the window to its minimum content size.
|
||||
lastClosedFrame = window?.frame
|
||||
|
||||
animateOut()
|
||||
}
|
||||
}
|
||||
|
||||
override func closeSurfaceNode(
|
||||
_ node: SplitTree<Ghostty.SurfaceView>.Node,
|
||||
withConfirmation: Bool = true
|
||||
) {
|
||||
// If this isn't the root then we're dealing with a split closure.
|
||||
if surfaceTree.root != node {
|
||||
super.closeSurfaceNode(node, withConfirmation: withConfirmation)
|
||||
return
|
||||
}
|
||||
|
||||
// If this isn't a final leaf then we're dealing with a split closure
|
||||
guard case .leaf(let surface) = node else {
|
||||
super.closeSurfaceNode(node, withConfirmation: withConfirmation)
|
||||
return
|
||||
}
|
||||
|
||||
// If its the root, we check if the process exited. If it did,
|
||||
// then we do empty the tree.
|
||||
if surface.processExited {
|
||||
surfaceTree = .init()
|
||||
return
|
||||
}
|
||||
|
||||
// If its the root then we just animate out. We never actually allow
|
||||
// the surface to fully close.
|
||||
animateOut()
|
||||
}
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
func toggle() {
|
||||
@@ -252,12 +280,6 @@ class QuickTerminalController: BaseTerminalController {
|
||||
let view = Ghostty.SurfaceView(ghostty_app, baseConfig: nil)
|
||||
surfaceTree = SplitTree(view: view)
|
||||
focusedSurface = view
|
||||
|
||||
// Restore our previous frame if we have one
|
||||
if let lastClosedFrame {
|
||||
window.setFrame(lastClosedFrame, display: false)
|
||||
self.lastClosedFrame = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Animate the window in
|
||||
@@ -283,6 +305,12 @@ class QuickTerminalController: BaseTerminalController {
|
||||
private func animateWindowIn(window: NSWindow, from position: QuickTerminalPosition) {
|
||||
guard let screen = derivedConfig.quickTerminalScreen.screen else { return }
|
||||
|
||||
// Restore our previous frame if we have one
|
||||
if let lastClosedFrame {
|
||||
window.setFrame(lastClosedFrame, display: false)
|
||||
self.lastClosedFrame = nil
|
||||
}
|
||||
|
||||
// Move our window off screen to the top
|
||||
position.setInitial(in: window, on: screen)
|
||||
|
||||
@@ -393,6 +421,12 @@ class QuickTerminalController: BaseTerminalController {
|
||||
}
|
||||
|
||||
private func animateWindowOut(window: NSWindow, to position: QuickTerminalPosition) {
|
||||
// Save the current window frame before animating out. This preserves
|
||||
// the user's preferred window size and position for when the quick
|
||||
// terminal is reactivated with a new surface. Without this, SwiftUI
|
||||
// would reset the window to its minimum content size.
|
||||
lastClosedFrame = window.frame
|
||||
|
||||
// If we hid the dock then we unhide it.
|
||||
hiddenDock = nil
|
||||
|
||||
|
Reference in New Issue
Block a user