macos: implement last surface close to close window

This commit is contained in:
Mitchell Hashimoto
2023-10-30 09:53:59 -07:00
parent 481d128405
commit 61451942e8
2 changed files with 11 additions and 4 deletions

View File

@ -95,6 +95,10 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
self.window?.contentResizeIncrements = to self.window?.contentResizeIncrements = to
} }
func lastSurfaceDidClose() {
self.window?.close()
}
//MARK: - Notifications //MARK: - Notifications
@objc private func onGotoTab(notification: SwiftUI.Notification) { @objc private func onGotoTab(notification: SwiftUI.Notification) {

View File

@ -10,12 +10,16 @@ protocol TerminalViewDelegate: AnyObject {
/// The cell size changed. /// The cell size changed.
func cellSizeDidChange(to: NSSize) func cellSizeDidChange(to: NSSize)
/// The last surface closed so there are no active surfaces.
func lastSurfaceDidClose()
} }
extension TerminalViewDelegate { extension TerminalViewDelegate {
func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) {} func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) {}
func titleDidChange(to: String) {} func titleDidChange(to: String) {}
func cellSizeDidChange(to: NSSize) {} func cellSizeDidChange(to: NSSize) {}
func lastSurfaceDidClose() {}
} }
struct TerminalView: View { struct TerminalView: View {
@ -66,7 +70,7 @@ struct TerminalView: View {
DebugBuildWarningView() DebugBuildWarningView()
} }
Ghostty.TerminalSplit(onClose: Self.closeWindow, baseConfig: nil) Ghostty.TerminalSplit(onClose: onClose, baseConfig: nil)
.ghosttyApp(ghostty.app!) .ghosttyApp(ghostty.app!)
.ghosttyConfig(ghostty.config!) .ghosttyConfig(ghostty.config!)
.focused($focused) .focused($focused)
@ -85,8 +89,7 @@ struct TerminalView: View {
} }
} }
static func closeWindow() { func onClose() {
guard let currentWindow = NSApp.keyWindow else { return } self.delegate?.lastSurfaceDidClose()
currentWindow.close()
} }
} }