macos: detect when surface tree becomes empty

This commit is contained in:
Mitchell Hashimoto
2023-10-30 14:45:48 -07:00
parent c18cf207d6
commit 1fcc5812be
2 changed files with 7 additions and 9 deletions

View File

@ -16,7 +16,13 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
var focusedSurface: Ghostty.SurfaceView? = nil
/// The surface tree for this window.
@Published var surfaceTree: Ghostty.SplitNode? = nil
@Published var surfaceTree: Ghostty.SplitNode? = nil {
didSet {
// If our surface tree becomes nil then it means all our surfaces
// have closed, so we also cloud the window.
if (surfaceTree == nil) { lastSurfaceDidClose() }
}
}
/// Fullscreen state management.
private let fullscreenHandler = FullScreenHandler()

View File

@ -10,9 +10,6 @@ protocol TerminalViewDelegate: AnyObject, ObservableObject {
/// The cell size changed.
func cellSizeDidChange(to: NSSize)
/// The last surface closed so there are no active surfaces.
func lastSurfaceDidClose()
}
protocol TerminalViewModel: ObservableObject {
@ -23,7 +20,6 @@ extension TerminalViewDelegate {
func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) {}
func titleDidChange(to: String) {}
func cellSizeDidChange(to: NSSize) {}
func lastSurfaceDidClose() {}
}
struct TerminalView<ViewModel: TerminalViewModel>: View {
@ -95,10 +91,6 @@ struct TerminalView<ViewModel: TerminalViewModel>: View {
}
}
}
func onClose() {
self.delegate?.lastSurfaceDidClose()
}
}
struct DebugBuildWarningView: View {