From 1aa77837eba4667fc8ea68018e1dff7dd3036b62 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Nov 2024 14:20:09 -0800 Subject: [PATCH] macos: use correct title background if top surface --- .../Features/Terminal/TerminalController.swift | 15 +++++---------- macos/Sources/Helpers/OSColor+Extension.swift | 8 ++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 75bb0e3bd..81c74987b 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -191,15 +191,10 @@ class TerminalController: BaseTerminalController { private func syncAppearance(_ surfaceConfig: Ghostty.SurfaceView.DerivedConfig) { guard let window = self.window as? TerminalWindow else { return } - // If our window is not visible, then delay this. This is possible specifically - // during state restoration but probably in other scenarios as well. To delay, - // we just loop directly on the dispatch queue. We have to delay because some - // APIs such as window blur have no effect unless the window is visible. - guard window.isVisible else { - // Weak window so that if the window changes or is destroyed we aren't holding a ref - DispatchQueue.main.async { [weak self] in self?.syncAppearance(surfaceConfig) } - return - } + // 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. + guard window.isVisible else { return } // Set the font for the window and tab titles. if let titleFontName = surfaceConfig.windowTitleFontFamily { @@ -233,7 +228,7 @@ class TerminalController: BaseTerminalController { let backgroundColor: OSColor if let surfaceTree { if let focusedSurface, surfaceTree.doesBorderTop(view: focusedSurface) { - backgroundColor = OSColor(focusedSurface.backgroundColor ?? derivedConfig.backgroundColor) + backgroundColor = OSColor(focusedSurface.backgroundColor ?? surfaceConfig.backgroundColor) } else { // We don't have a focused surface or our surface doesn't border the // top. We choose to match the color of the top-left most surface. diff --git a/macos/Sources/Helpers/OSColor+Extension.swift b/macos/Sources/Helpers/OSColor+Extension.swift index a6d545f2b..7cdfcc1e6 100644 --- a/macos/Sources/Helpers/OSColor+Extension.swift +++ b/macos/Sources/Helpers/OSColor+Extension.swift @@ -21,6 +21,14 @@ extension OSColor { return (0.299 * r) + (0.587 * g) + (0.114 * b) } + var hexString: String? { + guard let rgb = usingColorSpace(.deviceRGB) else { return nil } + let red = Int(rgb.redComponent * 255) + let green = Int(rgb.greenComponent * 255) + let blue = Int(rgb.blueComponent * 255) + return String(format: "#%02X%02X%02X", red, green, blue) + } + 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)