mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: support the macos-icon configurations
This commit is contained in:
@ -527,13 +527,19 @@ class AppDelegate: NSObject,
|
||||
GlobalEventTap.shared.disable()
|
||||
}
|
||||
|
||||
if let colorizedIcon = ColorizedGhosttyIcon(
|
||||
screenColors: [],
|
||||
ghostColor: .yellow
|
||||
).makeImage() {
|
||||
self.appIcon = colorizedIcon
|
||||
} else {
|
||||
switch (config.macosIcon) {
|
||||
case .official:
|
||||
self.appIcon = nil
|
||||
break
|
||||
|
||||
case .customColor:
|
||||
guard let ghostColor = config.macosIconGhostColor else { break }
|
||||
guard let screenColors = config.macosIconScreenColor else { break }
|
||||
guard let icon = ColorizedGhosttyIcon(
|
||||
screenColors: screenColors,
|
||||
ghostColor: ghostColor
|
||||
).makeImage() else { break }
|
||||
self.appIcon = icon
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,6 +252,35 @@ extension Ghostty {
|
||||
return v
|
||||
}
|
||||
|
||||
var macosIcon: MacOSIcon {
|
||||
let defaultValue = MacOSIcon.official
|
||||
guard let config = self.config else { return defaultValue }
|
||||
var v: UnsafePointer<Int8>? = nil
|
||||
let key = "macos-icon"
|
||||
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 MacOSIcon(rawValue: str) ?? defaultValue
|
||||
}
|
||||
|
||||
var macosIconGhostColor: OSColor? {
|
||||
guard let config = self.config else { return nil }
|
||||
var v: ghostty_config_color_s = .init()
|
||||
let key = "macos-icon-ghost-color"
|
||||
guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return nil }
|
||||
return .init(ghostty: v)
|
||||
}
|
||||
|
||||
var macosIconScreenColor: [OSColor]? {
|
||||
guard let config = self.config else { return nil }
|
||||
var v: ghostty_config_color_list_s = .init()
|
||||
let key = "macos-icon-screen-color"
|
||||
guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return nil }
|
||||
guard v.len > 0 else { return nil }
|
||||
let buffer = UnsafeBufferPointer(start: v.colors, count: v.len)
|
||||
return buffer.map { .init(ghostty: $0) }
|
||||
}
|
||||
|
||||
var focusFollowsMouse : Bool {
|
||||
guard let config = self.config else { return false }
|
||||
var v = false;
|
||||
|
@ -195,6 +195,12 @@ extension Ghostty {
|
||||
}
|
||||
}
|
||||
|
||||
/// macos-icon
|
||||
enum MacOSIcon: String {
|
||||
case official
|
||||
case customColor = "custom-color"
|
||||
}
|
||||
|
||||
/// Enum for the macos-titlebar-proxy-icon config option
|
||||
enum MacOSTitlebarProxyIcon: String {
|
||||
case visible
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import GhosttyKit
|
||||
|
||||
extension OSColor {
|
||||
var isLightColor: Bool {
|
||||
@ -89,3 +90,15 @@ extension OSColor {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Ghostty Types
|
||||
|
||||
extension OSColor {
|
||||
/// Create a color from a Ghostty color.
|
||||
convenience init(ghostty: ghostty_config_color_s) {
|
||||
let red = Double(ghostty.r) / 255
|
||||
let green = Double(ghostty.g) / 255
|
||||
let blue = Double(ghostty.b) / 255
|
||||
self.init(red: red, green: green, blue: blue, alpha: 1)
|
||||
}
|
||||
}
|
||||
|
@ -3704,8 +3704,8 @@ pub const ColorList = struct {
|
||||
const input = input_ orelse return error.ValueRequired;
|
||||
if (input.len == 0) return error.ValueRequired;
|
||||
|
||||
// Whenever a color list is set, we reset the list
|
||||
self.colors.clearRetainingCapacity();
|
||||
// Always reset on parse
|
||||
self.* = .{};
|
||||
|
||||
// Split the input by commas and parse each color
|
||||
var it = std.mem.tokenizeScalar(u8, input, ',');
|
||||
|
Reference in New Issue
Block a user