fix: use surfaceConfig.backgroundColor to determine if the theme is light or dark

Signed-off-by: Aaron Ruan <i@ar212.com>
This commit is contained in:
Aaron Ruan
2025-02-20 21:25:05 +08:00
committed by Mitchell Hashimoto
parent 3a7fb03ef9
commit 602b47ff4e
2 changed files with 8 additions and 2 deletions

View File

@@ -218,6 +218,9 @@ class TerminalController: BaseTerminalController {
// Set our explicit appearance if we need to based on the configuration.
window.appearance = surfaceConfig.windowAppearance
// Update our window light/darkness based on our updated background color
window.isLightTheme = OSColor(surfaceConfig.backgroundColor).isLightColor
// If our window is not visible, then we do nothing. Some things such as blurring
// have no effect if the window is not visible. Ultimately, we'll have this called
// at some point when a surface becomes focused.

View File

@@ -3,6 +3,10 @@ import Cocoa
class TerminalWindow: NSWindow {
@objc dynamic var keyEquivalent: String = ""
/// This is used to determine if certain elements should be drawn light or dark and should
/// be updated whenever the window background color or surrounding elements changes.
var isLightTheme: Bool = false
lazy var titlebarColor: NSColor = backgroundColor {
didSet {
guard let titlebarContainer else { return }
@@ -295,7 +299,6 @@ class TerminalWindow: NSWindow {
if newTabButtonImageLayer == nil {
let isLightTheme = backgroundColor.isLightColor
let fillColor: NSColor = isLightTheme ? .black.withAlphaComponent(0.85) : .white.withAlphaComponent(0.85)
let newImage = NSImage(size: newTabButtonImage.size, flipped: false) { rect in
newTabButtonImage.draw(in: rect)
@@ -714,7 +717,7 @@ fileprivate class WindowButtonsBackdropView: NSView {
init(window: TerminalWindow) {
self.terminalWindow = window
self.isLightTheme = window.backgroundColor.isLightColor
self.isLightTheme = window.isLightTheme
super.init(frame: .zero)