diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index af85341c6..b919d5282 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -124,13 +124,26 @@ 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 - parent.addTabbedWindow(window, ordered: .above) + // Add the window to the tab group and show it. + switch ghostty.windowNewTabPosition { + case "end": + // 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 { + last.addTabbedWindow(window, ordered: .above) + } else { + fallthrough + } + case "current": fallthrough + default: + parent.addTabbedWindow(window, ordered: .above) + } + window.makeKeyAndOrderFront(self) // It takes an event loop cycle until the macOS tabGroup state becomes diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index cfd9cdb95..e9c15ee95 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -84,6 +84,16 @@ extension Ghostty { guard let ptr = v else { return "" } return String(cString: ptr) } + + /// window-new-tab-position + var windowNewTabPosition: String { + guard let config = self.config else { return "" } + var v: UnsafePointer? = 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 {