From d7a82f212a34402fe1dcfdf234cacb4c0bb79b3e Mon Sep 17 00:00:00 2001 From: Albert Dong Date: Wed, 15 Jan 2025 12:12:42 -0800 Subject: [PATCH] Add setting to hide icon from dock/cmd-tab --- macos/Sources/App/macOS/AppDelegate.swift | 9 ++++++++ macos/Sources/Ghostty/Ghostty.Config.swift | 15 +++++++++++++ src/config/Config.zig | 26 ++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index d54170579..12f8f8c31 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -533,6 +533,15 @@ class AppDelegate: NSObject, // AppKit mutex on the appearance. DispatchQueue.main.async { self.syncAppearance(config: config) } + // Decide whether to hide/unhide app from dock and app switcher + switch (config.macosHidden) { + case .never: + NSApp.setActivationPolicy(.regular) + + case .always: + NSApp.setActivationPolicy(.accessory) + } + // If we have configuration errors, we need to show them. let c = ConfigurationErrorsController.sharedInstance c.errors = config.errors diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 22d66a1a8..ec23632f7 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -302,6 +302,16 @@ extension Ghostty { return buffer.map { .init(ghostty: $0) } } + var macosHidden: MacHidden { + guard let config = self.config else { return .never } + var v: UnsafePointer? = nil + let key = "macos-hidden" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return .never } + guard let ptr = v else { return .never } + let str = String(cString: ptr) + return MacHidden(rawValue: str) ?? .never + } + var focusFollowsMouse : Bool { guard let config = self.config else { return false } var v = false; @@ -516,6 +526,11 @@ extension Ghostty.Config { case download } + enum MacHidden : String { + case never + case always + } + enum ResizeOverlay : String { case always case never diff --git a/src/config/Config.zig b/src/config/Config.zig index 50abd5577..9e6f17ef4 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1974,6 +1974,26 @@ keybind: Keybinds = .{}, /// find false more visually appealing. @"macos-window-shadow": bool = true, +/// If true, the macOS icon in the dock and app switcher will be hidden. This is +/// mainly intended for those primarily using the quick-terminal mode. +/// +/// Note that setting this to true means that keyboard layout changes +/// will no longer be automatic. +/// +/// Control whether macOS app is excluded from the dock and app switcher, +/// a "hidden" state. This is mainly intended for those primarily using +/// quick-terminal mode, but is a general configuration for any use +/// case. +/// +/// Available values: +/// +/// * `never` - The macOS app is never hidden. +/// * `always` - The macOS app is always hidden. +/// +/// Note: When the macOS application is hidden, keyboard layout changes +/// will no longer be automatic. This is a limitation of macOS. +@"macos-hidden": MacHidden = .never, + /// If true, Ghostty on macOS will automatically enable the "Secure Input" /// feature when it detects that a password prompt is being displayed. /// @@ -5738,6 +5758,12 @@ pub const MacTitlebarProxyIcon = enum { hidden, }; +/// See macos-hidden +pub const MacHidden = enum { + never, + always, +}; + /// See macos-icon /// /// Note: future versions of Ghostty can support a custom icon with