macos: add macos-icon-frame and some custom frame styles

This commit is contained in:
Mitchell Hashimoto
2024-12-21 19:48:13 -08:00
parent bcced34726
commit 1f468202d4
14 changed files with 116 additions and 15 deletions

View File

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 145 KiB

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "beige.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "chrome.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "plastic.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "original"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View File

@ -532,12 +532,13 @@ class AppDelegate: NSObject,
self.appIcon = nil self.appIcon = nil
break break
case .customColor: case .customStyle:
guard let ghostColor = config.macosIconGhostColor else { break } guard let ghostColor = config.macosIconGhostColor else { break }
guard let screenColors = config.macosIconScreenColor else { break } guard let screenColors = config.macosIconScreenColor else { break }
guard let icon = ColorizedGhosttyIcon( guard let icon = ColorizedGhosttyIcon(
screenColors: screenColors, screenColors: screenColors,
ghostColor: ghostColor ghostColor: ghostColor,
frame: config.macosIconFrame
).makeImage() else { break } ).makeImage() else { break }
self.appIcon = icon self.appIcon = icon
} }

View File

@ -7,16 +7,26 @@ struct ColorizedGhosttyIcon {
/// The color of the ghost. /// The color of the ghost.
let ghostColor: NSColor let ghostColor: NSColor
/// The frame type to use
let frame: Ghostty.MacOSIconFrame
/// Make a custom colorized ghostty icon. /// Make a custom colorized ghostty icon.
func makeImage() -> NSImage? { func makeImage() -> NSImage? {
// All of our layers (in order) // All of our layers (not in order)
guard let base = NSImage(named: "CustomIconBase") else { return nil }
guard let screen = NSImage(named: "CustomIconScreen") else { return nil } guard let screen = NSImage(named: "CustomIconScreen") else { return nil }
guard let screenMask = NSImage(named: "CustomIconScreenMask") else { return nil } guard let screenMask = NSImage(named: "CustomIconScreenMask") else { return nil }
guard let ghost = NSImage(named: "CustomIconGhost") else { return nil } guard let ghost = NSImage(named: "CustomIconGhost") else { return nil }
guard let crt = NSImage(named: "CustomIconCRT") else { return nil } guard let crt = NSImage(named: "CustomIconCRT") else { return nil }
guard let gloss = NSImage(named: "CustomIconGloss") else { return nil } guard let gloss = NSImage(named: "CustomIconGloss") else { return nil }
let baseName = switch (frame) {
case .aluminum: "CustomIconBaseAluminum"
case .beige: "CustomIconBaseBeige"
case .chrome: "CustomIconBaseChrome"
case .plastic: "CustomIconBasePlastic"
}
guard let base = NSImage(named: baseName) else { return nil }
// Apply our color in various ways to our layers. // Apply our color in various ways to our layers.
// NOTE: These functions are not built-in, they're implemented as an extension // NOTE: These functions are not built-in, they're implemented as an extension
// to NSImage in NSImage+Extension.swift. // to NSImage in NSImage+Extension.swift.

View File

@ -6,7 +6,8 @@ struct ColorizedGhosttyIconView: View {
var body: some View { var body: some View {
Image(nsImage: ColorizedGhosttyIcon( Image(nsImage: ColorizedGhosttyIcon(
screenColors: [.purple, .blue], screenColors: [.purple, .blue],
ghostColor: .yellow ghostColor: .yellow,
frame: .aluminum
).makeImage()!) ).makeImage()!)
} }
} }

View File

@ -263,6 +263,17 @@ extension Ghostty {
return MacOSIcon(rawValue: str) ?? defaultValue return MacOSIcon(rawValue: str) ?? defaultValue
} }
var macosIconFrame: MacOSIconFrame {
let defaultValue = MacOSIconFrame.aluminum
guard let config = self.config else { return defaultValue }
var v: UnsafePointer<Int8>? = nil
let key = "macos-icon-frame"
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 MacOSIconFrame(rawValue: str) ?? defaultValue
}
var macosIconGhostColor: OSColor? { var macosIconGhostColor: OSColor? {
guard let config = self.config else { return nil } guard let config = self.config else { return nil }
var v: ghostty_config_color_s = .init() var v: ghostty_config_color_s = .init()

View File

@ -198,7 +198,15 @@ extension Ghostty {
/// macos-icon /// macos-icon
enum MacOSIcon: String { enum MacOSIcon: String {
case official case official
case customColor = "custom-color" case customStyle = "custom-style"
}
/// macos-icon-frame
enum MacOSIconFrame: String {
case aluminum
case beige
case plastic
case chrome
} }
/// Enum for the macos-titlebar-proxy-icon config option /// Enum for the macos-titlebar-proxy-icon config option

View File

@ -16,7 +16,6 @@ const build_config = @import("../build_config.zig");
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator; const ArenaAllocator = std.heap.ArenaAllocator;
const build_config = @import("../build_config.zig");
const global_state = &@import("../global.zig").state; const global_state = &@import("../global.zig").state;
const fontpkg = @import("../font/main.zig"); const fontpkg = @import("../font/main.zig");
const inputpkg = @import("../input.zig"); const inputpkg = @import("../input.zig");
@ -1688,11 +1687,11 @@ keybind: Keybinds = .{},
/// Valid values: /// Valid values:
/// ///
/// * `official` - Use the official Ghostty icon. /// * `official` - Use the official Ghostty icon.
/// * `custom-color` - Use the official Ghostty icon but with custom /// * `custom-style` - Use the official Ghostty icon but with custom
/// colors applied to various layers. The custom colors must be /// styles applied to various layers. The custom styles must be
/// specified using the additional `macos-icon-x-color` configurations. /// specified using the additional `macos-icon`-prefixed configurations.
/// Note that all colors are required. If any are missing, the icon /// The `macos-icon-ghost-color` and `macos-icon-screen-color`
/// will not be changed. /// configurations are required for this style.
/// ///
/// Other caveats: /// Other caveats:
/// ///
@ -1703,12 +1702,27 @@ keybind: Keybinds = .{},
/// ///
@"macos-icon": MacAppIcon = .official, @"macos-icon": MacAppIcon = .official,
/// The material to use for the frame of the macOS app icon.
///
/// Valid values:
///
/// * `aluminum` - A brushed aluminum frame. This is the default.
/// * `beige` - A classic 90's computer beige frame.
/// * `plastic` - A glossy, dark plastic frame.
/// * `chrome` - A shiny chrome frame.
///
/// This only has an effect when `macos-icon` is set to `custom-style`.
@"macos-icon-frame": MacAppIconFrame = .aluminum,
/// The color of the ghost in the macOS app icon. /// The color of the ghost in the macOS app icon.
/// ///
/// The format of the color is the same as the `background` configuration; /// The format of the color is the same as the `background` configuration;
/// see that for more information. /// see that for more information.
/// ///
/// This only has an effect when `macos-icon` is set to `custom-color`. /// Note: This configuration is required when `macos-icon` is set to
/// `custom-style`.
///
/// This only has an effect when `macos-icon` is set to `custom-style`.
@"macos-icon-ghost-color": ?Color = null, @"macos-icon-ghost-color": ?Color = null,
/// The color of the screen in the macOS app icon. /// The color of the screen in the macOS app icon.
@ -1718,7 +1732,10 @@ keybind: Keybinds = .{},
/// format of the color is the same as the `background` configuration; /// format of the color is the same as the `background` configuration;
/// see that for more information. /// see that for more information.
/// ///
/// This only has an effect when `macos-icon` is set to `custom-color`. /// Note: This configuration is required when `macos-icon` is set to
/// `custom-style`.
///
/// This only has an effect when `macos-icon` is set to `custom-style`.
@"macos-icon-screen-color": ?ColorList = null, @"macos-icon-screen-color": ?ColorList = null,
/// Put every surface (tab, split, window) into a dedicated Linux cgroup. /// Put every surface (tab, split, window) into a dedicated Linux cgroup.
@ -5107,7 +5124,15 @@ pub const MacTitlebarProxyIcon = enum {
/// format at all. /// format at all.
pub const MacAppIcon = enum { pub const MacAppIcon = enum {
official, official,
@"custom-color", @"custom-style",
};
/// See macos-icon-frame
pub const MacAppIconFrame = enum {
aluminum,
beige,
plastic,
chrome,
}; };
/// See gtk-single-instance /// See gtk-single-instance