From 1fcc5812be4017c5b01ea77793c730de4ebbecd7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Oct 2023 14:45:48 -0700 Subject: [PATCH] macos: detect when surface tree becomes empty --- macos/Sources/Features/Terminal/TerminalController.swift | 8 +++++++- macos/Sources/Features/Terminal/TerminalView.swift | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 00a57997e..fc0ebc7d0 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -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() diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index c7505af33..163d4e575 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -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: View { @@ -95,10 +91,6 @@ struct TerminalView: View { } } } - - func onClose() { - self.delegate?.lastSurfaceDidClose() - } } struct DebugBuildWarningView: View {