mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: only set titlebar color with enough luminance to avoid #1549
This commit is contained in:
@ -246,8 +246,12 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
||||
// when cascading.
|
||||
window.center()
|
||||
|
||||
// Set the background color of the window
|
||||
window.backgroundColor = NSColor(ghostty.config.backgroundColor)
|
||||
// Set the background color of the window. We only do this if the lum is
|
||||
// over 0.1 to prevent: https://github.com/mitchellh/ghostty/issues/1549
|
||||
let bgColor = NSColor(ghostty.config.backgroundColor)
|
||||
if (bgColor.luminance > 0.1) {
|
||||
window.backgroundColor = NSColor(ghostty.config.backgroundColor)
|
||||
}
|
||||
|
||||
// This makes sure our titlebar renders correctly when there is a transparent background
|
||||
window.titlebarOpacity = ghostty.config.backgroundOpacity
|
||||
|
@ -2,19 +2,29 @@ import Foundation
|
||||
|
||||
extension OSColor {
|
||||
var isLightColor: Bool {
|
||||
return self.luminance > 0.5
|
||||
}
|
||||
|
||||
var luminance: Double {
|
||||
var r: CGFloat = 0
|
||||
var g: CGFloat = 0
|
||||
var b: CGFloat = 0
|
||||
var a: CGFloat = 0
|
||||
|
||||
self.getRed(&r, green: &g, blue: &b, alpha: &a)
|
||||
let luminance = (0.299 * r) + (0.587 * g) + (0.114 * b)
|
||||
return luminance > 0.5
|
||||
|
||||
// getRed:green:blue:alpha requires sRGB space
|
||||
guard let rgb = self.usingColorSpace(.sRGB) else { return 0 }
|
||||
rgb.getRed(&r, green: &g, blue: &b, alpha: &a)
|
||||
return (0.299 * r) + (0.587 * g) + (0.114 * b)
|
||||
}
|
||||
|
||||
func darken(by amount: CGFloat) -> OSColor {
|
||||
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
|
||||
self.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
|
||||
return OSColor(hue: h, saturation: s, brightness: min(b * (1 - amount), 1), alpha: a)
|
||||
return OSColor(
|
||||
hue: h,
|
||||
saturation: s,
|
||||
brightness: min(b * (1 - amount), 1),
|
||||
alpha: a
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user