macos: fix background color of terminal window to match surface
parent
9d9c451b0a
commit
17ad77b5b0
|
|
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue