Add support for 'custom' on 'macos_icon' to support a completely custom app icon

pull/8230/head
Nicholas Mata 2025-08-14 03:17:33 -07:00 committed by Mitchell Hashimoto
parent 29419e7aac
commit 5948bd3f02
4 changed files with 34 additions and 0 deletions

View File

@ -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 }

View File

@ -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<Int8>? = 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 }

View File

@ -280,6 +280,7 @@ extension Ghostty {
case paper
case retro
case xray
case custom
case customStyle = "custom-style"
}

View File

@ -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",
};