Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import CmuxNextSettings
var tabsShown = true
/// Native chrome holes, in page coordinates; Session Info adds its own overlay hole.
var holes: [CGRect] = []
/// What the pane's toolbar hole paints (``holeFill(chromium:shares:tabsShown:page:)``), set with each offer.
public private(set) var holeFill: CGColor?
private var offeredNativeRowTools: Bool?
/// Only a shared page host has the return event stream needed by native controls.
var supportsNativeTools = false
Expand Down Expand Up @@ -72,6 +74,9 @@ import CmuxNextSettings
let next = (height: on ? height / zoom : 0, trailingInset: on ? max(0, trailingInset) / zoom : 0, soloTab: on && !row.tabsShown)
let shares = on && row.toolsWidth > 0
view.setTabRowCover(shares ? height : 0) // the pane lays the view under the strip only then
// The engine, not the shared host (which runs WebKit too, where the page is under the toolbar).
row.holeFill = holeFill(chromium: view.chromiumPage != nil, shares: shares, tabsShown: row.tabsShown,
page: view.performWithTheme { AgentPaneTheme.pageBackground(view.themeTokens, surface: view.surfaceKind) })
if let page = view.page {
// A Chromium chat is a window above the pane: it leaves the pane's tabs and toolbar uncovered.
// The holes are worked out from the row's top-left corner; the chat view is not flipped, so
Expand All @@ -88,6 +93,17 @@ import CmuxNextSettings
let event = row.event
view.deliver([event], scripts: ["window.cmuxAcpmuxBridge?.applyTabRow?.(\(event.value.compactText));"])
}

/// The color the pane's toolbar hole paints so the row reads as one surface (``PaneTabRowSharing/tabRowHoleFill``):
/// a Chromium chat is a window above the pane that leaves the toolbar uncovered, and alone in its pane its page
/// paints `page` (`--cmux-surface-background`) across the whole row (header.css, `[data-solo-tab]`), so the hole
/// paints it too. With its tabs shown the page leaves the row clear, and on WebKit the page is under the toolbar:
/// nil, as is a clear page color. A theme change lays the pane out again, which offers the row and reads it anew.
static func holeFill(chromium: Bool, shares: Bool, tabsShown: Bool, page: @autoclosure () -> ThemeRGB) -> CGColor? {
guard chromium, shares, !tabsShown else { return nil }
let color = page()
return color.alpha > 0 ? color.cgColor : nil
}
}

/// The parts of a shared tab row `width` points wide and `height` tall (top-left origin) that the
Expand Down Expand Up @@ -118,4 +134,5 @@ extension PaneTabRowSharing where Self: AgentPaneView {
public func setTabRow(height: CGFloat, trailingInset: CGFloat) { AgentPaneTabRow.offer(points: height, trailingInset: trailingInset, to: self) }
public func setTabRowTabs(shown: Bool) { model.tabRow.tabsShown = shown }
public var tabRowTakesLoneTab: Bool { true }
public var tabRowHoleFill: CGColor? { model.tabRow.holeFill }
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ final class PaneContentView: NSView, PaneContentChrome {
}
layoutParked()
layoutAgentTag()
if hostsContent, let sharing = content as? PaneTabRowSharing { sharing.offerTabRow(height: rowContent == nil ? 0 : shown, trailingInset: tools, tabs: !loneTab, in: self) }
if hostsContent, let sharing = content as? PaneTabRowSharing { sharing.offerTabRow(height: rowContent == nil ? 0 : shown, trailingInset: tools, tabs: !loneTab, toolbar: toolbar?.view, in: self) } else { toolbar?.view.paintTabRowHole(nil) }
if hostChanged { onResize?() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public protocol PaneTabRowSharing: AnyObject {
func setTabRowTabs(shown: Bool)
/// The view takes the whole row when its pane holds one tab, and the pane hides that tab (a chat; Leo 2026-11-03).
var tabRowTakesLoneTab: Bool { get }
/// What the pane's toolbar fills its frame with while the view shares the row, so the toolbar reads as the
/// surface the view paints around it: a view that is a window above the pane (a Chromium chat) leaves the
/// toolbar a hole, and where it paints its own surface across the row (alone in its pane) the hole would
/// show the pane's instead, a block of another shade beside the tools. Nil: the row is clear there.
var tabRowHoleFill: CGColor? { get }
}

extension PaneTabRowSharing {
public func setTabRowTabs(shown: Bool) {}
public var tabRowTakesLoneTab: Bool { false }
public var tabRowHoleFill: CGColor? { nil }

/// Points the strip gives up beside the view's tools in a row `room` wide (at most half of it).
public func tabRowWidth(room: CGFloat) -> CGFloat { min(max(0, tabRowToolsWidth ?? 0), max(0, room / 2)) }
Expand All @@ -39,13 +45,15 @@ extension PaneTabRowSharing {

/// Offers the view the row (`height` 0: none); a change in its tools' width lays `pane` out
/// again while the view is still in it (a view another pane took gets its row from that pane).
public func offerTabRow(height: CGFloat, trailingInset: CGFloat, tabs: Bool = true, in pane: NSView) {
/// `toolbar`: the pane's own buttons at the row's trailing end, filled with ``tabRowHoleFill`` after the offer.
public func offerTabRow(height: CGFloat, trailingInset: CGFloat, tabs: Bool = true, toolbar: NSView? = nil, in pane: NSView) {
onTabRowToolsChange = { [weak self, weak pane] in
guard let pane, let view = self as? NSView, view.isDescendant(of: pane) else { return }
pane.needsLayout = true
}
setTabRowTabs(shown: tabs || height <= 0)
setTabRow(height: height, trailingInset: height > 0 ? trailingInset : 0)
toolbar?.paintTabRowHole(height > 0 ? tabRowHoleFill : nil)
}
}

Expand All @@ -67,6 +75,7 @@ extension PaneTabRowForwarding {
public func setTabRow(height: CGFloat, trailingInset: CGFloat) { tabRowSharer?.setTabRow(height: height, trailingInset: trailingInset) }
public func setTabRowTabs(shown: Bool) { tabRowSharer?.setTabRowTabs(shown: shown) }
public var tabRowTakesLoneTab: Bool { tabRowSharer?.tabRowTakesLoneTab ?? false }
public var tabRowHoleFill: CGColor? { tabRowSharer?.tabRowHoleFill }
}

extension NSView {
Expand Down Expand Up @@ -97,4 +106,12 @@ extension NSView {
}

private static let tabRowCoverID = NSUserInterfaceItemIdentifier("cmux.tabRowCover")

/// Fills a pane's toolbar with `fill` (``PaneTabRowSharing/tabRowHoleFill``: a Chromium chat alone in its pane
/// paints its surface across the row and leaves the toolbar a hole, which would show the pane's own shade beside
/// the chat's tools, #33261); nil leaves it clear.
public func paintTabRowHole(_ fill: CGColor?) {
if fill != nil { wantsLayer = true }
if layer?.backgroundColor != fill { layer?.backgroundColor = fill }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if DEBUG
import AppKit
import CmuxNextDesign
import CmuxNextPages
import CmuxNextPagesTestSupport
import CmuxNextSettings
Expand Down Expand Up @@ -78,6 +79,54 @@ struct AgentPaneTabRowHolesTests {
#expect(holes(page, in: view).count == 2)
}

/// Leo (2026-11-03, the nightly): "latest nightly still not fixed yet?" / "i mean the rectangle near the
/// buttons". Alone in its pane a Chromium chat paints its own surface (`appearance.surfaces.agentPane`)
/// across the whole row, but its page window leaves the pane's toolbar a hole, where the pane's own shade
/// showed: a block of another color beside the tools (#33261). The toolbar hole paints the page's surface,
/// so nothing in the row differs from the surface around it; a row the page leaves clear paints nothing.
@Test func aLoneChromiumChatsToolbarHolePaintsThePagesSurface() {
let chat = ThemeRGB(hex: 0x282938)
#expect(AgentPaneTabRow.holeFill(chromium: true, shares: true, tabsShown: false, page: chat) == chat.cgColor)
// Tabs shown: the page leaves the row clear, so the hole shows the same pane the page does.
#expect(AgentPaneTabRow.holeFill(chromium: true, shares: true, tabsShown: true, page: chat) == nil)
// WebKit: the page is under the toolbar and already paints there.
#expect(AgentPaneTabRow.holeFill(chromium: false, shares: true, tabsShown: false, page: chat) == nil)
// Out of the row, or a clear page (glass): nothing.
#expect(AgentPaneTabRow.holeFill(chromium: true, shares: false, tabsShown: false, page: chat) == nil)
#expect(AgentPaneTabRow.holeFill(chromium: true, shares: true, tabsShown: false, page: chat.withAlpha(0)) == nil)
}

/// The chat hands its pane the fill with each offer, in its own theme scope, and drops it with the row.
@Test func aLoneChromiumChatHandsThePaneItsSurfaceForTheToolbar() async throws {
let (view, _) = try await chromiumChat()
view.model.tabRow.report(width: 120)
view.model.tabRow.tabsShown = false
AgentPaneTabRow.offer(points: 36, trailingInset: 60, to: view)
let surface = view.performWithTheme { AgentPaneTheme.pageBackground(view.themeTokens, surface: .agentPane) }
#expect(view.model.tabRow.holeFill == (surface.alpha > 0 ? surface.cgColor : nil))

view.model.tabRow.tabsShown = true
AgentPaneTabRow.offer(points: 36, trailingInset: 60, to: view)
#expect(view.model.tabRow.holeFill == nil)
view.model.tabRow.tabsShown = false
AgentPaneTabRow.offer(points: 0, trailingInset: 0, to: view)
#expect(view.model.tabRow.holeFill == nil)
}

/// A shared page host on WebKit: the page is under the toolbar and already paints there, so a translucent
/// surface would darken twice under a fill (review of #33407).
@Test func aLoneWebKitChatPaintsNoToolbarHole() throws {
let file = try #require(AgentPageTestRoot.page)
let view = try #require(AgentPaneView(model: AgentPaneModel(host: NoHost()), source: .bundled(file), pageHost: true, testRoot: true, chromium: nil))
view.frame = NSRect(x: 0, y: 0, width: 800, height: 600)
view.layoutSubtreeIfNeeded()
#expect(view.chromiumPage == nil)
view.model.tabRow.report(width: 120)
view.model.tabRow.tabsShown = false
AgentPaneTabRow.offer(points: 36, trailingInset: 60, to: view)
#expect(view.model.tabRow.holeFill == nil)
}

@Test func aChatOutOfTheRowCoversNothing() async throws {
let (view, page) = try await chromiumChat()
view.model.tabRow.report(width: 120)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Testing
private(set) var shared: CGFloat = 0
private(set) var tabsShown = true
var onTabRowToolsChange: (() -> Void)?
var tabRowHoleFill: CGColor?
init(need: CGFloat, takesLoneTab: Bool = false) {
self.need = need
tabRowTakesLoneTab = takesLoneTab
Expand Down Expand Up @@ -134,4 +135,35 @@ import Testing
let fill = try #require(pane.stripView.layer?.backgroundColor.flatMap { NSColor(cgColor: $0)?.usingColorSpace(.sRGB) })
#expect(abs(fill.blueComponent - barColor.blue) < 0.01, "the strip paints \(fill), not the tab bar's \(barColor)")
}

/// #33261: a Chromium chat alone in its pane paints its surface across the row and leaves the pane's "…" a
/// hole; the toolbar fills its frame with the chat's fill (`tabRowHoleFill`), so the row is one surface, and
/// goes clear again when the chat leaves the row or gives no fill.
@Test func theToolbarPaintsTheChatsHoleFill() throws {
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 900, height: 500), styleMask: [.titled],
backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
defer { window.orderOut(nil); window.close() }
let pane = PaneContentView(stripModel: TabStripModel(tabs: [TabItem(id: TabID("t0"), title: "Chat")]), reveal: LaunchReveal(deadline: .zero))
pane.frame = window.contentLayoutRect
window.contentView = pane
pane.toolbar = PaneToolbar(registry: { nil }, newTabMenu: { nil })
let chat = RowChat(need: 220, takesLoneTab: true)
let fill = ThemeRGB(hex: 0x282938).cgColor
chat.tabRowHoleFill = fill
_ = pane.show(chat)
let settle = {
for _ in 0..<4 {
pane.needsLayout = true
pane.layoutSubtreeIfNeeded()
}
}
settle()
let toolbar = try #require(pane.toolbar?.view)
#expect(pane.contentHost.frame.minY < pane.stripView.frame.maxY, "the chat shares the row")
#expect(toolbar.layer?.backgroundColor == fill)
chat.tabRowHoleFill = nil
settle()
#expect(toolbar.layer?.backgroundColor == nil)
}
}