macos: fix background color of terminal window to match surface

pull/7588/head
Mitchell Hashimoto 2025-06-12 21:33:40 -07:00
parent 9d9c451b0a
commit 17ad77b5b0
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 11 additions and 10 deletions

View File

@ -322,22 +322,23 @@ class TerminalWindow: NSWindow {
/// change the alpha channel again manually. /// change the alpha channel again manually.
var preferredBackgroundColor: NSColor? { var preferredBackgroundColor: NSColor? {
if let terminalController, !terminalController.surfaceTree.isEmpty { if let terminalController, !terminalController.surfaceTree.isEmpty {
let surface: Ghostty.SurfaceView?
// If our focused surface borders the top then we prefer its background color // If our focused surface borders the top then we prefer its background color
if let focusedSurface = terminalController.focusedSurface, if let focusedSurface = terminalController.focusedSurface,
let treeRoot = terminalController.surfaceTree.root, let treeRoot = terminalController.surfaceTree.root,
let focusedNode = treeRoot.node(view: focusedSurface), let focusedNode = treeRoot.node(view: focusedSurface),
treeRoot.spatial().doesBorder(side: .up, from: focusedNode), treeRoot.spatial().doesBorder(side: .up, from: focusedNode) {
let backgroundcolor = focusedSurface.backgroundColor { surface = focusedSurface
let alpha = focusedSurface.derivedConfig.backgroundOpacity.clamped(to: 0.001...1) } else {
return NSColor(backgroundcolor).withAlphaComponent(alpha) // If it doesn't border the top, we use the top-left leaf
surface = terminalController.surfaceTree.root?.leftmostLeaf()
} }
// Doesn't border the top or we don't have a focused surface, so if let surface {
// we try to match the top-left surface. let backgroundColor = surface.backgroundColor ?? surface.derivedConfig.backgroundColor
let topLeftSurface = terminalController.surfaceTree.root?.leftmostLeaf() let alpha = surface.derivedConfig.backgroundOpacity.clamped(to: 0.001...1)
if let topLeftBgColor = topLeftSurface?.backgroundColor { return NSColor(backgroundColor).withAlphaComponent(alpha)
let alpha = topLeftSurface?.derivedConfig.backgroundOpacity.clamped(to: 0.001...1) ?? 1
return NSColor(topLeftBgColor).withAlphaComponent(alpha)
} }
} }