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 keeps its active look through a full screen Space switch, and builds its blur like AppKit's (#156)
Victorf6b9fb61a758
diff --git a/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift b/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swiftindex 8ad0172..9783bd7 100644--- a/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift+++ b/Packages/CraCore/Sources/CraCore/SidebarBackdrop.swift@@ -77,8 +77,16 @@ public struct SidebarBackdrop: Equatable, Sendable {/// and a restore from the Dock keeps the flat fill through the genie until the window is main again,/// about 0.4 s after the app became active. Following the app instead asked for a live capture of a/// window still flying out of the Dock, which showed matte or sharp frames as it landed.- public static func windowActive(appActive: Bool, miniaturized: Bool, holdsKeyOrMain: Bool) -> Bool {- appActive && !miniaturized && holdsKeyOrMain+ ///+ /// `activeAppearance` is AppKit's own answer for the window, read from a material that follows it. A full+ /// screen window keeps its active appearance while its Space slides away and the app resigns active, so+ /// Arc's sidebar keeps the desktop tint through a ⌃← / ⌃→ round trip (probe, 5 Nov 2026). Cra's own rule+ /// dropped to the flat fill there and stepped back about 5 frames after the slide had landed. The rule+ /// above still counts on its own, because AppKit's answer doesn't know about Cra's child page windows.+ public static func windowActive(+ appActive: Bool, miniaturized: Bool, holdsKeyOrMain: Bool, activeAppearance: Bool = false+ ) -> Bool {+ !miniaturized && (appActive && holdsKeyOrMain || activeAppearance)}/// The white lift over the floating sidebar's material (dark hudWindow), light themes. Underdiff --git a/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift b/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swiftindex 9ff26e1..01269b3 100644--- a/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/SidebarBackdropTests.swift@@ -66,6 +66,17 @@ struct SidebarBackdropTests {#expect(!SidebarBackdrop.windowActive(appActive: false, miniaturized: false, holdsKeyOrMain: true))}+ /// A full screen window keeps AppKit's active appearance while its Space slides away (GitHub #156):+ /// the app resigns active and the window loses key and main, but the material stays active.+ @Test func fullScreenWindowKeepsAppKitsActiveAppearance() {+ #expect(SidebarBackdrop.windowActive(appActive: false, miniaturized: false, holdsKeyOrMain: false, activeAppearance: true))+ // A page window holding key: AppKit's answer for the parent may be off, Cra's rule still counts.+ #expect(SidebarBackdrop.windowActive(appActive: true, miniaturized: false, holdsKeyOrMain: true, activeAppearance: false))+ // Minimized wins.+ #expect(!SidebarBackdrop.windowActive(appActive: true, miniaturized: true, holdsKeyOrMain: true, activeAppearance: true))+ #expect(!SidebarBackdrop.windowActive(appActive: false, miniaturized: false, holdsKeyOrMain: false, activeAppearance: false))+ }+@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")diff --git a/Sources/Cra/UI/ActiveAppearanceProbe.swift b/Sources/Cra/UI/ActiveAppearanceProbe.swiftnew file mode 100644index 0000000..837cdb9--- /dev/null+++ b/Sources/Cra/UI/ActiveAppearanceProbe.swift@@ -0,0 +1,45 @@+import AppKit+import ObjectiveC++/// AppKit's own answer to "does this window draw its active look", read from a zero-size material that+/// follows its window, the way Arc's sidebar does (SidebarBackdrop.windowActive, GitHub #156).+///+/// It differs from app-active-and-key in one place that shows: a full screen window keeps its active+/// appearance while its Space slides away and the app resigns active, so Arc's sidebar keeps the desktop+/// tint through a ⌃← / ⌃→ round trip. A probe logged that on 5 Nov 2026: `_shouldUseActiveAppearance`+/// stayed on with the app inactive and the window holding neither key nor main, windowed it went off as+/// the window resigned main.+final class ActiveAppearanceProbe: NSVisualEffectView {+ /// AppKit told the view the window's key state changed (`_windowChangedKeyState`, the hook+ /// NSVisualEffectView itself redraws from).+ var onChange: (() -> Void)?++ private static let changedSel = NSSelectorFromString("_windowChangedKeyState")+ private static let answerSel = NSSelectorFromString("_shouldUseActiveAppearance")+ /// Both private hooks exist on this macOS; without them Cra keeps its own rule alone.+ static let available = class_getInstanceMethod(NSVisualEffectView.self, changedSel) != nil+ && class_getInstanceMethod(NSVisualEffectView.self, answerSel) != nil++ init() {+ super.init(frame: .zero)+ state = .followsWindowActiveState+ blendingMode = .withinWindow+ }++ required init?(coder: NSCoder) { fatalError() }++ /// nil when AppKit doesn't have the hook or the view isn't in a window.+ var isActive: Bool? {+ guard Self.available, window != nil, let imp = class_getMethodImplementation(NSVisualEffectView.self, Self.answerSel) else { return nil }+ typealias Answer = @convention(c) (AnyObject, Selector) -> Bool+ return unsafeBitCast(imp, to: Answer.self)(self, Self.answerSel)+ }++ @objc func _windowChangedKeyState() {+ if Self.available, let imp = class_getMethodImplementation(NSVisualEffectView.self, Self.changedSel) {+ typealias Changed = @convention(c) (AnyObject, Selector) -> Void+ unsafeBitCast(imp, to: Changed.self)(self, Self.changedSel)+ }+ onChange?()+ }+}diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swiftindex 48678fc..2a734bc 100644--- a/Sources/Cra/UI/ShellView.swift+++ b/Sources/Cra/UI/ShellView.swift@@ -20,6 +20,8 @@ final class ShellView: NSView {/// tint (CAChameleonLayer). We do the same (GitHub #83).private var desktopTintLayer: CALayer?var windowFullscreen = false { didSet { if windowFullscreen != oldValue { refreshLift() } } }+ /// AppKit's answer to whether the window draws its active look (MainWindowController.materialActiveNow).+ let activeAppearance = ActiveAppearanceProbe()private var loggedBackdrop: String?private let dimLayer = CALayer()private let liftLayer = CAGradientLayer()@@ -158,6 +160,18 @@ final class ShellView: NSView {return filter}+ /// The hudWindow material's capture, as AppKit builds it (probe dump, 5 Nov 2026): an eighth-scale+ /// capture under SDR normalize, a 30 pt blur and saturate 1.6. Cra's own full-scale 40 pt blur was+ /// blurrier and greyer than Arc's over a colourful backdrop, and 64 times the pixels for the window+ /// server to rebuild whenever the capture comes back (the dropout out of Stage Manager, GitHub #156).+ /// Over the plain white and black backdrops the dim and lift were fitted on, it draws the same.+ static let backdropScale = 0.125+ static func makeBackdropFilters() -> [NSObject] {+ guard let blur = makeBackdropBlur(radius: 30) else { return [] }+ let tint = makeTintFilters()+ return tint.count == 2 ? [tint[0], blur, tint[1]] : [blur]+ }+/// The hudWindow material's filters on its desktop tint: SDR normalize, saturate 1.6.static func makeTintFilters() -> [NSObject] {guard let cls = NSClassFromString("CAFilter") as? NSObject.Type else { return [] }@@ -194,15 +208,18 @@ final class ShellView: NSView {vibrant: .init(dim: t.blurDim, liftTop: t.liftActive, liftBottom: t.liftActiveBottom,dimInactive: t.blurDimInactive, liftInactive: t.liftInactive))dimLayer.opacity = Float(backdrop.dim)+ // The desktop tint stays in the tree, as in AppKit's material: at 0.05 windowed, active or not,+ // and in place of the blur in full screen. Only Reduce transparency takes it out. Inserted+ // fresh, it drew nothing until the window server had resolved it (GitHub #156). It sits under+ // the capture and the fill, so at 0.05 it doesn't change the calibrated colours.+ if let tint = desktopTintLayer {+ if reduceTransparency { tint.removeFromSuperlayer() } else if tint.superlayer == nil { backdropHost.layer?.insertSublayer(tint, at: 0) }+ tint.opacity = backdrop.source == .desktopTint ? 1 : 0.05+ }// 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() }+ if let b = backdropLayer, (backdrop.source == .blur) != (b.superlayer != nil) {+ if backdrop.source == .blur { backdropHost.layer?.insertSublayer(b, at: desktopTintLayer?.superlayer == nil ? 0 : 1) } else { b.removeFromSuperlayer() }}liftLayer.colors = [NSColor(white: 1, alpha: backdrop.liftTop).cgColor, NSColor(white: 1, alpha: backdrop.liftBottom).cgColor]CATransaction.commit()@@ -238,6 +255,7 @@ final class ShellView: NSView {vibrancy.state = .activevibrancy.isHidden = trueaddSubview(vibrancy)+ addSubview(activeAppearance)backdropHost.wantsLayer = true// A CABackdropLayer only blurs what is behind the window through Core// Animation's own filters (private CAFilter "gaussianBlur"); a CIFilter in@@ -248,9 +266,10 @@ final class ShellView: NSView {// without them the blur showed only while the window was redrawing (GitHub #37).if FeatureFlags.current.backdrop == .layer,let cls = NSClassFromString("CABackdropLayer") as? CALayer.Type,- let blur = ShellView.makeBackdropBlur(radius: 40) {+ case let filters = ShellView.makeBackdropFilters(), !filters.isEmpty {let b = cls.init()- b.filters = [blur]+ b.filters = filters+ b.setValue(ShellView.backdropScale, forKey: "scale")b.setValue(true, forKey: "windowServerAware")b.setValue("NSCGSWindowBehindWindowCaptureBackdropGroup", forKey: "groupName")// While the window server rebuilds the capture (activation, a Space switch) thediff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 116995e..b02a474 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -203,6 +203,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMNotificationCenter.default.addObserver(forName: NSApplication.didResignActiveNotification, object: nil, queue: .main) { [weak self] _ inTask { @MainActor in self?.refreshMaterialActive(); self?.sidebarUI.appActive = false }}+ shell.activeAppearance.onChange = { [weak self] in self?.refreshMaterialActive() }// Any window: key and main move between this window, its page windows and other windows.for name in [NSWindow.didBecomeKeyNotification, NSWindow.didResignKeyNotification, NSWindow.didBecomeMainNotification,NSWindow.didResignMainNotification, NSWindow.didMiniaturizeNotification, NSWindow.didDeminiaturizeNotification] {@@ -233,7 +234,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMreturn false}return SidebarBackdrop.windowActive(appActive: NSApp.isActive, miniaturized: window.isMiniaturized,- holdsKeyOrMain: holds(NSApp.keyWindow) || holds(NSApp.mainWindow))+ holdsKeyOrMain: holds(NSApp.keyWindow) || holds(NSApp.mainWindow),+ activeAppearance: shell.activeAppearance.isActive ?? false)}required init?(coder: NSCoder) { fatalError() }diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 1b05b27..438810b 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -2206,6 +2206,26 @@ Theme palettes in a hand-built space can be borrowed; only the `background` stylzoom (16/12/31 → 41/33/50 on its default theme) and steps ~2 levels when the Space settles (45/30/43 → 43/30/45), andCra does the same (189/112/120 → 216/133/137 at the start, 220/124/123 → 218/124/126 at the end), so no fullscreendifference against Arc reproduced on this Mac.+- [O] Space switches, Stage Manager and AppKit's capture settings (5 Nov 2026, issue #156 on 0.1.30; built-in XDR+ display; a probe app with a hudWindow NSVisualEffectView logging every 4 ms and on each notification: app active,+ key, main, `NSWindow._hasActiveAppearance`, the view's `_shouldUseActiveAppearance` and its layer tree; ⌃← / ⌃→+ posted as HID events). A full screen window keeps its active appearance when its Space slides away: the app resigns+ active and the window loses key and main, but `_hasActiveAppearance` and the material stay active, the desktop tint+ at opacity 1 throughout. So Arc's sidebar never leaves its active look on a ⌃← / ⌃→ round trip, while Cra's rule (app+ active and key or main) went to the flat fill and came back at `didBecomeActive`, ~4 ms after the Space change, which+ is after the slide: the reporter's lighter frames, ~5 frames past the animation. Windowed, the material goes inactive+ as the window resigns main, as before. AppKit tells its views through `-[NSView _windowChangedKeyState]`. Cra now asks+ a zero-size NSVisualEffectView that follows its window (`ActiveAppearanceProbe`) and ORs that answer into+ `SidebarBackdrop.windowActive`. The rule's own half stays, because AppKit's answer doesn't count Cra's page windows.+ Layer dump of the windowed hudWindow material: `CABackdropLayer` scale 0.125, `windowServerAware`, group+ `NSCGSWindowBehindWindowCaptureBackdropGroup`, `allowsSubstituteColor` 1, `substituteColor` nil, filters+ `sdrNormalize`, `gaussianBlur` (radius 30, normalize edges), `colorSaturate` 1.6; then the fill (0.157 grey at 0.4),+ the tone (0.08 grey, lighten) and the `CAChameleonLayer` at 0.05. Inactive it drops only the capture, the fill and+ tone go opaque, and the chameleon stays in at 0.05. Side by side over a stripe window, AppKit's settings on a bare+ layer blur like the material and Cra's full-scale 40 pt blur spread a 20 pt band about twice as wide and greyer. Cra+ now builds the capture with AppKit's settings (an eighth of the pixels for the window server to rebuild when a window+ comes back, the dropout the reporter saw out of Stage Manager on an M1) and keeps the desktop tint in the tree at 0.05+ under the capture, at 1 in full screen, out only with Reduce transparency. Stage Manager itself was not tested here.- [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).