diff --git a/CHANGELOG.md b/CHANGELOG.md index 8687917cda20..72710ff12e7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,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)). - Clicking a sidebar workspace keeps its highlight steady while the selection lands, instead of flickering off when the pointer moves away, and rapid clicks never show two rows selected ([#14871](https://github.com/manaflow-ai/cmux/pull/14871)). - Closing a workspace no longer briefly flashes the close (X) button on every sidebar row, and the X no longer appears on the row that slides under a context menu's old position ([#14826](https://github.com/manaflow-ai/cmux/pull/14826)). - Closing or creating a workspace no longer rebuilds every sidebar row, so a rename, checklist edit, or popover open on another row survives it ([#14866](https://github.com/manaflow-ai/cmux/pull/14866)). 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() 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)