diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 664e7ce38..95bb035cb 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -95,6 +95,10 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele self.window?.contentResizeIncrements = to } + func lastSurfaceDidClose() { + self.window?.close() + } + //MARK: - Notifications @objc private func onGotoTab(notification: SwiftUI.Notification) { diff --git a/macos/Sources/Features/Terminal/TerminalView.swift b/macos/Sources/Features/Terminal/TerminalView.swift index e10bf0b29..727a99a83 100644 --- a/macos/Sources/Features/Terminal/TerminalView.swift +++ b/macos/Sources/Features/Terminal/TerminalView.swift @@ -10,12 +10,16 @@ protocol TerminalViewDelegate: AnyObject { /// The cell size changed. func cellSizeDidChange(to: NSSize) + + /// The last surface closed so there are no active surfaces. + func lastSurfaceDidClose() } extension TerminalViewDelegate { func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) {} func titleDidChange(to: String) {} func cellSizeDidChange(to: NSSize) {} + func lastSurfaceDidClose() {} } struct TerminalView: View { @@ -66,7 +70,7 @@ struct TerminalView: View { DebugBuildWarningView() } - Ghostty.TerminalSplit(onClose: Self.closeWindow, baseConfig: nil) + Ghostty.TerminalSplit(onClose: onClose, baseConfig: nil) .ghosttyApp(ghostty.app!) .ghosttyConfig(ghostty.config!) .focused($focused) @@ -85,8 +89,7 @@ struct TerminalView: View { } } - static func closeWindow() { - guard let currentWindow = NSApp.keyWindow else { return } - currentWindow.close() + func onClose() { + self.delegate?.lastSurfaceDidClose() } }