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.
|
// when cascading.
|
||||||
window.center()
|
window.center()
|
||||||
|
|
||||||
// Set the background color of the window
|
// Set the background color of the window. We only do this if the lum is
|
||||||
window.backgroundColor = NSColor(ghostty.config.backgroundColor)
|
// 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
|
// This makes sure our titlebar renders correctly when there is a transparent background
|
||||||
window.titlebarOpacity = ghostty.config.backgroundOpacity
|
window.titlebarOpacity = ghostty.config.backgroundOpacity
|
||||||
|
@ -2,19 +2,29 @@ import Foundation
|
|||||||
|
|
||||||
extension OSColor {
|
extension OSColor {
|
||||||
var isLightColor: Bool {
|
var isLightColor: Bool {
|
||||||
|
return self.luminance > 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
var luminance: Double {
|
||||||
var r: CGFloat = 0
|
var r: CGFloat = 0
|
||||||
var g: CGFloat = 0
|
var g: CGFloat = 0
|
||||||
var b: CGFloat = 0
|
var b: CGFloat = 0
|
||||||
var a: CGFloat = 0
|
var a: CGFloat = 0
|
||||||
|
|
||||||
self.getRed(&r, green: &g, blue: &b, alpha: &a)
|
// getRed:green:blue:alpha requires sRGB space
|
||||||
let luminance = (0.299 * r) + (0.587 * g) + (0.114 * b)
|
guard let rgb = self.usingColorSpace(.sRGB) else { return 0 }
|
||||||
return luminance > 0.5
|
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 {
|
func darken(by amount: CGFloat) -> OSColor {
|
||||||
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
|
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
|
||||||
self.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
|
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