Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 32 additions & 1 deletion Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,30 @@ struct ContentView: View {
return -max(0, min(titlebarPadding, hostingSafeAreaTop))
}

nonisolated static func customTitlebarLeadingPadding(
isFullScreen: Bool,
isSidebarVisible: Bool,
sidebarWidth: CGFloat,
minimumSidebarWidth: CGFloat,
titlebarLeadingInset: CGFloat
) -> CGFloat {
if isFullScreen && !isSidebarVisible {
return 8
}

let minimumSidebarTitleInset = max(titlebarLeadingInset, minimumSidebarWidth + 12)
guard isSidebarVisible else {
return minimumSidebarTitleInset
}

let visibleSidebarTitleInset = sidebarWidth + 12
// Absorb floating-point drift around the minimum-width clamp.
guard sidebarWidth > minimumSidebarWidth + 0.5 else {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The 0.5 sub-pixel tolerance that separates "at minimum width" from "wider than minimum" is not explained. Without a comment, future readers may wonder whether this is pixels, points, a render artifact, or an arbitrary guard. A brief inline note stating that it absorbs floating-point drift around the minimum clamp would make the intent clear.

Suggested change
guard sidebarWidth > minimumSidebarWidth + 0.5 else {
// Use a 0.5-point tolerance to absorb floating-point drift at the minimum-width clamp.
guard sidebarWidth > minimumSidebarWidth + 0.5 else {

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an inline note explaining the 0.5-point tolerance around the minimum-width clamp.

— Claude Code

return minimumSidebarTitleInset
}
return max(titlebarLeadingInset, visibleSidebarTitleInset)
}

private func terminalContent(appearance: WindowAppearanceSnapshot) -> some View {
let mountedWorkspaceIdSet = Set(mountedWorkspaceIds)
let mountedWorkspaces = tabManager.tabs.filter { mountedWorkspaceIdSet.contains($0.id) }
Expand Down Expand Up @@ -2334,6 +2358,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).
Expand Down Expand Up @@ -2365,7 +2396,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)
Expand Down
68 changes: 68 additions & 0 deletions cmuxTests/WindowAndDragTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AppKit
import Carbon.HIToolbox
import Darwin
import PDFKit
import Testing
import SwiftUI
import UniformTypeIdentifiers
import WebKit
Expand Down Expand Up @@ -1958,6 +1959,73 @@ final class TitlebarLeadingInsetPassthroughViewTests: XCTestCase {
}


@Suite("Custom titlebar leading padding")
struct CustomTitlebarLeadingPaddingTests {
@Test func hiddenSidebarUsesMinimumSidebarTitleInset() {
#expect(
ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
) == 228
)
}

@Test func minimumWidthVisibleSidebarMatchesHiddenSidebarTitleInset() {
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
)

#expect(visible == hidden)
}

@Test func widerSidebarPushesTitlebarContentRight() {
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
)

#expect(visible > hidden)
#expect(visible == 332)
}

@Test func fullscreenHiddenSidebarKeepsCompactInset() {
#expect(
ContentView.customTitlebarLeadingPadding(
isFullScreen: true,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
) == 8
)
}
}


@MainActor
final class FolderWindowMoveSuppressionTests: XCTestCase {
private func makeWindow() -> NSWindow {
Expand Down
Loading