From 17b63f7617f8fe1cb26abf714f0dedff955110ed Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Wed, 18 Oct 2023 12:46:35 -0700 Subject: [PATCH 1/2] config: add quit-after-last-window-closed Whether or not to quit after the last window is closed. This defaults to false. Currently only supported on macOS. --- macos/Sources/AppDelegate.swift | 6 +++++- macos/Sources/Ghostty/AppState.swift | 9 +++++++++ src/config/Config.zig | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index 9bdd637bd..833fae4c4 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -81,7 +81,11 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp // else is initialized. NSApp.servicesProvider = ServiceProvider() } - + + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return ghostty.shouldQuitAfterLastWindowClosed + } + func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply { let windows = NSApplication.shared.windows if (windows.isEmpty) { return .terminateNow } diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 43f2a5dbf..90df697a7 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -51,6 +51,15 @@ extension Ghostty { } } + /// True if we should quit when the last window is closed. + var shouldQuitAfterLastWindowClosed: Bool { + guard let config = self.config else { return true } + var v = false; + let key = "quit-after-last-window-closed" + _ = ghostty_config_get(config, &v, key, UInt(key.count)) + return v; + } + /// True if we need to confirm before quitting. var needsConfirmQuit: Bool { guard let app = app else { return false } diff --git a/src/config/Config.zig b/src/config/Config.zig index 656726084..92709ede5 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -430,6 +430,10 @@ keybind: Keybinds = .{}, /// to true. If set to false, surfaces will close without any confirmation. @"confirm-close-surface": bool = true, +/// Whether or not to quit after the last window is closed. This defaults +/// to false. Currently only supported on macOS. +@"quit-after-last-window-closed": bool = false, + /// Whether to enable shell integration auto-injection or not. Shell /// integration greatly enhances the terminal experience by enabling /// a number of features: From 3a26812e6ab9732ca641ea063ee425b40962d8fc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Oct 2023 20:08:37 -0700 Subject: [PATCH 2/2] config: update doc comment --- src/config/Config.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 92709ede5..b59161289 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -431,7 +431,8 @@ keybind: Keybinds = .{}, @"confirm-close-surface": bool = true, /// Whether or not to quit after the last window is closed. This defaults -/// to false. Currently only supported on macOS. +/// to false. Currently only supported on macOS. On Linux, the process always +/// exits after the last window is closed. @"quit-after-last-window-closed": bool = false, /// Whether to enable shell integration auto-injection or not. Shell