diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index edf3662b9..3b4b1a2ef 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -413,6 +413,14 @@ class BaseTerminalController: NSWindowController, override func windowDidLoad() { guard let window else { return } + // If there is a hardcoded title in the configuration, we set that + // immediately. Future `set_title` apprt actions will override this + // if necessary but this ensures our window loads with the proper + // title immediately rather than on another event loop tick (see #5934) + if let title = derivedConfig.title { + window.title = title + } + // We always initialize our fullscreen style to native if we can because // initialization sets up some state (i.e. observers). If its set already // somehow we don't do this. @@ -617,17 +625,20 @@ class BaseTerminalController: NSWindowController, } private struct DerivedConfig { + let title: String? let macosTitlebarProxyIcon: Ghostty.MacOSTitlebarProxyIcon let windowStepResize: Bool let focusFollowsMouse: Bool init() { + self.title = nil self.macosTitlebarProxyIcon = .visible self.windowStepResize = false self.focusFollowsMouse = false } init(_ config: Ghostty.Config) { + self.title = config.title self.macosTitlebarProxyIcon = config.macosTitlebarProxyIcon self.windowStepResize = config.windowStepResize self.focusFollowsMouse = config.focusFollowsMouse diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 10e5446cc..20a43aa2b 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -132,6 +132,15 @@ extension Ghostty { return v } + var title: String? { + guard let config = self.config else { return nil } + var v: UnsafePointer? = nil + let key = "title" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return nil } + guard let ptr = v else { return nil } + return String(cString: ptr) + } + var windowSaveState: String { guard let config = self.config else { return "" } var v: UnsafePointer? = nil