diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 863e9f88d..f2f9ed277 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -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 diff --git a/macos/Sources/Helpers/OSColor+Extension.swift b/macos/Sources/Helpers/OSColor+Extension.swift index f8bfcd134..7cb3e28ef 100644 --- a/macos/Sources/Helpers/OSColor+Extension.swift +++ b/macos/Sources/Helpers/OSColor+Extension.swift @@ -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 + ) } }