From b4db2fbd8d6df6ca642d74d5dbd4d73bb4ace16a Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 11 May 2026 23:58:42 -0700 Subject: [PATCH 01/13] Add proxy icon regression test --- cmuxTests/WindowAndDragTests.swift | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 5f1b20cfbbee..a4200766a4ee 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -131,6 +131,40 @@ final class WindowAccessorTests: XCTestCase { } } +@MainActor +final class CmuxMainWindowTitlebarProxyIconTests: XCTestCase { + func testMainWindowSuppressesNativeRepresentedURLProxyIcon() { + _ = NSApplication.shared + let window = CmuxMainWindow( + contentRect: NSRect(x: 0, y: 0, width: 640, height: 420), + styleMask: [.titled, .closable, .resizable, .fullSizeContentView], + backing: .buffered, + defer: false + ) + defer { window.close() } + + let workspaceDirectory = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) + window.representedURL = workspaceDirectory + + XCTAssertNil( + window.representedURL, + "cmux main windows render the workspace folder icon inside the custom titlebar, so AppKit must not keep a native proxy icon at an independent titlebar position." + ) + XCTAssertTrue( + window.representedFilename.isEmpty, + "Clearing the native proxy URL should also leave the legacy represented filename empty." + ) + + window.representedFilename = workspaceDirectory.path + + XCTAssertTrue( + window.representedFilename.isEmpty, + "cmux main windows must also reject the legacy represented filename proxy icon path." + ) + XCTAssertNil(window.representedURL) + } +} + @MainActor final class MainWindowFocusRedrawTests: XCTestCase { func testKeyRegainInvalidatesContentWhenPointerIsOverSidebarDivider() { From 483dc2f4fa6c9ab7c67512e8dc2a84fbe21a36c8 Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Mon, 11 May 2026 23:58:50 -0700 Subject: [PATCH 02/13] Suppress native proxy icon on cmux windows --- Sources/App/CmuxMainWindow.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/App/CmuxMainWindow.swift b/Sources/App/CmuxMainWindow.swift index 02c71a3f234e..3e06b65df716 100644 --- a/Sources/App/CmuxMainWindow.swift +++ b/Sources/App/CmuxMainWindow.swift @@ -71,6 +71,18 @@ struct FirstMouseGatedHostingOverlay: NSViewRepresentable { final class CmuxMainWindow: NSWindow { private var isSoftHiddenForVisibilityController = false + // cmux renders the workspace directory icon inside its custom titlebar, whose layout follows + // the sidebar. AppKit's native proxy icon is positioned in the standard titlebar instead. + override var representedURL: URL? { + get { nil } + set { super.representedURL = nil } + } + + override var representedFilename: String { + get { "" } + set { super.representedFilename = "" } + } + func setSoftHiddenForVisibilityController(_ isSoftHidden: Bool) { isSoftHiddenForVisibilityController = isSoftHidden if isSoftHidden { From 81c6bc220e1b48ea293e79a0b12c5cdac509a7ea Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 03:40:16 -0700 Subject: [PATCH 03/13] chore: retrigger preview deployments From 85c1cf84e8a50cb14394542c9bf6ef46e88b2f9d Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 13:18:39 -0700 Subject: [PATCH 04/13] Refine native proxy icon suppression --- Sources/App/CmuxMainWindow.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/App/CmuxMainWindow.swift b/Sources/App/CmuxMainWindow.swift index 3e06b65df716..0263e2f4232c 100644 --- a/Sources/App/CmuxMainWindow.swift +++ b/Sources/App/CmuxMainWindow.swift @@ -75,12 +75,17 @@ final class CmuxMainWindow: NSWindow { // the sidebar. AppKit's native proxy icon is positioned in the standard titlebar instead. override var representedURL: URL? { get { nil } - set { super.representedURL = nil } + set { clearNativeTitlebarProxyIcon() } } override var representedFilename: String { get { "" } - set { super.representedFilename = "" } + set { clearNativeTitlebarProxyIcon() } + } + + private func clearNativeTitlebarProxyIcon() { + super.representedURL = nil + super.representedFilename = "" } func setSoftHiddenForVisibilityController(_ isSoftHidden: Bool) { From 8a0161f072377cc9d150748b8af18c9a221247f9 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 15:30:01 -0700 Subject: [PATCH 05/13] fix: keep titlebar folder icon aligned --- Sources/App/CmuxMainWindow.swift | 4 +++ Sources/ContentView.swift | 8 +++-- Sources/DetachedFolderDragIcon.swift | 50 ++++++++++++++++++++++------ Sources/WindowChromeMetrics.swift | 5 +++ cmuxTests/WindowAndDragTests.swift | 38 +++++++++++++++++++++ 5 files changed, 92 insertions(+), 13 deletions(-) diff --git a/Sources/App/CmuxMainWindow.swift b/Sources/App/CmuxMainWindow.swift index 0263e2f4232c..793141a5b6f6 100644 --- a/Sources/App/CmuxMainWindow.swift +++ b/Sources/App/CmuxMainWindow.swift @@ -70,6 +70,7 @@ struct FirstMouseGatedHostingOverlay: NSViewRepresentable { @MainActor final class CmuxMainWindow: NSWindow { private var isSoftHiddenForVisibilityController = false + private var isClearingNativeTitlebarProxyIcon = false // cmux renders the workspace directory icon inside its custom titlebar, whose layout follows // the sidebar. AppKit's native proxy icon is positioned in the standard titlebar instead. @@ -84,6 +85,9 @@ final class CmuxMainWindow: NSWindow { } private func clearNativeTitlebarProxyIcon() { + guard !isClearingNativeTitlebarProxyIcon else { return } + isClearingNativeTitlebarProxyIcon = true + defer { isClearingNativeTitlebarProxyIcon = false } super.representedURL = nil super.representedFilename = "" } diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 4a4058a883d4..6ba0324174cc 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -2293,7 +2293,7 @@ struct ContentView: View { TitlebarLeadingInsetReader(inset: $titlebarLeadingInset) .allowsHitTesting(false) - HStack(spacing: 8) { + HStack(spacing: TitlebarFolderIconMetrics.iconTitleSpacing) { if isFullScreen && !sidebarState.isVisible { fullscreenControls } @@ -2301,8 +2301,10 @@ struct ContentView: View { // Draggable folder icon + focused command name if let directory = focusedDirectory { DetachedFolderDragIcon(directory: directory) - .frame(width: 16, height: 16) - .padding(.leading, -6) + .frame( + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) } Text(titlebarText) diff --git a/Sources/DetachedFolderDragIcon.swift b/Sources/DetachedFolderDragIcon.swift index 1292371733ff..527f91959e1a 100644 --- a/Sources/DetachedFolderDragIcon.swift +++ b/Sources/DetachedFolderDragIcon.swift @@ -24,7 +24,7 @@ final class DetachedFolderDragIconHostView: NSView { init(directory: String) { self.directory = directory - super.init(frame: NSRect(origin: .zero, size: NSSize(width: 16, height: 16))) + super.init(frame: NSRect(origin: .zero, size: Self.iconSize)) } required init?(coder: NSCoder) { @@ -38,11 +38,21 @@ final class DetachedFolderDragIconHostView: NSView { } override var intrinsicContentSize: NSSize { - NSSize(width: 16, height: 16) + Self.iconSize } override var mouseDownCanMoveWindow: Bool { false } + override func setFrameOrigin(_ newOrigin: NSPoint) { + super.setFrameOrigin(newOrigin) + syncDetachedIconFrame() + } + + override func setFrameSize(_ newSize: NSSize) { + super.setFrameSize(newSize) + syncDetachedIconFrame() + } + override func viewDidMoveToWindow() { super.viewDidMoveToWindow() syncDetachedIcon() @@ -80,9 +90,15 @@ final class DetachedFolderDragIconHostView: NSView { syncDetachedIconFrame() } + #if DEBUG + var detachedIconFrameForTesting: NSRect? { + childWindow?.frame + } + #endif + private func makeDetachedIconWindow(parentWindow: NSWindow) -> NSPanel { let iconView = DraggableFolderNSView(directory: directory) - iconView.frame = NSRect(origin: .zero, size: NSSize(width: 16, height: 16)) + iconView.frame = NSRect(origin: .zero, size: Self.iconSize) let panel = NSPanel( contentRect: iconView.frame, @@ -136,7 +152,7 @@ final class DetachedFolderDragIconHostView: NSView { guard let parentWindow = window, let childWindow else { return } let localRect = bounds.isEmpty - ? NSRect(origin: .zero, size: NSSize(width: 16, height: 16)) + ? NSRect(origin: .zero, size: Self.iconSize) : bounds let rectInWindow = convert(localRect, to: nil) let rectOnScreen = parentWindow.convertToScreen(rectInWindow) @@ -165,6 +181,13 @@ final class DetachedFolderDragIconHostView: NSView { childWindow = nil iconView = nil } + + private static var iconSize: NSSize { + NSSize( + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + } } @MainActor @@ -194,7 +217,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { } override var intrinsicContentSize: NSSize { - NSSize(width: 16, height: 16) + Self.iconSize } override var mouseDownCanMoveWindow: Bool { false } @@ -209,8 +232,8 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { imageView.trailingAnchor.constraint(equalTo: trailingAnchor), imageView.topAnchor.constraint(equalTo: topAnchor), imageView.bottomAnchor.constraint(equalTo: bottomAnchor), - imageView.widthAnchor.constraint(equalToConstant: 16), - imageView.heightAnchor.constraint(equalToConstant: 16), + imageView.widthAnchor.constraint(equalToConstant: TitlebarFolderIconMetrics.iconSize), + imageView.heightAnchor.constraint(equalToConstant: TitlebarFolderIconMetrics.iconSize), ]) let dragHint = String(localized: "sidebar.folderIcon.dragHint", defaultValue: "Drag to open in Finder or another app") toolTip = dragHint @@ -224,7 +247,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { #endif let icon = NSWorkspace.shared.icon(forFile: directory) - icon.size = NSSize(width: 16, height: 16) + icon.size = Self.iconSize imageView.image = icon } @@ -343,7 +366,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { // Add path components (current dir at top, root at bottom - matches native macOS) for pathURL in pathComponents { let icon = NSWorkspace.shared.icon(forFile: pathURL.path) - icon.size = NSSize(width: 16, height: 16) + icon.size = Self.iconSize let displayName: String if pathURL.path == "/" { @@ -367,7 +390,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { // Add computer name at the bottom (like native proxy icon) let computerName = Host.current().localizedName ?? ProcessInfo.processInfo.hostName let computerIcon = NSImage(named: NSImage.computerName) ?? NSImage() - computerIcon.size = NSSize(width: 16, height: 16) + computerIcon.size = Self.iconSize let computerItem = NSMenuItem(title: computerName, action: #selector(openComputer(_:)), keyEquivalent: "") computerItem.target = self @@ -386,4 +409,11 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { // Open the root filesystem entry represented by the bottom path item. NSWorkspace.shared.open(URL(fileURLWithPath: "/", isDirectory: true)) } + + private static var iconSize: NSSize { + NSSize( + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + } } diff --git a/Sources/WindowChromeMetrics.swift b/Sources/WindowChromeMetrics.swift index 6abee8ea7d93..7a8a34b5c863 100644 --- a/Sources/WindowChromeMetrics.swift +++ b/Sources/WindowChromeMetrics.swift @@ -14,6 +14,11 @@ enum WindowChromeMetrics { } } +enum TitlebarFolderIconMetrics { + static let iconSize: CGFloat = 16 + static let iconTitleSpacing: CGFloat = 8 +} + enum MinimalModeChromeMetrics { static let titlebarHeight: CGFloat = WindowChromeMetrics.appTitlebarHeight } diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index a4200766a4ee..992ac67be220 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -1599,6 +1599,44 @@ final class WindowDragHandleHitTests: XCTestCase { @MainActor final class DraggableFolderHitTests: XCTestCase { + func testDetachedFolderPanelFollowsHostFrameChanges() { + _ = NSApplication.shared + let window = NSWindow( + contentRect: NSRect(x: 40, y: 40, width: 320, height: 180), + styleMask: [.titled, .closable], + backing: .buffered, + defer: false + ) + defer { window.close() } + let container = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 180)) + window.contentView = container + + let hostView = DetachedFolderDragIconHostView(directory: NSTemporaryDirectory()) + hostView.frame = NSRect( + x: 24, + y: 120, + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + container.addSubview(hostView) + defer { hostView.removeFromSuperview() } + + hostView.syncDetachedIcon() + guard let initialFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to be created") + return + } + + hostView.setFrameOrigin(NSPoint(x: 96, y: 120)) + + guard let movedFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to remain attached") + return + } + XCTAssertEqual(movedFrame.minX, initialFrame.minX + 72, accuracy: 0.5) + XCTAssertEqual(movedFrame.minY, initialFrame.minY, accuracy: 0.5) + } + func testFolderHitTestReturnsContainerWhenInsideBounds() { let folderView = DraggableFolderNSView(directory: "/tmp") folderView.frame = NSRect(x: 0, y: 0, width: 16, height: 16) From 392e6b61941ee28d9f6a08e640c6b5221506b79f Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 22:25:44 -0700 Subject: [PATCH 06/13] fix: restore titlebar folder icon leading offset --- Sources/ContentView.swift | 1 + Sources/WindowChromeMetrics.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 52af4aa84e67..63b4d265bf1d 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -2305,6 +2305,7 @@ struct ContentView: View { width: TitlebarFolderIconMetrics.iconSize, height: TitlebarFolderIconMetrics.iconSize ) + .padding(.leading, TitlebarFolderIconMetrics.iconLeadingPadding) } Text(titlebarText) diff --git a/Sources/WindowChromeMetrics.swift b/Sources/WindowChromeMetrics.swift index 7a8a34b5c863..d9c3587a5ee2 100644 --- a/Sources/WindowChromeMetrics.swift +++ b/Sources/WindowChromeMetrics.swift @@ -17,6 +17,7 @@ enum WindowChromeMetrics { enum TitlebarFolderIconMetrics { static let iconSize: CGFloat = 16 static let iconTitleSpacing: CGFloat = 8 + static let iconLeadingPadding: CGFloat = -6 } enum MinimalModeChromeMetrics { From bfbee93ba39d000d405538d8297c6104657b145e Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 23:07:31 -0700 Subject: [PATCH 07/13] test: cover folder icon frame replacement --- cmuxTests/WindowAndDragTests.swift | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 6bd297b79df2..6214b609d1a6 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -1637,6 +1637,49 @@ final class DraggableFolderHitTests: XCTestCase { XCTAssertEqual(movedFrame.minY, initialFrame.minY, accuracy: 0.5) } + func testDetachedFolderPanelFollowsHostFrameReplacement() { + _ = NSApplication.shared + let window = NSWindow( + contentRect: NSRect(x: 40, y: 40, width: 320, height: 180), + styleMask: [.titled, .closable], + backing: .buffered, + defer: false + ) + defer { window.close() } + let container = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 180)) + window.contentView = container + + let hostView = DetachedFolderDragIconHostView(directory: NSTemporaryDirectory()) + hostView.frame = NSRect( + x: 24, + y: 120, + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + container.addSubview(hostView) + defer { hostView.removeFromSuperview() } + + hostView.syncDetachedIcon() + guard let initialFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to be created") + return + } + + hostView.frame = NSRect( + x: 96, + y: 128, + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + + guard let movedFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to remain attached") + return + } + XCTAssertEqual(movedFrame.minX, initialFrame.minX + 72, accuracy: 0.5) + XCTAssertEqual(movedFrame.minY, initialFrame.minY + 8, accuracy: 0.5) + } + func testFolderHitTestReturnsContainerWhenInsideBounds() { let folderView = DraggableFolderNSView(directory: "/tmp") folderView.frame = NSRect(x: 0, y: 0, width: 16, height: 16) From 5db27dbcd627038f8649ca06b8a49fd624272163 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Tue, 12 May 2026 23:07:32 -0700 Subject: [PATCH 08/13] fix: resync folder icon on frame replacement --- Sources/DetachedFolderDragIcon.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/DetachedFolderDragIcon.swift b/Sources/DetachedFolderDragIcon.swift index 527f91959e1a..6be080525c10 100644 --- a/Sources/DetachedFolderDragIcon.swift +++ b/Sources/DetachedFolderDragIcon.swift @@ -43,6 +43,12 @@ final class DetachedFolderDragIconHostView: NSView { override var mouseDownCanMoveWindow: Bool { false } + override var frame: NSRect { + didSet { + syncDetachedIconFrame() + } + } + override func setFrameOrigin(_ newOrigin: NSPoint) { super.setFrameOrigin(newOrigin) syncDetachedIconFrame() From 7dc7da710a75c893636695f1363a622901fcf811 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 13 May 2026 01:08:56 -0700 Subject: [PATCH 09/13] test: cover folder icon ancestor movement --- cmuxTests/WindowAndDragTests.swift | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 6214b609d1a6..1f89f72c20a6 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -1680,6 +1680,54 @@ final class DraggableFolderHitTests: XCTestCase { XCTAssertEqual(movedFrame.minY, initialFrame.minY + 8, accuracy: 0.5) } + func testDetachedFolderPanelFollowsAncestorFrameChanges() { + _ = NSApplication.shared + let window = NSWindow( + contentRect: NSRect(x: 40, y: 40, width: 320, height: 180), + styleMask: [.titled, .closable], + backing: .buffered, + defer: false + ) + defer { window.close() } + let container = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 180)) + window.contentView = container + + let titlebarHost = NSView(frame: NSRect(x: 24, y: 0, width: 180, height: 180)) + container.addSubview(titlebarHost) + defer { titlebarHost.removeFromSuperview() } + + let hostView = DetachedFolderDragIconHostView(directory: NSTemporaryDirectory()) + hostView.frame = NSRect( + x: 12, + y: 120, + width: TitlebarFolderIconMetrics.iconSize, + height: TitlebarFolderIconMetrics.iconSize + ) + titlebarHost.addSubview(hostView) + defer { hostView.removeFromSuperview() } + + hostView.syncDetachedIcon() + guard let initialFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to be created") + return + } + + titlebarHost.setFrameOrigin(NSPoint(x: 96, y: 0)) + RunLoop.main.run(until: Date().addingTimeInterval(0.02)) + + guard let movedFrame = hostView.detachedIconFrameForTesting else { + XCTFail("Expected detached folder panel to remain attached") + return + } + XCTAssertEqual( + movedFrame.minX, + initialFrame.minX + 72, + accuracy: 0.5, + "The detached panel must follow converted window coordinates when a sidebar toggle moves an ancestor view without changing the host view's local frame." + ) + XCTAssertEqual(movedFrame.minY, initialFrame.minY, accuracy: 0.5) + } + func testFolderHitTestReturnsContainerWhenInsideBounds() { let folderView = DraggableFolderNSView(directory: "/tmp") folderView.frame = NSRect(x: 0, y: 0, width: 16, height: 16) From 9024c581c56f9a699c71883b6bb9aa381a3db7fc Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 13 May 2026 01:09:25 -0700 Subject: [PATCH 10/13] fix: track folder icon ancestor movement --- Sources/DetachedFolderDragIcon.swift | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Sources/DetachedFolderDragIcon.swift b/Sources/DetachedFolderDragIcon.swift index 6be080525c10..9fb10840f512 100644 --- a/Sources/DetachedFolderDragIcon.swift +++ b/Sources/DetachedFolderDragIcon.swift @@ -20,6 +20,9 @@ final class DetachedFolderDragIconHostView: NSView { private var childWindow: NSPanel? private var iconView: DraggableFolderNSView? private var observers: [NSObjectProtocol] = [] + private var ancestorViewObservers: [NSObjectProtocol] = [] + private var observedAncestorViewIds: [ObjectIdentifier] = [] + private var hasScheduledFrameSync = false private weak var observedParentWindow: NSWindow? init(directory: String) { @@ -61,11 +64,13 @@ final class DetachedFolderDragIconHostView: NSView { override func viewDidMoveToWindow() { super.viewDidMoveToWindow() + installAncestorViewObservers() syncDetachedIcon() } override func viewDidMoveToSuperview() { super.viewDidMoveToSuperview() + installAncestorViewObservers() syncDetachedIcon() } @@ -155,6 +160,7 @@ final class DetachedFolderDragIconHostView: NSView { } private func syncDetachedIconFrame() { + installAncestorViewObservers() guard let parentWindow = window, let childWindow else { return } let localRect = bounds.isEmpty @@ -167,6 +173,71 @@ final class DetachedFolderDragIconHostView: NSView { } } + private func installAncestorViewObservers() { + var ancestors: [NSView] = [] + var ancestor = superview + while let view = ancestor { + ancestors.append(view) + ancestor = view.superview + } + + let ancestorIds = ancestors.map { ObjectIdentifier($0) } + guard ancestorIds != observedAncestorViewIds else { return } + + removeAncestorViewObservers() + guard !ancestors.isEmpty else { return } + + let center = NotificationCenter.default + for ancestor in ancestors { + // SwiftUI may keep this host's local frame stable while moving an + // enclosing titlebar/content view, such as when the left sidebar + // opens. Observe the ancestor chain so the detached panel follows + // the host's converted window rect, not just its local frame. + ancestor.postsFrameChangedNotifications = true + ancestor.postsBoundsChangedNotifications = true + ancestorViewObservers.append(center.addObserver( + forName: NSView.frameDidChangeNotification, + object: ancestor, + queue: .main + ) { [weak self] _ in + MainActor.assumeIsolated { + self?.scheduleDetachedIconFrameSync() + } + }) + ancestorViewObservers.append(center.addObserver( + forName: NSView.boundsDidChangeNotification, + object: ancestor, + queue: .main + ) { [weak self] _ in + MainActor.assumeIsolated { + self?.scheduleDetachedIconFrameSync() + } + }) + } + observedAncestorViewIds = ancestorIds + } + + private func scheduleDetachedIconFrameSync() { + guard !hasScheduledFrameSync else { return } + hasScheduledFrameSync = true + DispatchQueue.main.async { [weak self] in + MainActor.assumeIsolated { + guard let self else { return } + self.hasScheduledFrameSync = false + self.syncDetachedIconFrame() + } + } + } + + private func removeAncestorViewObservers() { + for observer in ancestorViewObservers { + NotificationCenter.default.removeObserver(observer) + } + ancestorViewObservers.removeAll() + observedAncestorViewIds.removeAll() + hasScheduledFrameSync = false + } + private func removeParentWindowObservers() { for observer in observers { NotificationCenter.default.removeObserver(observer) @@ -180,6 +251,7 @@ final class DetachedFolderDragIconHostView: NSView { // leaves its parent window or deinitializes, remove both so no stale // panel keeps tracking an old parent window. removeParentWindowObservers() + removeAncestorViewObservers() if let childWindow { childWindow.parent?.removeChildWindow(childWindow) childWindow.orderOut(nil) From f46e6956fbe3a8acb2ab2f4059960ec44a3ed00e Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 13 May 2026 01:29:11 -0700 Subject: [PATCH 11/13] fix: address folder icon review feedback --- Sources/DetachedFolderDragIcon.swift | 42 +++++++++++++++------------- Sources/WindowChromeMetrics.swift | 1 + cmuxTests/WindowAndDragTests.swift | 19 ++----------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Sources/DetachedFolderDragIcon.swift b/Sources/DetachedFolderDragIcon.swift index 9fb10840f512..19dedf907465 100644 --- a/Sources/DetachedFolderDragIcon.swift +++ b/Sources/DetachedFolderDragIcon.swift @@ -21,13 +21,14 @@ final class DetachedFolderDragIconHostView: NSView { private var iconView: DraggableFolderNSView? private var observers: [NSObjectProtocol] = [] private var ancestorViewObservers: [NSObjectProtocol] = [] + private var ancestorViewNotificationStates: [AncestorViewNotificationState] = [] private var observedAncestorViewIds: [ObjectIdentifier] = [] private var hasScheduledFrameSync = false private weak var observedParentWindow: NSWindow? init(directory: String) { self.directory = directory - super.init(frame: NSRect(origin: .zero, size: Self.iconSize)) + super.init(frame: NSRect(origin: .zero, size: TitlebarFolderIconMetrics.iconFrameSize)) } required init?(coder: NSCoder) { @@ -41,7 +42,7 @@ final class DetachedFolderDragIconHostView: NSView { } override var intrinsicContentSize: NSSize { - Self.iconSize + TitlebarFolderIconMetrics.iconFrameSize } override var mouseDownCanMoveWindow: Bool { false } @@ -109,7 +110,7 @@ final class DetachedFolderDragIconHostView: NSView { private func makeDetachedIconWindow(parentWindow: NSWindow) -> NSPanel { let iconView = DraggableFolderNSView(directory: directory) - iconView.frame = NSRect(origin: .zero, size: Self.iconSize) + iconView.frame = NSRect(origin: .zero, size: TitlebarFolderIconMetrics.iconFrameSize) let panel = NSPanel( contentRect: iconView.frame, @@ -164,7 +165,7 @@ final class DetachedFolderDragIconHostView: NSView { guard let parentWindow = window, let childWindow else { return } let localRect = bounds.isEmpty - ? NSRect(origin: .zero, size: Self.iconSize) + ? NSRect(origin: .zero, size: TitlebarFolderIconMetrics.iconFrameSize) : bounds let rectInWindow = convert(localRect, to: nil) let rectOnScreen = parentWindow.convertToScreen(rectInWindow) @@ -193,6 +194,11 @@ final class DetachedFolderDragIconHostView: NSView { // enclosing titlebar/content view, such as when the left sidebar // opens. Observe the ancestor chain so the detached panel follows // the host's converted window rect, not just its local frame. + ancestorViewNotificationStates.append(AncestorViewNotificationState( + view: ancestor, + postsFrameChangedNotifications: ancestor.postsFrameChangedNotifications, + postsBoundsChangedNotifications: ancestor.postsBoundsChangedNotifications + )) ancestor.postsFrameChangedNotifications = true ancestor.postsBoundsChangedNotifications = true ancestorViewObservers.append(center.addObserver( @@ -233,7 +239,12 @@ final class DetachedFolderDragIconHostView: NSView { for observer in ancestorViewObservers { NotificationCenter.default.removeObserver(observer) } + for state in ancestorViewNotificationStates { + state.view?.postsFrameChangedNotifications = state.postsFrameChangedNotifications + state.view?.postsBoundsChangedNotifications = state.postsBoundsChangedNotifications + } ancestorViewObservers.removeAll() + ancestorViewNotificationStates.removeAll() observedAncestorViewIds.removeAll() hasScheduledFrameSync = false } @@ -260,11 +271,10 @@ final class DetachedFolderDragIconHostView: NSView { iconView = nil } - private static var iconSize: NSSize { - NSSize( - width: TitlebarFolderIconMetrics.iconSize, - height: TitlebarFolderIconMetrics.iconSize - ) + private struct AncestorViewNotificationState { + weak var view: NSView? + let postsFrameChangedNotifications: Bool + let postsBoundsChangedNotifications: Bool } } @@ -295,7 +305,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { } override var intrinsicContentSize: NSSize { - Self.iconSize + TitlebarFolderIconMetrics.iconFrameSize } override var mouseDownCanMoveWindow: Bool { false } @@ -325,7 +335,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { #endif let icon = NSWorkspace.shared.icon(forFile: directory) - icon.size = Self.iconSize + icon.size = TitlebarFolderIconMetrics.iconFrameSize imageView.image = icon } @@ -444,7 +454,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { // Add path components (current dir at top, root at bottom - matches native macOS) for pathURL in pathComponents { let icon = NSWorkspace.shared.icon(forFile: pathURL.path) - icon.size = Self.iconSize + icon.size = TitlebarFolderIconMetrics.iconFrameSize let displayName: String if pathURL.path == "/" { @@ -468,7 +478,7 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { // Add computer name at the bottom (like native proxy icon) let computerName = Host.current().localizedName ?? ProcessInfo.processInfo.hostName let computerIcon = NSImage(named: NSImage.computerName) ?? NSImage() - computerIcon.size = Self.iconSize + computerIcon.size = TitlebarFolderIconMetrics.iconFrameSize let computerItem = NSMenuItem(title: computerName, action: #selector(openComputer(_:)), keyEquivalent: "") computerItem.target = self @@ -488,10 +498,4 @@ final class DraggableFolderNSView: NSView, NSDraggingSource { NSWorkspace.shared.open(URL(fileURLWithPath: "/", isDirectory: true)) } - private static var iconSize: NSSize { - NSSize( - width: TitlebarFolderIconMetrics.iconSize, - height: TitlebarFolderIconMetrics.iconSize - ) - } } diff --git a/Sources/WindowChromeMetrics.swift b/Sources/WindowChromeMetrics.swift index d9c3587a5ee2..b17f57ff7b49 100644 --- a/Sources/WindowChromeMetrics.swift +++ b/Sources/WindowChromeMetrics.swift @@ -16,6 +16,7 @@ enum WindowChromeMetrics { enum TitlebarFolderIconMetrics { static let iconSize: CGFloat = 16 + static let iconFrameSize = CGSize(width: iconSize, height: iconSize) static let iconTitleSpacing: CGFloat = 8 static let iconLeadingPadding: CGFloat = -6 } diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index a184ac93c702..4085fc00a3e9 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -167,7 +167,7 @@ final class CmuxMainWindowTitlebarProxyIconTests: XCTestCase { @MainActor final class MainWindowFocusRedrawTests: XCTestCase { - func testKeyRegainInvalidatesContentWhenPointerIsOverSidebarDivider() { + func testKeyRegainInvalidatesRootContentView() { _ = NSApplication.shared let appDelegate = AppDelegate() @@ -202,21 +202,6 @@ final class MainWindowFocusRedrawTests: XCTestCase { contentView.layoutSubtreeIfNeeded() splitView.adjustSubviews() - let dividerPointInSplit = NSPoint( - x: sidebar.frame.maxX + splitView.dividerThickness / 2, - y: splitView.bounds.midY - ) - let dividerRectInSplit = NSRect( - x: sidebar.frame.maxX, - y: 0, - width: max(splitView.dividerThickness, 1), - height: splitView.bounds.height - ).insetBy(dx: -5, dy: 0) - - XCTAssertTrue( - dividerRectInSplit.contains(dividerPointInSplit), - "Test setup should place the pointer over the sidebar/main split divider without depending on screen coordinates." - ) contentView.needsDisplay = false @@ -229,7 +214,7 @@ final class MainWindowFocusRedrawTests: XCTestCase { XCTAssertTrue( contentView.needsDisplay, - "Regaining key focus must invalidate the root content view even when the pointer is over the resize divider." + "Regaining key focus must invalidate the root content view." ) } } From c32a266c22da8e4b400b6c3485bc5742a559f275 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 13 May 2026 01:31:06 -0700 Subject: [PATCH 12/13] test: stabilize folder icon ancestor sync --- cmuxTests/WindowAndDragTests.swift | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 4085fc00a3e9..115a347e99d1 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -1699,19 +1699,31 @@ final class DraggableFolderHitTests: XCTestCase { } titlebarHost.setFrameOrigin(NSPoint(x: 96, y: 0)) - RunLoop.main.run(until: Date().addingTimeInterval(0.02)) + let expectedMinX = initialFrame.minX + 72 + let expectedMinY = initialFrame.minY + let deadline = Date().addingTimeInterval(0.5) + var movedFrame = hostView.detachedIconFrameForTesting + while Date() < deadline { + if let frame = movedFrame, + abs(frame.minX - expectedMinX) <= 0.5, + abs(frame.minY - expectedMinY) <= 0.5 { + break + } + RunLoop.main.run(until: Date().addingTimeInterval(0.005)) + movedFrame = hostView.detachedIconFrameForTesting + } - guard let movedFrame = hostView.detachedIconFrameForTesting else { + guard let movedFrame else { XCTFail("Expected detached folder panel to remain attached") return } XCTAssertEqual( movedFrame.minX, - initialFrame.minX + 72, + expectedMinX, accuracy: 0.5, "The detached panel must follow converted window coordinates when a sidebar toggle moves an ancestor view without changing the host view's local frame." ) - XCTAssertEqual(movedFrame.minY, initialFrame.minY, accuracy: 0.5) + XCTAssertEqual(movedFrame.minY, expectedMinY, accuracy: 0.5) } func testFolderHitTestReturnsContainerWhenInsideBounds() { From b9054cffd269fc718491fa1b85cd403aa614ec8b Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 13 May 2026 01:38:34 -0700 Subject: [PATCH 13/13] fix: handle sidebar tool panels in global search --- Sources/Search/GlobalSearchDocuments.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Search/GlobalSearchDocuments.swift b/Sources/Search/GlobalSearchDocuments.swift index 11120bb19475..baa92275e4fc 100644 --- a/Sources/Search/GlobalSearchDocuments.swift +++ b/Sources/Search/GlobalSearchDocuments.swift @@ -34,7 +34,7 @@ enum GlobalSearchDocuments { kind = .browser case .markdown: kind = .markdown - case .terminal, .filePreview: + case .terminal, .filePreview, .rightSidebarTool: kind = .title }