From f1133fcc122fd360e0f3cbe51007686425bb3cee Mon Sep 17 00:00:00 2001 From: Leo Li Date: Sat, 26 Sep 2026 22:33:12 -0400 Subject: [PATCH 1/2] test: expect the portal reconcile to move the unfocused dim with focus The synchronous portal reconcile reveals a terminal and sets its active state, but leaves the unfocused-split dim at whatever the SwiftUI host last applied. This regression expects the reconcile to clear the dim on the terminal it activates, including a tab that was dimmed while hidden. Co-Authored-By: Claude Opus 5.5 --- cmuxTests/WorkspaceUnitTests.swift | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cmuxTests/WorkspaceUnitTests.swift b/cmuxTests/WorkspaceUnitTests.swift index 548d67f78f78..f0cc0660d549 100644 --- a/cmuxTests/WorkspaceUnitTests.swift +++ b/cmuxTests/WorkspaceUnitTests.swift @@ -4729,6 +4729,43 @@ final class WorkspaceTeardownTests: XCTestCase { #endif } + func testPortalReconcileMovesUnfocusedDimWithFocus() throws { +#if DEBUG + let workspace = Workspace() + let firstPanelId = try XCTUnwrap(workspace.focusedPanelId) + let firstPanel = try XCTUnwrap(workspace.terminalPanel(for: firstPanelId)) + let splitPanel = try XCTUnwrap( + workspace.newTerminalSplit(from: firstPanelId, orientation: .horizontal) + ) + workspace.focusPanel(firstPanelId) + XCTAssertEqual(workspace.focusedPanelId, firstPanelId) + + // The SwiftUI hosts last rendered the split as focused and have not had + // their next portal turn yet. + firstPanel.hostedView.setInactiveOverlay(color: .black, opacity: 0.3, visible: true) + splitPanel.hostedView.setInactiveOverlay(color: .black, opacity: 0.3, visible: false) + workspace.debugReconcileTerminalPortalVisibilityForTesting() + XCTAssertTrue( + firstPanel.hostedView.debugInactiveOverlayState().isHidden, + "The focused terminal must lose its dim in the same pass that activates it" + ) + XCTAssertFalse(splitPanel.hostedView.debugInactiveOverlayState().isHidden) + + // A background tab keeps the dim it got while hidden until it is revealed. + let paneId = try XCTUnwrap(workspace.bonsplitController.focusedPaneId) + let backgroundTab = try XCTUnwrap(workspace.newTerminalSurface(inPane: paneId, focus: false)) + backgroundTab.hostedView.setInactiveOverlay(color: .black, opacity: 0.3, visible: true) + workspace.focusPanel(backgroundTab.id) + workspace.debugReconcileTerminalPortalVisibilityForTesting() + XCTAssertTrue( + backgroundTab.hostedView.debugInactiveOverlayState().isHidden, + "A revealed tab must not show the dim it got while hidden" + ) +#else + throw XCTSkip("Debug-only regression test") +#endif + } + func testSelectingWorkspaceTodoPaneHidesDeselectedTerminalPortal() throws { let workspace = Workspace() let terminalPanelId = try XCTUnwrap(workspace.focusedPanelId) From 5f12a1127052591a451d4876134cb79e1512a538 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Sat, 26 Sep 2026 22:50:36 -0400 Subject: [PATCH 2/2] Keep the unfocused-pane dim in step with focus when a pane is revealed applyTabSelectionNow reveals the target terminal and sets its active state synchronously through reconcileTerminalPortalVisibilityForCurrentRenderedLayout, but the unfocused-split dim was only updated by the SwiftUI host's portal reconciliation on a later run-loop turn. A tab or workspace dimmed while hidden was therefore committed on screen dimmed, then brightened. The reconcile now sets the dim with visibility and active state, using the same split rule as WorkspaceContentView (Workspace.hasMultipleSplitSurfaces). GhosttySurfaceScrollView keeps the last dim color and opacity so the reconcile only toggles visibility. Canvas hosts keep their own dim rule. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + Sources/GhosttyTerminalView.swift | 11 +++++++++++ Sources/Workspace.swift | 15 +++++++++++++++ Sources/WorkspaceContentView.swift | 3 +-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3c5a66f4bf..fefbb01187dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to cmux are documented here. - The Settings > Mobile pairing row says Open Pairing and no longer promises a Tailscale QR code, which pairing does not use ([#14817](https://github.com/manaflow-ai/cmux/pull/14817)) -- thanks @aliyansajid! ### Fixed +- In a split, a pane you switch to no longer shows a dimmed frame before it brightens; the unfocused-pane dim now changes in the same frame as focus ([#14892](https://github.com/manaflow-ai/cmux/pull/14892)). - Context-menu submenus built with `Menu` in custom sidebars appear instead of being dropped ([#14808](https://github.com/manaflow-ai/cmux/pull/14808)) -- thanks @aliyansajid! - Closing the last workspace no longer unfolds a collapsed sidebar group above it ([#10169](https://github.com/manaflow-ai/cmux/pull/10169)) -- thanks @AvoChang! - The focused pane border follows a zoomed terminal or browser pane instead of remaining at its pre-zoom split size, including when window chrome changes the overlay reference coordinates ([#14646](https://github.com/manaflow-ai/cmux/pull/14646)). diff --git a/Sources/GhosttyTerminalView.swift b/Sources/GhosttyTerminalView.swift index 336b3e68295b..7e8c2aa52f7c 100644 --- a/Sources/GhosttyTerminalView.swift +++ b/Sources/GhosttyTerminalView.swift @@ -10164,6 +10164,8 @@ final class GhosttySurfaceScrollView: NSView { let surfaceView: GhosttyNSView private let mobileViewportBorderOverlayView = TerminalViewportBorderOverlayView(frame: .zero) private let inactiveOverlayView: GhosttyFlashOverlayView + private var inactiveOverlayColor: NSColor = .clear + private var inactiveOverlayOpacity: CGFloat = 0 private let dropZoneOverlayView: GhosttyFlashOverlayView private let paneDropTargetView = TerminalPaneDropTargetView(frame: .zero) private let notificationRingOverlayView: GhosttyFlashOverlayView @@ -11321,6 +11323,8 @@ final class GhosttySurfaceScrollView: NSView { func setInactiveOverlay(color: NSColor, opacity: CGFloat, visible: Bool) { let clampedOpacity = max(0, min(1, opacity)) + inactiveOverlayColor = color + inactiveOverlayOpacity = clampedOpacity CATransaction.begin() CATransaction.setDisableActions(true) inactiveOverlayView.layer?.backgroundColor = color.withAlphaComponent(clampedOpacity).cgColor @@ -11328,6 +11332,13 @@ final class GhosttySurfaceScrollView: NSView { CATransaction.commit() } + /// Shows or hides the unfocused-split dim with the last configured color, so + /// the workspace's synchronous portal reconcile can move it together with + /// visibility and active state. + func setInactiveOverlayVisible(_ visible: Bool) { + setInactiveOverlay(color: inactiveOverlayColor, opacity: inactiveOverlayOpacity, visible: visible) + } + func setNotificationRing(visible: Bool) { if !Thread.isMainThread { DispatchQueue.main.async { [weak self] in diff --git a/Sources/Workspace.swift b/Sources/Workspace.swift index b36e36c971ec..7364bb7d0db3 100644 --- a/Sources/Workspace.swift +++ b/Sources/Workspace.swift @@ -12507,9 +12507,17 @@ final class Workspace: Identifiable, ObservableObject, FilePreviewTabMetadataHos return renderedVisiblePanelIdsForCurrentLayout() } + /// Whether the split layout shows more than one surface, which is when + /// unfocused terminals dim. `WorkspaceContentView` and the portal reconcile + /// below share this so both paths agree on the dim. + var hasMultipleSplitSurfaces: Bool { + bonsplitController.allPaneIds.count > 1 || panels.count > 1 + } + @discardableResult func reconcileTerminalPortalVisibilityForCurrentRenderedLayout() -> Bool { let visiblePanelIds = renderedVisiblePanelIdsForCurrentLayout() + let dimsUnfocusedTerminals = hasMultipleSplitSurfaces // Focus-exclusivity: when the right sidebar (Dock) owns input focus in this // window, no main terminal should be (re)marked active even if it is still // this workspace's focused panel — mirroring the SwiftUI `isFocused` gate so @@ -12535,6 +12543,13 @@ final class Workspace: Identifiable, ObservableObject, FilePreviewTabMetadataHos terminalPanel.hostedView.setActive(shouldBeActive) didChange = true } + // This reveal and focus change commit now, but the SwiftUI host only + // updates the dim on its next portal turn. Move the dim here too, or a + // tab or workspace dimmed while hidden shows one dimmed frame. Canvas + // hosts own their dim rule. + if shouldBeVisible, layoutMode != .canvas { + terminalPanel.hostedView.setInactiveOverlayVisible(dimsUnfocusedTerminals && !shouldBeActive) + } TerminalWindowPortalRegistry.updateEntryVisibility( for: terminalPanel.hostedView, visibleInUI: shouldBeVisible diff --git a/Sources/WorkspaceContentView.swift b/Sources/WorkspaceContentView.swift index 09c704553f56..c2ea110a3523 100644 --- a/Sources/WorkspaceContentView.swift +++ b/Sources/WorkspaceContentView.swift @@ -195,8 +195,7 @@ struct WorkspaceContentView: View { }() #endif let appearance = PanelAppearance.fromConfig(config) - let isSplit = workspace.bonsplitController.allPaneIds.count > 1 || - workspace.panels.count > 1 + let isSplit = workspace.hasMultipleSplitSurfaces let usesWorkspacePaneOverlay = TmuxOverlayExperimentSettings.target().usesWorkspacePaneOverlay let isWorkspaceManuallyUnread = notificationStore.hasManualUnread(forTabId: workspace.id) let workspaceManualUnreadPanelId = workspace.representativePanelIdForWorkspaceManualUnread()