Skip to content

Commit

Permalink
[macOS] feat: Add setting to hide icon from dock/cmd-tab (#5122)
Browse files Browse the repository at this point in the history
Resolves #4538 

Adds boolean configuration option `macos-hidden` which toggles the
NSApp's activation policy appropriately on config change.
  • Loading branch information
mitchellh authored Feb 15, 2025
2 parents aeccbd2 + d7a82f2 commit 6d8db4b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions macos/Sources/App/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions macos/Sources/Ghostty/Ghostty.Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int8>? = 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;
Expand Down Expand Up @@ -516,6 +526,11 @@ extension Ghostty.Config {
case download
}

enum MacHidden : String {
case never
case always
}

enum ResizeOverlay : String {
case always
case never
Expand Down
26 changes: 26 additions & 0 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d8db4b

Please sign in to comment.