From f9ad061ea8ed4da5cd954eb4e145ae1b857b085d Mon Sep 17 00:00:00 2001 From: David Keegan Date: Thu, 31 Jul 2025 13:16:52 -0600 Subject: [PATCH 1/2] Add macos-dock-drop-folder-behavior configuration option This adds a new configuration option that controls whether folders dropped onto the Ghostty dock icon open in a new tab (default) or a new window. The option accepts two values: - tab: Opens folders in a new tab in the main window (default) - window: Opens folders in a new window This is useful for users who prefer window-based workflows over tab-based workflows when opening folders via drag and drop. --- macos/Sources/App/macOS/AppDelegate.swift | 14 ++++++++++---- macos/Sources/Ghostty/Ghostty.Config.swift | 11 +++++++++++ macos/Sources/Ghostty/Package.swift | 6 ++++++ src/config/Config.zig | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index cbd3668c5..a4c6986a9 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -402,11 +402,17 @@ class AppDelegate: NSObject, var config = Ghostty.SurfaceConfiguration() if (isDirectory.boolValue) { - // When opening a directory, create a new tab in the main - // window with that as the working directory. - // If no windows exist, a new one will be created. + // When opening a directory, check the configuration to decide + // whether to open in a new tab or new window. config.workingDirectory = filename - _ = TerminalController.newTab(ghostty, withBaseConfig: config) + + let behavior = ghostty.config.macosDockDropFolderBehavior + if behavior == .window { + _ = TerminalController.newWindow(ghostty, withBaseConfig: config) + } else { + // Default to tab behavior + _ = TerminalController.newTab(ghostty, withBaseConfig: config) + } } else { // When opening a file, we want to execute the file. To do this, we // don't override the command directly, because it won't load the diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index a223b2a0a..fca272a3e 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -282,6 +282,17 @@ extension Ghostty { return MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue } + var macosDockDropFolderBehavior: MacOSDockDropFolderBehavior { + let defaultValue = MacOSDockDropFolderBehavior.tab + guard let config = self.config else { return defaultValue } + var v: UnsafePointer? = nil + let key = "macos-dock-drop-folder-behavior" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue } + guard let ptr = v else { return defaultValue } + let str = String(cString: ptr) + return MacOSDockDropFolderBehavior(rawValue: str) ?? defaultValue + } + var macosWindowShadow: Bool { guard let config = self.config else { return false } var v = false; diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index 73487f1bd..6ba88045b 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -304,6 +304,12 @@ extension Ghostty { case hidden } + /// Enum for the macos-dock-drop-folder-behavior config option + enum MacOSDockDropFolderBehavior: String { + case tab + case window + } + /// Enum for auto-update-channel config option enum AutoUpdateChannel: String { case tip diff --git a/src/config/Config.zig b/src/config/Config.zig index 178b9f851..7ae767fd6 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -2631,6 +2631,20 @@ keybind: Keybinds = .{}, /// editor, etc. @"macos-titlebar-proxy-icon": MacTitlebarProxyIcon = .visible, +/// Controls the behavior when dropping a folder onto the Ghostty dock icon +/// on macOS. +/// +/// Valid values are: +/// +/// * `tab` - Open the folder in a new tab in the main window (default). +/// * `window` - Open the folder in a new window. +/// +/// The default value is `tab`. +/// +/// This setting is only supported on macOS and has no effect on other +/// platforms. +@"macos-dock-drop-folder-behavior": MacOSDockDropFolderBehavior = .tab, + /// macOS doesn't have a distinct "alt" key and instead has the "option" /// key which behaves slightly differently. On macOS by default, the /// option key plus a character will sometimes produce a Unicode character. @@ -7082,6 +7096,12 @@ pub const WindowNewTabPosition = enum { end, }; +/// See macos-dock-drop-folder-behavior +pub const MacOSDockDropFolderBehavior = enum { + tab, + window, +}; + /// See window-show-tab-bar pub const WindowShowTabBar = enum { always, From e01ff4093a1e3b3106daef892c33fc9abb9ea249 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Aug 2025 10:45:12 -0700 Subject: [PATCH 2/2] macos: have macos-dock-drop-behavior apply to all drops --- macos/Sources/App/macOS/AppDelegate.swift | 15 +++++---------- macos/Sources/Ghostty/Ghostty.Config.swift | 13 +++++++++---- macos/Sources/Ghostty/Package.swift | 6 ------ src/config/Config.zig | 19 ++++++++++--------- src/config/formatter.zig | 2 ++ 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index a4c6986a9..d54b49642 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -405,14 +405,6 @@ class AppDelegate: NSObject, // When opening a directory, check the configuration to decide // whether to open in a new tab or new window. config.workingDirectory = filename - - let behavior = ghostty.config.macosDockDropFolderBehavior - if behavior == .window { - _ = TerminalController.newWindow(ghostty, withBaseConfig: config) - } else { - // Default to tab behavior - _ = TerminalController.newTab(ghostty, withBaseConfig: config) - } } else { // When opening a file, we want to execute the file. To do this, we // don't override the command directly, because it won't load the @@ -424,8 +416,11 @@ class AppDelegate: NSObject, // Set the parent directory to our working directory so that relative // paths in scripts work. config.workingDirectory = (filename as NSString).deletingLastPathComponent - - _ = TerminalController.newWindow(ghostty, withBaseConfig: config) + } + + switch ghostty.config.macosDockDropBehavior { + case .new_tab: _ = TerminalController.newTab(ghostty, withBaseConfig: config) + case .new_window: _ = TerminalController.newWindow(ghostty, withBaseConfig: config) } return true diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index fca272a3e..6992f59f6 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -282,15 +282,15 @@ extension Ghostty { return MacOSTitlebarProxyIcon(rawValue: str) ?? defaultValue } - var macosDockDropFolderBehavior: MacOSDockDropFolderBehavior { - let defaultValue = MacOSDockDropFolderBehavior.tab + var macosDockDropBehavior: MacDockDropBehavior { + let defaultValue = MacDockDropBehavior.new_tab guard let config = self.config else { return defaultValue } var v: UnsafePointer? = nil - let key = "macos-dock-drop-folder-behavior" + let key = "macos-dock-drop-behavior" guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue } guard let ptr = v else { return defaultValue } let str = String(cString: ptr) - return MacOSDockDropFolderBehavior(rawValue: str) ?? defaultValue + return MacDockDropBehavior(rawValue: str) ?? defaultValue } var macosWindowShadow: Bool { @@ -618,6 +618,11 @@ extension Ghostty.Config { static let attention = BellFeatures(rawValue: 1 << 2) static let title = BellFeatures(rawValue: 1 << 3) } + + enum MacDockDropBehavior: String { + case new_tab = "new-tab" + case new_window = "new-window" + } enum MacHidden : String { case never diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index 6ba88045b..73487f1bd 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -304,12 +304,6 @@ extension Ghostty { case hidden } - /// Enum for the macos-dock-drop-folder-behavior config option - enum MacOSDockDropFolderBehavior: String { - case tab - case window - } - /// Enum for auto-update-channel config option enum AutoUpdateChannel: String { case tip diff --git a/src/config/Config.zig b/src/config/Config.zig index 7ae767fd6..d8fcfa1d7 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -2631,19 +2631,20 @@ keybind: Keybinds = .{}, /// editor, etc. @"macos-titlebar-proxy-icon": MacTitlebarProxyIcon = .visible, -/// Controls the behavior when dropping a folder onto the Ghostty dock icon -/// on macOS. +/// Controls the windowing behavior when dropping a file or folder +/// onto the Ghostty icon in the macOS dock. /// /// Valid values are: /// -/// * `tab` - Open the folder in a new tab in the main window (default). -/// * `window` - Open the folder in a new window. +/// * `new-tab` - Create a new tab in the current window, or open +/// a new window if none exist. +/// * `new-window` - Create a new window unconditionally. /// -/// The default value is `tab`. +/// The default value is `new-tab`. /// /// This setting is only supported on macOS and has no effect on other /// platforms. -@"macos-dock-drop-folder-behavior": MacOSDockDropFolderBehavior = .tab, +@"macos-dock-drop-behavior": MacOSDockDropBehavior = .@"new-tab", /// macOS doesn't have a distinct "alt" key and instead has the "option" /// key which behaves slightly differently. On macOS by default, the @@ -7096,9 +7097,9 @@ pub const WindowNewTabPosition = enum { end, }; -/// See macos-dock-drop-folder-behavior -pub const MacOSDockDropFolderBehavior = enum { - tab, +/// See macos-dock-drop-behavior +pub const MacOSDockDropBehavior = enum { + @"new-tab", window, }; diff --git a/src/config/formatter.zig b/src/config/formatter.zig index cabf80953..a42395c19 100644 --- a/src/config/formatter.zig +++ b/src/config/formatter.zig @@ -147,6 +147,8 @@ pub const FileFormatter = struct { opts: std.fmt.FormatOptions, writer: anytype, ) !void { + @setEvalBranchQuota(10_000); + _ = layout; _ = opts;