mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: implement last surface close to close window
This commit is contained in:
@ -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) {
|
||||||
|
@ -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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user