macos: respect window-new-tab-position configuration

This commit is contained in:
Thorsten Ball
2024-01-12 20:22:53 +01:00
parent a925afae84
commit 90427a8d22
2 changed files with 20 additions and 3 deletions

View File

@ -124,13 +124,20 @@ class TerminalManager {
tg.removeWindow(window)
}
// Our windows start our invisible. We need to make it visible. If we
// Our windows start out invisible. We need to make it visible. If we
// don't do this then various features such as window blur won't work because
// the macOS APIs only work on a visible window.
controller.showWindow(self)
// Add the window to the tab group and show it
// Add the window to the tab group and show it. If we already have a tab group
// and we want the new tab to open at the end, then we use the last window in
// the tab group as the parent.
if let last = parent.tabGroup?.windows.last, ghostty.windowNewTabPosition == "end" {
last.addTabbedWindow(window, ordered: .above)
} else {
parent.addTabbedWindow(window, ordered: .above)
}
window.makeKeyAndOrderFront(self)
// It takes an event loop cycle until the macOS tabGroup state becomes

View File

@ -85,6 +85,16 @@ extension Ghostty {
return String(cString: ptr)
}
/// window-new-tab-position
var windowNewTabPosition: String {
guard let config = self.config else { return "" }
var v: UnsafePointer<Int8>? = nil
let key = "window-new-tab-position"
guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return "" }
guard let ptr = v else { return "" }
return String(cString: ptr)
}
/// True if we need to confirm before quitting.
var needsConfirmQuit: Bool {
guard let app = app else { return false }