Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Sidebar follows Reduce transparency like Arc, pinned and hidden; one backdrop refresh per theme change (#156) (#160)

Victor Kildahl1d24d8c8528c
diff --git a/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift b/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift
new file mode 100644
index 0000000..ace92fa
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift
@@ -0,0 +1,87 @@
+import Foundation
+
+/// What the sidebar's backdrop layer draws for light vibrant and solid themes (ShellView's
+/// CABackdropLayer path): which capture is in the tree, and the black dim and white lift over it.
+///
+/// AppKit's material, and with it Arc's sidebar, keeps only the layer it draws from in the tree:
+/// no capture under an opaque fill, the desktop tint instead of the blur in fullscreen, and no
+/// capture at all with Reduce Transparency, where every material is one opaque fill (GitHub #156).
+public struct SidebarBackdrop: Equatable, Sendable {
+ public enum Source: String, Sendable {
+ case none = "flat"
+ case blur
+ case desktopTint = "desktop tint"
+ }
+
+ /// The light vibrant themes' calibration (CraTuning: blurDim, liftActive, …).
+ public struct Vibrant: Equatable, Sendable {
+ public var dim: Double
+ public var liftTop: Double
+ public var liftBottom: Double
+ public var dimInactive: Double
+ public var liftInactive: Double
+
+ public init(dim: Double, liftTop: Double, liftBottom: Double, dimInactive: Double, liftInactive: Double) {
+ self.dim = dim
+ self.liftTop = liftTop
+ self.liftBottom = liftBottom
+ self.dimInactive = dimInactive
+ self.liftInactive = liftInactive
+ }
+ }
+
+ public var source: Source
+ public var dim: Double
+ public var liftTop: Double
+ public var liftBottom: Double
+
+ public init(source: Source, dim: Double, liftTop: Double, liftBottom: Double) {
+ self.source = source
+ self.dim = dim
+ self.liftTop = liftTop
+ self.liftBottom = liftBottom
+ }
+
+ /// Solid themes: Arc's material is grey 66 passing 52 % of the backdrop, flat 212 while inactive.
+ public static let solidActive = SidebarBackdrop(source: .blur, dim: 0.30, liftTop: 0.26, liftBottom: 0.26)
+ public static let solidInactive = SidebarBackdrop(source: .none, dim: 1, liftTop: 0.83, liftBottom: 0.83)
+ /// Solid themes with Reduce Transparency: Arc's flat grey under the space colour, active or not
+ /// (GitHub #156: 160 in both of the reporter's solid spaces, windowed and fullscreen, and the
+ /// same through a Space swipe, where the app is inactive until it lands).
+ public static let solidReduced = SidebarBackdrop(source: .none, dim: 1, liftTop: 0.63, liftBottom: 0.63)
+
+ public static func resolve(
+ solid: Bool, active: Bool, fullscreen: Bool, reduceTransparency: Bool,
+ tintAvailable: Bool, vibrant: Vibrant
+ ) -> SidebarBackdrop {
+ if solid {
+ if reduceTransparency { return solidReduced }
+ guard active else { return solidInactive }
+ var b = solidActive
+ if fullscreen && tintAvailable { b.source = .desktopTint }
+ return b
+ }
+ // Reduce Transparency turns the material into its inactive look, without a capture.
+ let full = active && !reduceTransparency
+ let dim = reduceTransparency ? 1 : active ? vibrant.dim : vibrant.dimInactive
+ return SidebarBackdrop(
+ source: dim >= 1 ? .none : fullscreen && tintAvailable ? .desktopTint : .blur, dim: dim,
+ liftTop: full ? vibrant.liftTop : vibrant.liftInactive,
+ liftBottom: full ? vibrant.liftBottom : vibrant.liftInactive)
+ }
+
+ /// The white lift over the floating sidebar's material (dark hudWindow), light themes. Under
+ /// Reduce transparency that material is its opaque dark fill, 38, which is Arc's floating panel
+ /// under the space colour (GitHub #156: 156/64/72 at #F25E6B 0.8), so the lift goes.
+ public static func floatingLift(dark: Bool, reduceTransparency: Bool, lift: Double) -> Double {
+ dark ? 0.15 : reduceTransparency ? 0 : lift
+ }
+
+ /// One cra.log line per change, so a report of a sharp or off-colour sidebar can be matched to
+ /// the window's state.
+ public func logLine(active: Bool, reduceTransparency: Bool) -> String {
+ var s = "\(source.rawValue), \(active ? "active" : "inactive"), dim \(String(format: "%.2f", dim))"
+ if reduceTransparency { s += ", reduce transparency" }
+ return s
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift b/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift
new file mode 100644
index 0000000..3b0c57b
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift
@@ -0,0 +1,63 @@
+import CraCore
+import Testing
+
+/// The sidebar's backdrop layer through activation, fullscreen and Reduce Transparency (GitHub #156).
+struct SidebarBackdropTests {
+ let vibrant = SidebarBackdrop.Vibrant(dim: 0.36, liftTop: 0.35, liftBottom: 0.37, dimInactive: 1, liftInactive: 0.28)
+
+ func resolve(solid: Bool, active: Bool = true, fullscreen: Bool = false, reduce: Bool = false, tint: Bool = true) -> SidebarBackdrop {
+ SidebarBackdrop.resolve(solid: solid, active: active, fullscreen: fullscreen, reduceTransparency: reduce, tintAvailable: tint, vibrant: vibrant)
+ }
+
+ @Test func solidThemesBlurWhileActiveAndGoFlatWhileInactive() {
+ #expect(resolve(solid: true) == SidebarBackdrop(source: .blur, dim: 0.30, liftTop: 0.26, liftBottom: 0.26))
+ #expect(resolve(solid: true, active: false) == SidebarBackdrop(source: .none, dim: 1, liftTop: 0.83, liftBottom: 0.83))
+ }
+
+ @Test func fullscreenSwapsTheBlurForTheDesktopTint() {
+ #expect(resolve(solid: true, fullscreen: true).source == .desktopTint)
+ #expect(resolve(solid: false, fullscreen: true).source == .desktopTint)
+ // Without CAChameleonLayer the blur stays.
+ #expect(resolve(solid: true, fullscreen: true, tint: false).source == .blur)
+ #expect(resolve(solid: true, active: false, fullscreen: true).source == .none)
+ }
+
+ @Test func reduceTransparencyNeverShowsACapture() {
+ for solid in [true, false] {
+ for active in [true, false] {
+ for fullscreen in [true, false] {
+ let b = resolve(solid: solid, active: active, fullscreen: fullscreen, reduce: true)
+ #expect(b.source == .none)
+ #expect(b.dim == 1)
+ }
+ }
+ }
+ // Solid: Arc's opaque grey under the space colour, darker than the inactive fill, and the
+ // same while inactive, so neither an activation nor a Space swipe steps.
+ #expect(resolve(solid: true, reduce: true) == SidebarBackdrop.solidReduced)
+ #expect(resolve(solid: true, active: false, fullscreen: true, reduce: true) == SidebarBackdrop.solidReduced)
+ #expect(SidebarBackdrop.solidReduced.liftTop < SidebarBackdrop.solidInactive.liftTop)
+ // Light vibrant: the inactive look, active or not.
+ #expect(resolve(solid: false, reduce: true) == resolve(solid: false, active: false))
+ #expect(resolve(solid: false, active: false, reduce: true) == resolve(solid: false, active: false))
+ }
+
+ @Test func lightVibrantThemesKeepTheirCalibration() {
+ #expect(resolve(solid: false) == SidebarBackdrop(source: .blur, dim: 0.36, liftTop: 0.35, liftBottom: 0.37))
+ #expect(resolve(solid: false, active: false) == SidebarBackdrop(source: .none, dim: 1, liftTop: 0.28, liftBottom: 0.28))
+ }
+
+ @Test func floatingSidebarDropsItsLiftUnderReduceTransparency() {
+ #expect(SidebarBackdrop.floatingLift(dark: false, reduceTransparency: false, lift: 0.35) == 0.35)
+ #expect(SidebarBackdrop.floatingLift(dark: false, reduceTransparency: true, lift: 0.35) == 0)
+ #expect(SidebarBackdrop.floatingLift(dark: true, reduceTransparency: false, lift: 0.35) == 0.15)
+ #expect(SidebarBackdrop.floatingLift(dark: true, reduceTransparency: true, lift: 0.35) == 0.15)
+ }
+
+ @Test func logLineNamesTheState() {
+ #expect(resolve(solid: true).logLine(active: true, reduceTransparency: false) == "blur, active, dim 0.30")
+ #expect(resolve(solid: true, fullscreen: true).logLine(active: true, reduceTransparency: false) == "desktop tint, active, dim 0.30")
+ #expect(resolve(solid: true, active: false).logLine(active: false, reduceTransparency: false) == "flat, inactive, dim 1.00")
+ #expect(resolve(solid: true, reduce: true).logLine(active: true, reduceTransparency: true) == "flat, active, dim 1.00, reduce transparency")
+ }
+}
diff --git a/Sources/Cra/Services/Diagnostics.swift b/Sources/Cra/Services/Diagnostics.swift
index 9407709..c9f9f8c 100644
--- a/Sources/Cra/Services/Diagnostics.swift
+++ b/Sources/Cra/Services/Diagnostics.swift
@@ -165,6 +165,8 @@ enum Diagnostics {
"macOS \(os.majorVersion).\(os.minorVersion).\(os.patchVersion), \(String(cString: model)), \(ProcessInfo.processInfo.physicalMemory >> 30) GB, \(ProcessInfo.processInfo.activeProcessorCount) cores",
DisplayDiagnostics.summary(displays),
"Stage Manager: \(stageManager ? "on" : "off")",
+ // The sidebar goes opaque under it, like AppKit's materials (GitHub #156).
+ "Reduce transparency: \(NSWorkspace.shared.accessibilityDisplayShouldReduceTransparency ? "on" : "off"), increase contrast: \(NSWorkspace.shared.accessibilityDisplayShouldIncreaseContrast ? "on" : "off")",
"Running from: \(Bundle.main.bundlePath)",
"Up for: \(Int(ProcessInfo.processInfo.systemUptime / 60)) min (Mac), \(Int(-(NSRunningApplication.current.launchDate ?? Date()).timeIntervalSinceNow / 60)) min (Cra)",
"Embedded pages: \(EmbeddedPages.isEnabled), Chrome-style hosting: \(CraCEFRuntime.chromeHosting())",
diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swift
index 261c872..785c6d9 100644
--- a/Sources/Cra/UI/ShellView.swift
+++ b/Sources/Cra/UI/ShellView.swift
@@ -23,10 +23,13 @@ final class ShellView: NSView {
private var loggedBackdrop: String?
private let dimLayer = CALayer()
private let liftLayer = CAGradientLayer()
- /// Set by the window controller: light theme that wants the blur path.
- var vibrantLight = false { didSet { refreshLift() } }
+ /// Light theme that wants the blur path (setTheme).
+ private(set) var vibrantLight = false
/// Arc's one-colour themes, light or dark: the blur under SpacePalette.solidAlpha's material.
- var solidBackdrop = false { didSet { refreshLift() } }
+ private(set) var solidBackdrop = false
+ /// System Settings ▸ Accessibility ▸ Display ▸ Reduce transparency (or Increase contrast):
+ /// AppKit's materials, and Arc's sidebar, go opaque. The backdrop layer path follows (GitHub #156).
+ private var reduceTransparency = NSWorkspace.shared.accessibilityDisplayShouldReduceTransparency
var usesBackdropLayer: Bool { (solidBackdrop || vibrantLight && !vibrantDark) && backdropLayer != nil }
/// Lifts the dark blur toward Arc's mid-grey base before the gradient goes on.
let vibrancyLift = NSView()
@@ -118,7 +121,16 @@ final class ShellView: NSView {
}
/// Dark vibrant themes keep the earlier calibration (underWindowBackground + 15% lift).
- var vibrantDark = false { didSet { refreshLift() } }
+ private(set) var vibrantDark = false
+
+ /// A space's theme in one refresh: set one flag at a time, a switch from a vibrant to a solid
+ /// space drew a frame with the vibrant calibration (two cra.log lines, dim 0.36 then 0.30).
+ func setTheme(vibrantDark: Bool, vibrantLight: Bool, solid: Bool) {
+ self.vibrantDark = vibrantDark
+ self.vibrantLight = vibrantLight
+ solidBackdrop = solid
+ refreshLift()
+ }
/// Core Animation's gaussian blur (the filter NSVisualEffectView uses), built
/// through its private class; nil when the runtime does not provide it.
@@ -161,25 +173,25 @@ final class ShellView: NSView {
vibrancyLift.isHidden = true
backdropHost.isHidden = false
CATransaction.begin(); CATransaction.setDisableActions(true)
- let tint = windowFullscreen && desktopTintLayer != nil
- // Solid: Arc's material is grey 66 passing 52 % of the backdrop, flat 212 while inactive.
- let dim = solidBackdrop ? (windowActive ? 0.30 : 1) : windowActive ? t.blurDim : t.blurDimInactive
- dimLayer.opacity = Float(dim)
- // NSVisualEffectView keeps only the layer it draws from in the tree: no capture under an
- // opaque fill, the desktop tint instead of the blur in fullscreen. A capture added back
- // on activation draws the substitute colour until it is live, where one kept under the
- // fill showed the window behind sharp for a frame (GitHub #132).
- let source = dim >= 1 ? nil : tint ? desktopTintLayer : backdropLayer
+ let backdrop = SidebarBackdrop.resolve(
+ solid: solidBackdrop, active: windowActive, fullscreen: windowFullscreen,
+ reduceTransparency: reduceTransparency, tintAvailable: desktopTintLayer != nil,
+ vibrant: .init(dim: t.blurDim, liftTop: t.liftActive, liftBottom: t.liftActiveBottom,
+ dimInactive: t.blurDimInactive, liftInactive: t.liftInactive))
+ dimLayer.opacity = Float(backdrop.dim)
+ // A capture added back on activation draws the substitute colour until it is live, where
+ // one kept under the fill showed the window behind sharp for a frame (GitHub #132).
+ let source: CALayer? = switch backdrop.source {
+ case .none: nil
+ case .blur: backdropLayer
+ case .desktopTint: desktopTintLayer
+ }
for l in [backdropLayer, desktopTintLayer].compactMap({ $0 }) where (l === source) != (l.superlayer != nil) {
if l === source { backdropHost.layer?.insertSublayer(l, at: 0) } else { l.removeFromSuperlayer() }
}
- let top = solidBackdrop ? (windowActive ? 0.26 : 0.83) : windowActive ? t.liftActive : t.liftInactive
- let bottom = solidBackdrop ? top : windowActive ? t.liftActiveBottom : t.liftInactive
- liftLayer.colors = [NSColor(white: 1, alpha: top).cgColor, NSColor(white: 1, alpha: bottom).cgColor]
+ liftLayer.colors = [NSColor(white: 1, alpha: backdrop.liftTop).cgColor, NSColor(white: 1, alpha: backdrop.liftBottom).cgColor]
CATransaction.commit()
- // One line per change, so a report of a sharp or off-colour sidebar can be matched
- // to the window's state in cra.log.
- let state = "\(source == nil ? "flat" : tint ? "desktop tint" : "blur"), \(windowActive ? "active" : "inactive"), dim \(String(format: "%.2f", dim))"
+ let state = backdrop.logLine(active: windowActive, reduceTransparency: reduceTransparency)
if state != loggedBackdrop {
loggedBackdrop = state
CraLog.note("sidebar backdrop: " + state)
@@ -249,6 +261,9 @@ final class ShellView: NSView {
backdropHost.isHidden = true
addSubview(backdropHost)
Self.logBackdropPath(layer: backdropLayer != nil)
+ NSWorkspace.shared.notificationCenter.addObserver(
+ self, selector: #selector(accessibilityDisplayOptionsChanged),
+ name: NSWorkspace.accessibilityDisplayOptionsDidChangeNotification, object: nil)
vibrancyLift.wantsLayer = true
vibrancyLift.layer?.backgroundColor = NSColor(white: 1, alpha: 0.15).cgColor
vibrancyLift.isHidden = true
@@ -293,6 +308,13 @@ final class ShellView: NSView {
required init?(coder: NSCoder) { fatalError() }
+ @objc private func accessibilityDisplayOptionsChanged() {
+ let reduce = NSWorkspace.shared.accessibilityDisplayShouldReduceTransparency
+ guard reduce != reduceTransparency else { return }
+ reduceTransparency = reduce
+ refreshLift()
+ }
+
override var isFlipped: Bool { false }
// MARK: Panes
diff --git a/Sources/Cra/UI/Windows/FloatingSidebar.swift b/Sources/Cra/UI/Windows/FloatingSidebar.swift
index 4382279..bb71091 100644
--- a/Sources/Cra/UI/Windows/FloatingSidebar.swift
+++ b/Sources/Cra/UI/Windows/FloatingSidebar.swift
@@ -49,10 +49,13 @@ final class FloatingSidebarController {
deinit {
poll?.invalidate()
activation.forEach(NotificationCenter.default.removeObserver)
+ displayOptions.map(NSWorkspace.shared.notificationCenter.removeObserver)
}
private var poll: Timer?
private var activation: [NSObjectProtocol] = []
+ /// Reduce transparency changes the panel's lift (GitHub #156).
+ private var displayOptions: NSObjectProtocol?
/// No window of ours reliably receives mouse-moved events here: the key window
/// is usually a Chromium page window, and the shell's tracking areas only run in
@@ -68,6 +71,11 @@ final class FloatingSidebarController {
}
}
setPolling(NSApp.isActive)
+ displayOptions = NSWorkspace.shared.notificationCenter.addObserver(
+ forName: NSWorkspace.accessibilityDisplayOptionsDidChangeNotification, object: nil, queue: .main
+ ) { [weak self] _ in
+ MainActor.assumeIsolated { self?.refreshBackdrop() }
+ }
}
private func setPolling(_ on: Bool) {
@@ -184,7 +192,8 @@ final class FloatingSidebarController {
lift.isHidden = !pal.vibrant
blur.material = pal.isDark ? .underWindowBackground : t.material
blur.appearance = NSAppearance(named: t.darkBlur ? .darkAqua : .aqua)
- lift.layer?.backgroundColor = NSColor(white: 1, alpha: pal.isDark ? 0.15 : t.liftActive).cgColor
+ let reduce = NSWorkspace.shared.accessibilityDisplayShouldReduceTransparency
+ lift.layer?.backgroundColor = NSColor(white: 1, alpha: SidebarBackdrop.floatingLift(dark: pal.isDark, reduceTransparency: reduce, lift: t.liftActive)).cgColor
}
func show() {
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 7fa0474..6aaa322 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -353,10 +353,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
// Vibrant themes see through to the desktop like Arc; others are opaque.
shell.vibrancy.isHidden = !palette.vibrant
shell.vibrancyLift.isHidden = !palette.vibrant
- shell.vibrantDark = palette.isDark
- shell.vibrantLight = palette.vibrant && !palette.isDark
- shell.solidBackdrop = palette.solid
- shell.refreshLift()
+ shell.setTheme(vibrantDark: palette.isDark, vibrantLight: palette.vibrant && !palette.isDark, solid: palette.solid)
window?.isOpaque = !palette.vibrant
window?.backgroundColor = palette.vibrant ? .clear : NSColor(palette.gradientColors.first ?? .gray)
}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index b3a9e3a..3fe39d2 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2028,6 +2028,22 @@ Theme palettes in a hand-built space can be borrowed; only the `background` styl
CloudDev (#F25E6B, 0.8) fullscreen, stills: 214/116/119 before, 217/114/117 after (Arc on #132's Mac 210/110/117).
A Space swipe reads the inactive value until the app is active again, then steps in one frame, as AppKit's
material does (`followsWindowActiveState`).
+- [O] Reduce Transparency (3 Nov 2026, issue #156, the reporter's 0.1.28 recordings next to Arc's, 60 fps). On the
+ reporter's Mac Arc's sidebar never passes the backdrop: flat in every frame, windowed or fullscreen, active or not,
+ over a wallpaper Cra's blur shows plainly (white 0.8 space 218–222 grey; CloudDev #F25E6B 0.8 210/110/117 windowed
+ and fullscreen alike; hidden-sidebar panel 156/64/72). Cra in the same captures: blur active, 231/127/135 flat
+ inactive, 169/74/82 over the desktop tint in fullscreen, so every activation and every Space swipe stepped and Arc's
+ never did. That is Accessibility ▸ Display ▸ Reduce transparency (or Increase contrast, which turns it on):
+ NSVisualEffectView, dumped from a probe with `NSWorkspace.accessibilityDisplayShouldReduceTransparency` swapped to
+ true and `_accessibilityRTChanged:` sent, drops the CABackdropLayer and the CAChameleonLayer and keeps one opaque
+ fill (hudWindow aqua 228 active / 240 inactive, dark 38 / 40; sidebar and underWindowBackground aqua 246 / 236, dark
+ 56 / 20). ArcCore also reads the setting itself (one ObjC helper at 0x457c2d4 in 1.171's arm64 slice). Solving
+ α·colour + (1 − α)·F, α = solidAlpha(0.8) = 0.63, gives F ≈ 160 for Arc's pinned sidebar in both spaces (against
+ 212 inactive), and ≈ 40 for its floating panel (the dark material's fill). Cra's own CABackdropLayer ignored the
+ setting. Cra now resolves the layer through `SidebarBackdrop` (CraCore): with Reduce transparency there is no
+ capture at all, solid themes rest at dim 1, lift 0.63 active or inactive (Arc's value doesn't move when its
+ fullscreen swipe lands, Cra's stepped from the inactive 212), light vibrant themes at their inactive look, and the floating sidebar drops its white lift so the
+ dark material's fill shows under the colour like Arc's panel (Cra pinned − floating 45/46/45, Arc 54/46/45); cra.log adds ", reduce transparency" and the diagnostics export names the setting.
- [O] Tab list scroller: AppKit overlay scroller (AXScrollBar, 17 pt track) shown while scrolling, then faded;
the knob is 4 pt wide, 3 pt in from the sidebar edge, white 49 % on a dark theme, no track. Cra:
`SidebarScroller`, 10 pt wide so it stays in the gutter right of the rows (knob on Arc's exact columns).
diff --git a/scripts/test-floating-sidebar.sh b/scripts/test-floating-sidebar.sh
index 116e5e5..7cb4544 100755
--- a/scripts/test-floating-sidebar.sh
+++ b/scripts/test-floating-sidebar.sh
@@ -5,7 +5,8 @@ cd "$(dirname "$0")/.."
TEST_DIR="$(mktemp -d /tmp/cra-sidebar-tests.XXXXXX)"
trap 'rm -rf "$TEST_DIR"' EXIT
xcrun swiftc -parse-as-library ${CRA_TEST_SWIFTC_FLAGS:-} Sources/Cra/UI/Windows/FloatingSidebarGeometry.swift \
- Sources/Cra/UI/Windows/FloatingSidebar.swift Tests/FloatingSidebarTests.swift \
+ Sources/Cra/UI/Windows/FloatingSidebar.swift Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift \
+ Tests/FloatingSidebarTests.swift \
-o "$TEST_DIR/sidebar-tests"
"$TEST_DIR/sidebar-tests"
[ -z "${CRA_TEST_KEEP:-}" ] || cp "$TEST_DIR/sidebar-tests" "$CRA_TEST_KEEP/"