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
3 changes: 3 additions & 0 deletions .claude/rules/theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ paths:

- **A content window subclasses `ContentWindow`** and holds a `ThemeWindowBackdrop`. On macOS 26 and later the backdrop sets `window.background` only while the theme sets it; earlier the window keeps its own color. Code asks `ThemeWindowBackdrop.canReachChrome`, never an `#available` of its own.
- `ContentWindow` owns the titlebar. Before macOS 26 it stays opaque: a transparent one there swaps its material for a flat fill.
- **In full screen the titlebar stays opaque too.** There it moves into a window of its own, and transparent under a custom window color it draws an opaque system backstop over one titlebar section, the sidebar's when the window has an inspector. Handing the color back once full screen has begun does not remove it (`apple/scripts/probes/check-fullscreen-titlebar-backstop.sh`). So the full-screen toolbar is the system material in every theme.
- **An opaque titlebar makes its accessories vibrant**, where system fills resolve darker. A vibrant editor tab strip resolves its fills in its window's appearance (`EditorTabStripPalette.drawing(_:_:)`), so it draws the same on either titlebar, and its track takes the theme only while it is not vibrant. Never build an appearance by name for this: `NSAppearance(named:)` returns nil for the high-contrast names, and the window's appearance already carries Increase Contrast.
- **A delegate of a content window forwards `windowDidFailToEnterFullScreen(_:)` to `ContentWindow.fullScreenEntryDidFail()`.** AppKit can refuse full screen after `willEnterFullScreen` and tells only the delegate.
- The detail column sits on `DetailColumnBackdrop`, so a pane that draws nothing shows `window.background`. `DetailPaneBackdropFill` goes only there.
- A glass sidebar or inspector pane sits on `SplitItemBackdrop`, pinned to the pane's edges and not its safe area, so it covers the titlebar band too. It draws only under Reduce Transparency (Content, never chrome) and is clear otherwise, so the glass shows.

Expand Down
30 changes: 15 additions & 15 deletions apple/TablePro/Core/Services/Infrastructure/ContentWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import AppKit

/// The window class of the four content windows: main, Data File, Compare & Sync and the value
/// viewers. On macOS 26 and later the theme reaches a toolbar and titlebar only through
/// `backgroundColor`, and only while the titlebar draws no background of its own.
// The four content windows: main, Data File, Compare & Sync and the value viewers. From macOS 26 the theme
// reaches the toolbar and titlebar only through `backgroundColor`, and only while the titlebar draws no
// background of its own.
@MainActor
internal class ContentWindow: NSWindow {
override internal init(
Expand All @@ -29,25 +29,25 @@ internal class ContentWindow: NSWindow {
)
}

// Hiding the toolbar drops the content's top safe area, so the titlebar is decided again.
override internal func toggleToolbarShown(_ sender: Any?) {
super.toggleToolbarShown(sender)
applyTitlebarPolicy()
}

// The full-screen hooks run either side of the style mask flipping, so they name the state they move to.
internal func applyTitlebarPolicy(isFullScreen: Bool? = nil) {
guard ThemeWindowBackdrop.canReachChrome else { return }
titlebarAppearsTransparent = Self.titlebarIsTransparent(
isFullScreen: isFullScreen ?? styleMask.contains(.fullScreen),
toolbarVisible: toolbar?.isVisible ?? false
isFullScreen: isFullScreen ?? styleMask.contains(.fullScreen)
)
}

// In full screen with no toolbar the content reaches the screen edge, and the titlebar that
// slides down over it needs its own background to stay legible.
internal static func titlebarIsTransparent(isFullScreen: Bool, toolbarVisible: Bool) -> Bool {
isFullScreen ? toolbarVisible : true
// Full screen moves the titlebar into a window of its own. Transparent over a themed window, it draws an
// opaque system backstop under one section in place of the window color, the sidebar's when there is an
// inspector, and changing the color once it is up does not remove it
// (apple/scripts/probes/check-fullscreen-titlebar-backstop.sh).
internal static func titlebarIsTransparent(isFullScreen: Bool) -> Bool {
!isFullScreen
}

// AppKit can refuse full screen after posting willEnterFullScreen, and tells only the delegate.
internal func fullScreenEntryDidFail() {
applyTitlebarPolicy(isFullScreen: false)
}

@objc private func willEnterFullScreen(_ notification: Notification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,6 @@ internal final class MainSplitViewController: NSSplitViewController {
/// when the window appears. A repoint cannot be relied on for this: a window opening with
/// no session repoints from nothing to nothing, which returns before it reaches the toolbar.
owner.refreshContext(forcing: true)
/// The transparency decision reads `window.toolbar?.isVisible`, so a window that gains its
/// toolbar after that decision was taken keeps the opaque titlebar chosen for a
/// toolbar-less one, over content that is no longer inset below it.
(window as? ContentWindow)?.applyTitlebarPolicy()
}

/// The window's toolbar goes too. Dropping only the owner left the built `NSToolbar` on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ internal final class TabWindowController: NSWindowController, NSWindowDelegate {
return false
}

internal func windowDidFailToEnterFullScreen(_ window: NSWindow) {
(window as? ContentWindow)?.fullScreenEntryDidFail()
}

internal func windowWillClose(_ notification: Notification) {
let seq = MainContentCoordinator.nextSwitchSeq()
let t0 = Date()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ internal final class CompareSyncWindowController: NSWindowController,
window.close()
}

internal func windowDidFailToEnterFullScreen(_ window: NSWindow) {
(window as? ContentWindow)?.fullScreenEntryDidFail()
}

internal func windowWillClose(_ notification: Notification) {
// Stays listed until the run itself ends: a statement already sent can still be writing.
session.cancelRunningWork()
Expand Down
4 changes: 4 additions & 0 deletions apple/TablePro/Views/DataFiles/DataFileWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ final class DataFileWindowController: NSWindowController, NSWindowDelegate, NSTo
(contentViewController as? DataFileSplitViewController)?.dismissTransientUI()
}

func windowDidFailToEnterFullScreen(_ window: NSWindow) {
(window as? ContentWindow)?.fullScreenEntryDidFail()
}

func focusSearchField() {
searchItem?.beginSearchInteraction()
}
Expand Down
4 changes: 4 additions & 0 deletions apple/TablePro/Views/Main/EditorTabItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ internal final class EditorTabItemView: NSView {
}

override internal func draw(_ dirtyRect: NSRect) {
EditorTabStripPalette.drawing(self) { drawFills() }
}

private func drawFills() {
let metrics = EditorTabStripLayout.self
if showsLeadingSeparator {
EditorTabStripPalette.separatorColor.setFill()
Expand Down
18 changes: 18 additions & 0 deletions apple/TablePro/Views/Main/EditorTabStripSurfaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ internal enum EditorTabStripPalette {
followsWindowBackdrop && ThemeBackdropState.isThemed(highContrast: highContrast)
}

// A vibrant strip sits on the material of an opaque titlebar, which the window color never reaches.
@MainActor
internal static func isOverThemedBackdrop(in appearance: NSAppearance, highContrast: Bool) -> Bool {
!appearance.allowsVibrancy && isOverThemedBackdrop(highContrast: highContrast)
}

// An opaque titlebar, as in full screen, makes the strip vibrant, where `controlColor` resolves darker than
// the track. The fills are picked for the transparent titlebar, so a vibrant strip resolves them in its
// window's appearance, which also carries Increase Contrast.
@MainActor
internal static func drawing(_ view: NSView, _ body: () -> Void) {
guard view.effectiveAppearance.allowsVibrancy, let window = view.window else {
body()
return
}
window.effectiveAppearance.performAsCurrentDrawingAppearance(body)
}

// Over a themed window an opaque gray cuts a slab into the theme, so the track takes a translucent system fill.
internal static func trackColor(overThemedBackdrop: Bool) -> NSColor {
let native = NSColor.unemphasizedSelectedContentBackgroundColor
Expand Down
8 changes: 6 additions & 2 deletions apple/TablePro/Views/Main/EditorTabStripView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,13 @@ internal final class EditorTabTrackView: NSView {
override internal var mouseDownCanMoveWindow: Bool { false }

override internal func draw(_ dirtyRect: NSRect) {
let radius = bounds.height / 2
let highContrast = NSWorkspace.shared.accessibilityDisplayShouldIncreaseContrast
let themed = EditorTabStripPalette.isOverThemedBackdrop(highContrast: highContrast)
let themed = EditorTabStripPalette.isOverThemedBackdrop(in: effectiveAppearance, highContrast: highContrast)
EditorTabStripPalette.drawing(self) { drawTrack(overThemedBackdrop: themed) }
}

private func drawTrack(overThemedBackdrop themed: Bool) {
let radius = bounds.height / 2
EditorTabStripPalette.trackColor(overThemedBackdrop: themed).setFill()
NSBezierPath(roundedRect: bounds, xRadius: radius, yRadius: radius).fill()

Expand Down
63 changes: 41 additions & 22 deletions apple/TableProTests/Services/ContentWindowTitlebarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import SwiftUI
@testable import TablePro
import Testing

/// The four content windows as the app builds them. Never ordered front and never closed: `close()`
/// on a test window over-releases it.
// Never ordered front, and closed only with isReleasedWhenClosed off: `close()` on a test window over-releases it.
@MainActor
struct ContentWindowTitlebarTests {
private struct Built {
Expand Down Expand Up @@ -73,21 +72,11 @@ struct ContentWindowTitlebarTests {
}

@Test(
"The titlebar stays opaque only in full screen with the toolbar hidden",
arguments: [
(isFullScreen: false, toolbarVisible: false, transparent: true),
(isFullScreen: false, toolbarVisible: true, transparent: true),
(isFullScreen: true, toolbarVisible: true, transparent: true),
(isFullScreen: true, toolbarVisible: false, transparent: false),
]
"The titlebar is transparent in a window and opaque in full screen",
arguments: [(isFullScreen: false, transparent: true), (isFullScreen: true, transparent: false)]
)
func transparencyFollowsTheSafeArea(state: (isFullScreen: Bool, toolbarVisible: Bool, transparent: Bool)) {
#expect(
ContentWindow.titlebarIsTransparent(
isFullScreen: state.isFullScreen,
toolbarVisible: state.toolbarVisible
) == state.transparent
)
func transparencyFollowsFullScreen(state: (isFullScreen: Bool, transparent: Bool)) {
#expect(ContentWindow.titlebarIsTransparent(isFullScreen: state.isFullScreen) == state.transparent)
}

@Test(
Expand All @@ -113,7 +102,7 @@ struct ContentWindowTitlebarTests {
}

@Test(
"A full-screen window keeps a transparent titlebar while its toolbar is showing",
"The main window keeps an opaque titlebar in full screen while its toolbar is showing",
.enabled(
if: ProcessInfo.processInfo.isOperatingSystemAtLeast(
OperatingSystemVersion(majorVersion: 26, minorVersion: 0, patchVersion: 0)
Expand All @@ -122,19 +111,49 @@ struct ContentWindowTitlebarTests {
)
)
func fullScreenWithAToolbar() throws {
let window = CompareSyncWindowController.makeWindow()
defer { window.toolbar = nil }
let window = TabWindowController.makeEditorWindow()
window.isReleasedWhenClosed = false
defer {
window.toolbar = nil
window.close()
}
let toolbar = NSToolbar(identifier: "com.TablePro.tests.titlebar.\(UUID().uuidString)")
toolbar.autosavesConfiguration = false
window.toolbar = toolbar
toolbar.isVisible = true
try #require(toolbar.isVisible)

NotificationCenter.default.post(name: NSWindow.willEnterFullScreenNotification, object: window)
#expect(!window.titlebarAppearsTransparent)

NotificationCenter.default.post(name: NSWindow.didExitFullScreenNotification, object: window)
#expect(window.titlebarAppearsTransparent)
}

toolbar.isVisible = false
NotificationCenter.default.post(name: NSWindow.willEnterFullScreenNotification, object: window)
#expect(!window.titlebarAppearsTransparent)
@Test(
"A full-screen entry AppKit refuses gives the window its transparent titlebar back",
.enabled(
if: ProcessInfo.processInfo.isOperatingSystemAtLeast(
OperatingSystemVersion(majorVersion: 26, minorVersion: 0, patchVersion: 0)
),
"the titlebar turns transparent from macOS 26"
)
)
func failedFullScreenEntry() throws {
let fixture = try OffscreenConnectionWindow(size: CGSize(width: 1_200, height: 800))
defer { fixture.tearDown() }
let dataFile = DataFileWindowController(document: DataFileDocument())
let dataFileWindow = try #require(dataFile.window)
defer { dataFileWindow.delegate = nil }
let windows: [(NSWindow, () -> Void)] = [
(fixture.window, { fixture.controller.windowDidFailToEnterFullScreen(fixture.window) }),
(dataFileWindow, { dataFile.windowDidFailToEnterFullScreen(dataFileWindow) }),
]
for (window, fail) in windows {
NotificationCenter.default.post(name: NSWindow.willEnterFullScreenNotification, object: window)
#expect(!window.titlebarAppearsTransparent)
fail()
#expect(window.titlebarAppearsTransparent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,61 @@ struct EditorTabStripTrackThemeTests {
}

private static func center(of view: NSView) throws -> NSColor {
try color(of: view, atFraction: 0.5)
}

// Left of a tab's centred title, inside its capsule.
private static func color(of view: NSView, atFraction fraction: CGFloat) throws -> NSColor {
let bitmap = try #require(view.bitmapImageRepForCachingDisplay(in: view.bounds))
view.cacheDisplay(in: view.bounds, to: bitmap)
let color = try #require(bitmap.colorAt(x: bitmap.pixelsWide / 2, y: bitmap.pixelsHigh / 2))
let x = Int(CGFloat(bitmap.pixelsWide) * fraction)
let color = try #require(bitmap.colorAt(x: x, y: bitmap.pixelsHigh / 2))
return try #require(color.usingColorSpace(.sRGB))
}

@Test(
"On an opaque titlebar's vibrant strip the track and the selected tab draw as on the transparent titlebar",
arguments: [(NSAppearance.Name.vibrantDark, NSAppearance.Name.darkAqua), (.vibrantLight, .aqua)]
)
func vibrantStripDrawsLikeTheTransparentTitlebar(names: (vibrant: NSAppearance.Name, plain: NSAppearance.Name)) throws {
// Never ordered front and never closed: `close()` on a test window over-releases it.
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 200, height: 100),
styleMask: [.titled],
backing: .buffered,
defer: true
)
window.isReleasedWhenClosed = false
window.appearance = NSAppearance(named: names.plain)
let track = EditorTabTrackView(frame: NSRect(x: 0, y: 0, width: 120, height: 40))
let tab = EditorTabItemView(item: .sample(isSelected: true))
tab.frame = NSRect(x: 0, y: 50, width: 160, height: 28)
try ThemeTestFixture.adopting(.builtIn, appearance: .dark) {
for view in [track, tab] as [NSView] {
window.contentView?.addSubview(view)
defer { view.removeFromSuperview() }
view.appearance = nil
let plain = try Self.color(of: view, atFraction: 0.15)
view.appearance = NSAppearance(named: names.vibrant)
let vibrant = try Self.color(of: view, atFraction: 0.15)
#expect(ThemeTestFixture.matches(plain, vibrant), "\(type(of: view)) drew \(vibrant), not \(plain)")
}
}
}

@Test("On an opaque titlebar's vibrant strip a window theme leaves the track the system's own")
func vibrantStripKeepsTheSystemTrackUnderATheme() throws {
try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) {
let vibrant = try #require(NSAppearance(named: .vibrantDark))
let plain = try #require(NSAppearance(named: .darkAqua))
#expect(!EditorTabStripPalette.isOverThemedBackdrop(in: vibrant, highContrast: false))
#expect(
EditorTabStripPalette.isOverThemedBackdrop(in: plain, highContrast: false)
== EditorTabStripPalette.followsWindowBackdrop
)
}
}

@Test("The selected tab stays the system's own fill under a theme")
func selectedTabStaysSystem() throws {
try ThemeTestFixture.adopting([.windowBackdrop: ThemeTestFixture.windowHex], appearance: .dark) {
Expand Down
1 change: 1 addition & 0 deletions apple/changelog.d/4635.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In full screen, a theme with a window background covered the top of the sidebar with a dark or light block.
Loading
Loading