From 22819f8a296e799b75904f03ddf1d4204fd9c6be Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 Jun 2025 11:40:54 -0700 Subject: [PATCH] macos: transfer doesBorderTop --- macos/Sources/Features/Splits/SplitTree.swift | 33 +++++++++++++++++++ .../Terminal/TerminalController.swift | 10 ++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Features/Splits/SplitTree.swift b/macos/Sources/Features/Splits/SplitTree.swift index f458b5dee..78bed7120 100644 --- a/macos/Sources/Features/Splits/SplitTree.swift +++ b/macos/Sources/Features/Splits/SplitTree.swift @@ -774,6 +774,39 @@ extension SplitTree.Spatial { } } } + + /// Returns whether the given node borders the specified side of the spatial bounds. + /// + /// This method checks if a node's bounds touch the edge of the overall spatial area: + /// - **Up**: Node's top edge touches the top of the spatial area (Y=0) + /// - **Down**: Node's bottom edge touches the bottom of the spatial area (Y=maxY) + /// - **Left**: Node's left edge touches the left of the spatial area (X=0) + /// - **Right**: Node's right edge touches the right of the spatial area (X=maxX) + /// + /// - Parameters: + /// - side: The side of the spatial bounds to check + /// - node: The node to check if it borders the specified side + /// - Returns: True if the node borders the specified side, false otherwise + func doesBorder(side: Direction, from node: SplitTree.Node) -> Bool { + // Find the slot for this node + guard let slot = slots.first(where: { $0.node == node }) else { return false } + + // Calculate the overall bounds of all slots + let overallBounds = slots.reduce(CGRect.null) { result, slot in + result.union(slot.bounds) + } + + return switch side { + case .up: + slot.bounds.minY == overallBounds.minY + case .down: + slot.bounds.maxY == overallBounds.maxY + case .left: + slot.bounds.minX == overallBounds.minX + case .right: + slot.bounds.maxX == overallBounds.maxX + } + } } // MARK: SplitTree.Node Protocols diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 120ac6377..eb140b2a3 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -282,15 +282,19 @@ class TerminalController: BaseTerminalController { // If it does, we match the focused surface. If it doesn't, we use the app // configuration. let backgroundColor: OSColor - if let surfaceTree { - if let focusedSurface, surfaceTree.doesBorderTop(view: focusedSurface) { + if !surfaceTree2.isEmpty { + if let focusedSurface = focusedSurface, + let treeRoot = surfaceTree2.root, + let focusedNode = treeRoot.node(view: focusedSurface), + treeRoot.spatial().doesBorder(side: .up, from: focusedNode) { // Similar to above, an alpha component of "0" causes compositor issues, so // we use 0.001. See: https://github.com/ghostty-org/ghostty/pull/4308 backgroundColor = OSColor(focusedSurface.backgroundColor ?? surfaceConfig.backgroundColor).withAlphaComponent(0.001) } 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. - backgroundColor = OSColor(surfaceTree.topLeft().backgroundColor ?? derivedConfig.backgroundColor) + let topLeftSurface = surfaceTree2.root?.leftmostLeaf() + backgroundColor = OSColor(topLeftSurface?.backgroundColor ?? derivedConfig.backgroundColor) } } else { backgroundColor = OSColor(self.derivedConfig.backgroundColor)