diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index c6ad36e56..3244f163c 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -837,6 +837,13 @@ class AppDelegate: NSObject, case .xray: self.appIcon = NSImage(named: "XrayImage")! + case .custom: + if let userIcon = NSImage(contentsOfFile: config.macosCustomIcon) { + self.appIcon = userIcon + } else { + self.appIcon = nil // Revert back to official icon if invalid location + } + case .customStyle: guard let ghostColor = config.macosIconGhostColor else { break } guard let screenColors = config.macosIconScreenColor else { break } diff --git a/macos/Sources/Ghostty/Ghostty.Config.swift b/macos/Sources/Ghostty/Ghostty.Config.swift index 241c10632..0f6276d01 100644 --- a/macos/Sources/Ghostty/Ghostty.Config.swift +++ b/macos/Sources/Ghostty/Ghostty.Config.swift @@ -301,6 +301,20 @@ extension Ghostty { return MacOSIcon(rawValue: str) ?? defaultValue } + var macosCustomIcon: String { + let homeDirURL = FileManager.default.homeDirectoryForCurrentUser + let ghosttyConfigIconPath = homeDirURL.appendingPathComponent( + ".config/ghostty/Ghostty.icns", + conformingTo: .fileURL).path() + let defaultValue = ghosttyConfigIconPath + guard let config = self.config else { return defaultValue } + var v: UnsafePointer? = nil + let key = "macos-custom-icon" + guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return defaultValue } + guard let ptr = v else { return defaultValue } + return String(cString: ptr) + } + var macosIconFrame: MacOSIconFrame { let defaultValue = MacOSIconFrame.aluminum guard let config = self.config else { return defaultValue } diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index 9b05934df..73487f1bd 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -280,6 +280,7 @@ extension Ghostty { case paper case retro case xray + case custom case customStyle = "custom-style" } diff --git a/src/config/Config.zig b/src/config/Config.zig index 5ac2d6617..178b9f851 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -2735,6 +2735,8 @@ keybind: Keybinds = .{}, /// * `blueprint`, `chalkboard`, `microchip`, `glass`, `holographic`, /// `paper`, `retro`, `xray` - Official variants of the Ghostty icon /// hand-created by artists (no AI). +/// * `custom` - Use a completely custom icon. The location must be specified +/// using the additional `macos-custom-icon` configuration /// * `custom-style` - Use the official Ghostty icon but with custom /// styles applied to various layers. The custom styles must be /// specified using the additional `macos-icon`-prefixed configurations. @@ -2753,6 +2755,15 @@ keybind: Keybinds = .{}, /// effort. @"macos-icon": MacAppIcon = .official, +/// The absolute path to the custom icon file. +/// Supported formats include PNG, JPEG, and ICNS. +/// +/// Defaults to `~/.config/ghostty/Ghostty.icns` +/// +/// Note: This configuration is required when `macos-icon` is set to +/// `custom` +@"macos-custom-icon": ?[]const u8 = null, + /// The material to use for the frame of the macOS app icon. /// /// Valid values: @@ -6975,6 +6986,7 @@ pub const MacAppIcon = enum { paper, retro, xray, + custom, @"custom-style", };