From cc97ba52912120fc946a293b183b755d3a8b82a4 Mon Sep 17 00:00:00 2001 From: Aziz Albahar Date: Sun, 31 May 2026 23:54:45 -0500 Subject: [PATCH 1/3] test: cover titlebar padding at minimum sidebar width --- Sources/ContentView.swift | 24 ++++++++++- cmuxTests/WindowAndDragTests.swift | 68 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index d15273d7fe54..55908383e2d8 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -2054,6 +2054,21 @@ struct ContentView: View { return -max(0, min(titlebarPadding, hostingSafeAreaTop)) } + static func customTitlebarLeadingPadding( + isFullScreen: Bool, + isSidebarVisible: Bool, + sidebarWidth: CGFloat, + minimumSidebarWidth: CGFloat, + titlebarLeadingInset: CGFloat + ) -> CGFloat { + if isFullScreen && !isSidebarVisible { + return 8 + } + + _ = minimumSidebarWidth + return isSidebarVisible ? sidebarWidth + 12 : titlebarLeadingInset + } + private func terminalContent(appearance: WindowAppearanceSnapshot) -> some View { let mountedWorkspaceIdSet = Set(mountedWorkspaceIds) let mountedWorkspaces = tabManager.tabs.filter { mountedWorkspaceIdSet.contains($0.id) } @@ -2333,6 +2348,13 @@ struct ContentView: View { private func customTitlebar(appearance: WindowAppearanceSnapshot) -> some View { let titlebarContentHeight = max(1, WindowChromeMetrics.appTitlebarHeight - 2) + let leadingPadding = Self.customTitlebarLeadingPadding( + isFullScreen: isFullScreen, + isSidebarVisible: sidebarState.isVisible, + sidebarWidth: sidebarWidth, + minimumSidebarWidth: minimumSidebarWidth, + titlebarLeadingInset: titlebarLeadingInset + ) return ZStack { // Enable window dragging from the titlebar strip without making the entire content // view draggable (which breaks drag gestures like tab reordering). @@ -2364,7 +2386,7 @@ struct ContentView: View { } .frame(height: titlebarContentHeight) .padding(.top, 2) - .padding(.leading, (isFullScreen && !sidebarState.isVisible) ? 8 : (sidebarState.isVisible ? sidebarWidth + 12 : titlebarLeadingInset)) + .padding(.leading, leadingPadding) .padding(.trailing, 8) } .frame(height: WindowChromeMetrics.appTitlebarHeight) diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 626b64658077..976c9567ea17 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -1958,6 +1958,74 @@ final class TitlebarLeadingInsetPassthroughViewTests: XCTestCase { } +final class CustomTitlebarLeadingPaddingTests: XCTestCase { + func testHiddenSidebarUsesMinimumSidebarTitleInset() { + XCTAssertEqual( + ContentView.customTitlebarLeadingPadding( + isFullScreen: false, + isSidebarVisible: false, + sidebarWidth: 216, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ), + 228 + ) + } + + func testMinimumWidthVisibleSidebarMatchesHiddenSidebarTitleInset() { + let hidden = ContentView.customTitlebarLeadingPadding( + isFullScreen: false, + isSidebarVisible: false, + sidebarWidth: 216, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ) + let visible = ContentView.customTitlebarLeadingPadding( + isFullScreen: false, + isSidebarVisible: true, + sidebarWidth: 216, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ) + + XCTAssertEqual(visible, hidden) + } + + func testWiderSidebarPushesTitlebarContentRight() { + let hidden = ContentView.customTitlebarLeadingPadding( + isFullScreen: false, + isSidebarVisible: false, + sidebarWidth: 216, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ) + let visible = ContentView.customTitlebarLeadingPadding( + isFullScreen: false, + isSidebarVisible: true, + sidebarWidth: 320, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ) + + XCTAssertGreaterThan(visible, hidden) + XCTAssertEqual(visible, 332) + } + + func testFullscreenHiddenSidebarKeepsCompactInset() { + XCTAssertEqual( + ContentView.customTitlebarLeadingPadding( + isFullScreen: true, + isSidebarVisible: false, + sidebarWidth: 216, + minimumSidebarWidth: 216, + titlebarLeadingInset: 82 + ), + 8 + ) + } +} + + @MainActor final class FolderWindowMoveSuppressionTests: XCTestCase { private func makeWindow() -> NSWindow { From a29db70ea69d4bb98852e0aaa4d75cf62d6c3fdf Mon Sep 17 00:00:00 2001 From: Aziz Albahar Date: Sun, 31 May 2026 23:54:52 -0500 Subject: [PATCH 2/3] fix: keep titlebar position stable at minimum sidebar width --- Sources/ContentView.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 55908383e2d8..c38dc921c366 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -2065,8 +2065,16 @@ struct ContentView: View { return 8 } - _ = minimumSidebarWidth - return isSidebarVisible ? sidebarWidth + 12 : titlebarLeadingInset + let minimumSidebarTitleInset = max(titlebarLeadingInset, minimumSidebarWidth + 12) + guard isSidebarVisible else { + return minimumSidebarTitleInset + } + + let visibleSidebarTitleInset = sidebarWidth + 12 + guard sidebarWidth > minimumSidebarWidth + 0.5 else { + return minimumSidebarTitleInset + } + return max(minimumSidebarTitleInset, visibleSidebarTitleInset) } private func terminalContent(appearance: WindowAppearanceSnapshot) -> some View { From 6f5db4ccdd95fe47056e7d1b353039ba4e5e5164 Mon Sep 17 00:00:00 2001 From: Aziz Albahar Date: Mon, 1 Jun 2026 00:01:48 -0500 Subject: [PATCH 3/3] fix: address titlebar padding review feedback --- Sources/ContentView.swift | 5 +++-- cmuxTests/WindowAndDragTests.swift | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 64c4dbb1fb72..8ff416373c82 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -2055,7 +2055,7 @@ struct ContentView: View { return -max(0, min(titlebarPadding, hostingSafeAreaTop)) } - static func customTitlebarLeadingPadding( + nonisolated static func customTitlebarLeadingPadding( isFullScreen: Bool, isSidebarVisible: Bool, sidebarWidth: CGFloat, @@ -2072,10 +2072,11 @@ struct ContentView: View { } let visibleSidebarTitleInset = sidebarWidth + 12 + // Absorb floating-point drift around the minimum-width clamp. guard sidebarWidth > minimumSidebarWidth + 0.5 else { return minimumSidebarTitleInset } - return max(minimumSidebarTitleInset, visibleSidebarTitleInset) + return max(titlebarLeadingInset, visibleSidebarTitleInset) } private func terminalContent(appearance: WindowAppearanceSnapshot) -> some View { diff --git a/cmuxTests/WindowAndDragTests.swift b/cmuxTests/WindowAndDragTests.swift index 976c9567ea17..929eb6cecb81 100644 --- a/cmuxTests/WindowAndDragTests.swift +++ b/cmuxTests/WindowAndDragTests.swift @@ -3,6 +3,7 @@ import AppKit import Carbon.HIToolbox import Darwin import PDFKit +import Testing import SwiftUI import UniformTypeIdentifiers import WebKit @@ -1958,21 +1959,21 @@ final class TitlebarLeadingInsetPassthroughViewTests: XCTestCase { } -final class CustomTitlebarLeadingPaddingTests: XCTestCase { - func testHiddenSidebarUsesMinimumSidebarTitleInset() { - XCTAssertEqual( +@Suite("Custom titlebar leading padding") +struct CustomTitlebarLeadingPaddingTests { + @Test func hiddenSidebarUsesMinimumSidebarTitleInset() { + #expect( ContentView.customTitlebarLeadingPadding( isFullScreen: false, isSidebarVisible: false, sidebarWidth: 216, minimumSidebarWidth: 216, titlebarLeadingInset: 82 - ), - 228 + ) == 228 ) } - func testMinimumWidthVisibleSidebarMatchesHiddenSidebarTitleInset() { + @Test func minimumWidthVisibleSidebarMatchesHiddenSidebarTitleInset() { let hidden = ContentView.customTitlebarLeadingPadding( isFullScreen: false, isSidebarVisible: false, @@ -1988,10 +1989,10 @@ final class CustomTitlebarLeadingPaddingTests: XCTestCase { titlebarLeadingInset: 82 ) - XCTAssertEqual(visible, hidden) + #expect(visible == hidden) } - func testWiderSidebarPushesTitlebarContentRight() { + @Test func widerSidebarPushesTitlebarContentRight() { let hidden = ContentView.customTitlebarLeadingPadding( isFullScreen: false, isSidebarVisible: false, @@ -2007,20 +2008,19 @@ final class CustomTitlebarLeadingPaddingTests: XCTestCase { titlebarLeadingInset: 82 ) - XCTAssertGreaterThan(visible, hidden) - XCTAssertEqual(visible, 332) + #expect(visible > hidden) + #expect(visible == 332) } - func testFullscreenHiddenSidebarKeepsCompactInset() { - XCTAssertEqual( + @Test func fullscreenHiddenSidebarKeepsCompactInset() { + #expect( ContentView.customTitlebarLeadingPadding( isFullScreen: true, isSidebarVisible: false, sidebarWidth: 216, minimumSidebarWidth: 216, titlebarLeadingInset: 82 - ), - 8 + ) == 8 ) } }