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.

Swipe into the Library, a Spaces page that scrolls and follows the window, no scroller flash on space swipes (#77)

Victor Kildahl65d457966bb4
diff --git a/Packages/CraCore/Sources/CraCore/LibrarySwipe.swift b/Packages/CraCore/Sources/CraCore/LibrarySwipe.swift
new file mode 100644
index 0000000..920d765
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/LibrarySwipe.swift
@@ -0,0 +1,70 @@
+import CoreGraphics
+import Foundation
+
+/// Swiping into the Library: past the first space two fingers pull the Library in from the left,
+/// in the Library they push it back out. Arc 1.171 has this gesture (docs/arc-reverse-engineering.md,
+/// "Swiping into the Library"). Like Arc the sidebar widens with the reveal, from its own width to
+/// the Library's, so it lands at the Library's width with no resize after; but where Arc's Library
+/// follows the fingers at half speed, Cra's moves like a space swipe (Victor, 1 Nov 2026): the
+/// Library is the page before the first space, its right edge 1:1 under the fingers, with the space
+/// swipe's rubber band, release rule and spring.
+/// The reveal is 0 on the space, 1 with the Library in, past 1 while it rubber-bands.
+public enum LibrarySwipe {
+ /// The space swipe's settle (Dia's zero-bounce spring, perceptual duration 0.4 s).
+ public static let omega: CGFloat = 2 * .pi / 0.4
+ /// A release faster than this (pages per second) goes its way whatever the position.
+ public static let flickSpeed: CGFloat = 0.8
+
+ /// The reveal for `travel` points of finger movement (+ toward the Library) from `start`, the
+ /// Library being `width` wide; nil when a swipe that began on the space goes the other way,
+ /// toward the next space.
+ public static func reveal(from start: CGFloat, travel: CGFloat, width: CGFloat) -> CGFloat? {
+ let r = start + travel / max(1, width)
+ if r < 0 { return start == 0 ? nil : -band(-r) }
+ return r > 1 ? 1 + band(r - 1) : r
+ }
+
+ /// The space swipe's rubber band past either end: AppKit's resistance curve, halved.
+ static func band(_ x: CGFloat) -> CGFloat { (1 - 1 / (x * 0.55 + 1)) * 0.5 }
+
+ /// The sidebar's width for reveal `r`: its own `base` width on the space, the Library's
+ /// `library` width with the Library in, in proportion between, and on with the rubber band (Arc).
+ public static func sidebarWidth(reveal r: CGFloat, base: CGFloat, library: CGFloat) -> CGFloat {
+ base + (library - base) * max(0, r)
+ }
+
+ /// Where the Library (at its full width) sits for reveal `r`: in from the left, its right
+ /// edge under the fingers, then riding the sidebar's edge while it rubber-bands. The space
+ /// sits right after it, like the next page.
+ public static func libraryX(reveal r: CGFloat, base: CGFloat, library: CGFloat) -> CGFloat {
+ r <= 1 ? (r - 1) * library : sidebarWidth(reveal: r, base: base, library: library) - library
+ }
+ public static func spaceX(reveal r: CGFloat, base: CGFloat, library: CGFloat) -> CGFloat {
+ libraryX(reveal: r, base: base, library: library) + library
+ }
+
+ /// Where a released swipe settles: a flick goes its way, else past halfway opens.
+ /// `velocity` is in reveals per second, + toward the Library.
+ public static func target(reveal r: CGFloat, velocity: CGFloat) -> CGFloat {
+ abs(velocity) > flickSpeed ? (velocity > 0 ? 1 : 0) : (r > 0.5 ? 1 : 0)
+ }
+
+ /// Release velocity in reveals per second from the last moments' `(time, delta)` samples.
+ public static func velocity(samples: [(time: TimeInterval, dx: CGFloat)], width: CGFloat) -> CGFloat {
+ guard let first = samples.first, let last = samples.last, last.time - first.time > 0.004 else { return 0 }
+ return samples.reduce(0) { $0 + $1.dx } / CGFloat(last.time - first.time) / max(1, width)
+ }
+
+ /// The settle `t` seconds after release from reveal `r` moving at `velocity` reveals per second.
+ public static func settle(from r: CGFloat, velocity: CGFloat, to target: CGFloat, at t: CGFloat) -> CGFloat {
+ let x0 = r - target
+ return target + (x0 + (velocity + omega * x0) * t) * exp(-omega * t)
+ }
+
+ /// The settle has come to rest: within a quarter point of `target` and nearly still.
+ public static func isSettled(from r: CGFloat, velocity: CGFloat, to target: CGFloat, at t: CGFloat, width: CGFloat) -> Bool {
+ let x = settle(from: r, velocity: velocity, to: target, at: t)
+ let speed = abs(x - settle(from: r, velocity: velocity, to: target, at: t - 0.01)) * 100 * width
+ return abs(x - target) * width < 0.25 && speed < 5
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/LibrarySwipeTests.swift b/Packages/CraCore/Tests/CraCoreTests/LibrarySwipeTests.swift
new file mode 100644
index 0000000..244c8a5
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/LibrarySwipeTests.swift
@@ -0,0 +1,67 @@
+import CoreGraphics
+import CraCore
+import Testing
+
+/// The swipe into the Library moves like a space swipe: the Library is the page before the first space.
+struct LibrarySwipeTests {
+ /// The Library's right edge moves with the fingers, point for point.
+ @Test func followsTheFingersOneToOne() {
+ #expect(LibrarySwipe.reveal(from: 0, travel: 208.5, width: 417) == 0.5)
+ #expect(LibrarySwipe.reveal(from: 1, travel: -208.5, width: 417) == 0.5)
+ #expect(LibrarySwipe.libraryX(reveal: 0.5, base: 347, library: 417) == -208.5)
+ #expect(LibrarySwipe.spaceX(reveal: 0.5, base: 347, library: 417) == 208.5)
+ }
+
+ /// Like Arc, the sidebar widens with the reveal and lands at the Library's width.
+ @Test func sidebarWidensWithTheReveal() {
+ #expect(LibrarySwipe.sidebarWidth(reveal: 0, base: 260, library: 330) == 260)
+ #expect(LibrarySwipe.sidebarWidth(reveal: 0.5, base: 260, library: 330) == 295)
+ #expect(LibrarySwipe.sidebarWidth(reveal: 1, base: 260, library: 1044) == 1044)
+ #expect(LibrarySwipe.sidebarWidth(reveal: -0.2, base: 260, library: 330) == 260)
+ // Rubber-banding past, it keeps widening and the Library rides its edge.
+ let w = LibrarySwipe.sidebarWidth(reveal: 1.1, base: 347, library: 417)
+ #expect(w > 417)
+ #expect(LibrarySwipe.libraryX(reveal: 1.1, base: 347, library: 417) == w - 417)
+ }
+
+ @Test func goingTheOtherWayFromTheSpaceIsASpaceSwipe() {
+ #expect(LibrarySwipe.reveal(from: 0, travel: -10, width: 347) == nil)
+ }
+
+ /// Past either end it gives way like the space swipe: never more than half a page.
+ @Test func rubberBandsPastEitherEnd() {
+ let past = LibrarySwipe.reveal(from: 0, travel: 347 * 3, width: 347)!
+ #expect(past > 1 && past < 1.5)
+ let out = LibrarySwipe.reveal(from: 1, travel: -417 * 3, width: 417)!
+ #expect(out < 0 && out > -0.5)
+ #expect(LibrarySwipe.reveal(from: 0, travel: 347 * 1.2, width: 347)! < 1.2)
+ }
+
+ @Test(arguments: [
+ (0.4, 0.0, 0.0), (0.6, 0.0, 1.0),
+ (0.2, 1.0, 1.0), (0.8, -1.0, 0.0), (0.4, 0.5, 0.0),
+ ])
+ func whereItSettles(reveal: Double, velocity: Double, target: Double) {
+ #expect(LibrarySwipe.target(reveal: CGFloat(reveal), velocity: CGFloat(velocity)) == CGFloat(target))
+ }
+
+ @Test func velocityFromRecentSamples() {
+ let samples: [(time: Double, dx: CGFloat)] = [(1.00, 10), (1.02, 10), (1.04, 10)]
+ #expect(abs(LibrarySwipe.velocity(samples: samples, width: 375) - 2) < 0.001)
+ #expect(LibrarySwipe.velocity(samples: [(1, 5)], width: 375) == 0)
+ }
+
+ /// The space swipe's spring: critically damped, so it never overshoots, and it picks up
+ /// the release speed.
+ @Test func settlesLikeASpaceSwipe() {
+ var previous: CGFloat = 0.6
+ for i in 1...60 {
+ let x = LibrarySwipe.settle(from: 0.6, velocity: 0, to: 1, at: CGFloat(i) / 120)
+ #expect(x <= 1 && x >= previous)
+ previous = x
+ }
+ #expect(LibrarySwipe.settle(from: 0.6, velocity: 3, to: 1, at: 0.02) > LibrarySwipe.settle(from: 0.6, velocity: 0, to: 1, at: 0.02))
+ #expect(!LibrarySwipe.isSettled(from: 0.6, velocity: 0, to: 1, at: 0.05, width: 347))
+ #expect(LibrarySwipe.isSettled(from: 0.6, velocity: 0, to: 1, at: 1, width: 347))
+ }
+}
diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swift
index 62b993e..6927720 100644
--- a/Sources/Cra/UI/ShellView.swift
+++ b/Sources/Cra/UI/ShellView.swift
@@ -636,6 +636,20 @@ final class ShellView: NSView {
}
/// Animate between sidebar states by interpolating frames.
+ /// While the sidebar's width follows the fingers (a Library swipe) the pages keep their size
+ /// and their cards move over them: resizing a page makes Chromium lay it out again, and once
+ /// per event that stalled the swipe. `thawPages` gives them the size they end up with, once.
+ func freezePages() {
+ for c in paneCards where c.frozenWebBounds == nil { c.frozenWebBounds = NSRect(origin: .zero, size: c.webArea.bounds.size) }
+ }
+
+ func thawPages() {
+ guard paneCards.contains(where: { $0.frozenWebBounds != nil }) else { return }
+ for c in paneCards { c.frozenWebBounds = nil }
+ needsLayout = true
+ layoutSubtreeIfNeeded()
+ }
+
func animateSidebar(visible: Bool, floating: Bool, fullscreen: Bool, width: CGFloat, duration: TimeInterval = 0.085) {
let target = frames(sidebarVisible: visible, floating: floating, fullscreen: fullscreen, width: width)
// Size the pages for their destination once, up front; the cards then just slide over them.
diff --git a/Sources/Cra/UI/Sidebar/LibraryView.swift b/Sources/Cra/UI/Sidebar/LibraryView.swift
index aeb26ed..4856aba 100644
--- a/Sources/Cra/UI/Sidebar/LibraryView.swift
+++ b/Sources/Cra/UI/Sidebar/LibraryView.swift
@@ -103,9 +103,12 @@ final class LibraryView: NSView {
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
- list.focusSearch()
+ // A swipe brings the Library in under the fingers; its search takes the keys once it lands.
+ if ui.libraryReveal == nil { list.focusSearch() }
}
+ func focusSearch() { list.focusSearch() }
+
override func cancelOperation(_ sender: Any?) { actions.closeLibrary() }
override func layout() {
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
index 52fdd86..f23b8cf 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
@@ -41,6 +41,7 @@ final class SidebarView: NSView {
for v in [topBar, pager, player, trayHost, bannerHost, dock] as [NSView] { tabs.addSubview(v) }
addSubview(tabs)
player.onCountChange = { [weak self] in self?.needsLayout = true }
+ ui.observeLibraryReveal { [weak self] in self?.applyLibraryReveal() }
observe()
}
@@ -100,16 +101,11 @@ final class SidebarView: NSView {
/// The Library takes over the column: in from a little to the left, out to the left past its
/// rail while the tab list fades back in.
private func showLibrary(_ page: LibraryPage?) {
- guard page != shownLibrary else { return }
+ guard page != shownLibrary, ui.libraryReveal == nil else { return }
let opening = shownLibrary == nil && page != nil
shownLibrary = page
if let page {
- let host = libraryHost ?? {
- let h = LibraryView(page: page, palette: palette, store: store, ui: ui, actions: actions, favicons: favicons)
- addSubview(h)
- libraryHost = h
- return h
- }()
+ let host = libraryHost ?? makeLibraryHost(page)
host.page = page
host.frame = bounds
if opening {
@@ -137,6 +133,52 @@ final class SidebarView: NSView {
}
}
+ private func makeLibraryHost(_ page: LibraryPage) -> LibraryView {
+ let h = LibraryView(page: page, palette: palette, store: store, ui: ui, actions: actions, favicons: favicons)
+ addSubview(h)
+ libraryHost = h
+ return h
+ }
+
+ /// A swipe's reveal `r` (SidebarUIState.libraryReveal): the Library is the page before the
+ /// first space and the two slide side by side like space pages while the sidebar widens under
+ /// them (LibrarySwipe). Each keeps its own width, so neither lays out again as it moves. Once
+ /// the swipe has landed the window controller has set the page, and the column takes that state.
+ private func applyLibraryReveal() {
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ defer { CATransaction.commit() }
+ guard let r = ui.libraryReveal else {
+ layer?.masksToBounds = false
+ tabs.setFrameOrigin(.zero)
+ if let page = ui.libraryPage {
+ let host = libraryHost ?? makeLibraryHost(page)
+ host.page = page
+ host.alphaValue = 1
+ host.frame = bounds
+ tabs.alphaValue = 0
+ if shownLibrary != page { host.focusSearch() }
+ shownLibrary = page
+ } else {
+ libraryHost?.removeFromSuperview()
+ libraryHost = nil
+ tabs.alphaValue = 1
+ shownLibrary = nil
+ }
+ return
+ }
+ let page = ui.libraryPage ?? ui.libraryRevealPage
+ let host = libraryHost ?? makeLibraryHost(page)
+ host.page = page
+ host.alphaValue = 1
+ tabs.alphaValue = 1
+ // Neither page shows outside the column, under the card's inset.
+ layer?.masksToBounds = true
+ let base = ui.libraryRevealBase, library = ui.libraryRevealWidth
+ host.frame = NSRect(x: LibrarySwipe.libraryX(reveal: r, base: base, library: library), y: 0, width: library, height: bounds.height)
+ tabs.frame = NSRect(x: LibrarySwipe.spaceX(reveal: r, base: base, library: library), y: 0, width: base, height: bounds.height)
+ }
+
override func hitTest(_ point: NSPoint) -> NSView? {
if let host = libraryHost {
// `point` is in the superview's space; the host sits in this (flipped) view's.
@@ -148,9 +190,14 @@ final class SidebarView: NSView {
override func layout() {
super.layout()
- let b = bounds
- tabs.frame = b
- libraryHost?.frame = b
+ if ui.libraryReveal == nil {
+ tabs.frame = bounds
+ libraryHost?.frame = bounds
+ } else {
+ applyLibraryReveal()
+ }
+ // The column's own size: during a Library swipe it keeps the sidebar's width as that widens.
+ let b = tabs.bounds
let th = topBar.preferredHeight
topBar.frame = NSRect(x: 0, y: 0, width: b.width, height: th)
// Arc's list viewport ends 50 pt above the window bottom; the dock sits centred in that band.
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
index 84e39b4..5fce0fb 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
@@ -1053,11 +1053,16 @@ enum SidebarListMetrics {
/// The list's scroll view. Space swipes are read by the window controller's scroll monitor,
/// which has to see every event of a gesture: responsive scrolling takes a gesture's events
/// off that path once it starts over the list, and a horizontal gesture never scrolls a list.
+/// It goes on up instead: on the Library's Spaces page the cards scroll sideways under the
+/// fingers, or under Shift and a mouse wheel, over a card's list too (Arc 1.171).
final class SpaceListScrollView: NSScrollView {
override class var isCompatibleWithResponsiveScrolling: Bool { false }
override func scrollWheel(with event: NSEvent) {
- if event.hasPreciseScrollingDeltas, event.momentumPhase.isEmpty, abs(event.scrollingDeltaX) > abs(event.scrollingDeltaY) { return }
+ if abs(event.scrollingDeltaX) > abs(event.scrollingDeltaY) {
+ nextResponder?.scrollWheel(with: event)
+ return
+ }
super.scrollWheel(with: event)
}
}
@@ -1074,6 +1079,21 @@ final class SpaceListScrollView: NSScrollView {
final class SidebarScroller: NSScroller {
var isDarkTheme = true { didSet { if isDarkTheme != oldValue { needsDisplay = true } } }
+ /// AppKit flashes an overlay knob as soon as two fingers touch the trackpad over a list, and
+ /// a swipe between spaces starts like that: the window's scroll monitor hides the knob until
+ /// a gesture turns out to scroll the list (the legacy scroller always shows).
+ static var hiddenForSwipe = false {
+ didSet { if hiddenForSwipe != oldValue { for s in all.allObjects { s.needsDisplay = true } } }
+ }
+ private static let all = NSHashTable<SidebarScroller>.weakObjects()
+
+ override init(frame: NSRect) {
+ super.init(frame: frame)
+ Self.all.add(self)
+ }
+
+ required init?(coder: NSCoder) { fatalError() }
+
override class var isCompatibleWithOverlayScrollers: Bool { true }
override class func scrollerWidth(for controlSize: NSControl.ControlSize, scrollerStyle: NSScroller.Style) -> CGFloat { 10 }
@@ -1088,6 +1108,7 @@ final class SidebarScroller: NSScroller {
NSBezierPath(roundedRect: backingAlignedRect(r, options: .alignAllEdgesNearest), xRadius: 2.5, yRadius: 2.5).fill()
return
}
+ guard !Self.hiddenForSwipe else { return }
let r = NSRect(x: bounds.maxX - 7, y: knob.minY + 2, width: 4, height: max(0, knob.height - 4))
(isDarkTheme ? NSColor.white.withAlphaComponent(0.49) : NSColor.black.withAlphaComponent(0.3)).setFill()
NSBezierPath(roundedRect: r, xRadius: 2, yRadius: 2).fill()
diff --git a/Sources/Cra/UI/Sidebar/SpacesManagerView.swift b/Sources/Cra/UI/Sidebar/SpacesManagerView.swift
index e6f27bd..e63e898 100644
--- a/Sources/Cra/UI/Sidebar/SpacesManagerView.swift
+++ b/Sources/Cra/UI/Sidebar/SpacesManagerView.swift
@@ -14,6 +14,8 @@ enum SpacesManagerMetrics {
static let plus: CGFloat = 29
static let plusGap: CGFloat = 34
static let trail: CGFloat = 37.5
+ /// What the page keeps beside the Spaces page, whatever the window's width (Arc 1.171).
+ static let pageRoom: CGFloat = 56
/// The Library's width on this page: Arc widens the sidebar to fit every card.
static func width(spaces n: Int) -> CGFloat {
@@ -27,7 +29,7 @@ final class SpacesManagerView: NSView {
private let ui: SidebarUIState
private let actions: SidebarActions
private let favicons: FaviconCache
- private let scroll = NSScrollView()
+ private let scroll = SpacesStripScrollView()
private let document = FlippedView()
private var cards: [UUID: SpaceManagerCard] = [:]
private var order: [UUID] = []
@@ -143,7 +145,7 @@ private final class SpaceManagerCard: NSView {
private lazy var brush = SidebarGlyphButton(symbol: "paintbrush.pointed.fill", size: 26, iconSize: 13, help: "Edit Theme Color",
colors: colors) { [weak self] in
guard let self, let s = self.store.space(self.spaceID) else { return }
- self.actions.editSpaceTheme(s)
+ self.actions.editSpaceThemeBeside(s, self)
}
/// Dragging it carries the card along the row; where it is let go is the space's new place.
private let move = SpaceMoveHandle()
@@ -268,3 +270,10 @@ private final class SpaceMoveHandle: NSView {
onEnd()
}
}
+
+/// The cards' row. Like the tab lists (SpaceListScrollView) it stays off responsive scrolling,
+/// which would take a gesture's events past the window's scroll monitor once it starts here:
+/// a swipe that starts with the cards at their end has to reach the monitor to leave the Library.
+final class SpacesStripScrollView: NSScrollView {
+ override class var isCompatibleWithResponsiveScrolling: Bool { false }
+}
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index effb01e..1e2fd5c 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -49,6 +49,16 @@ final class SidebarUIState {
/// Library per window and reopens it on the page last shown).
var libraryPage: LibraryPage?
@ObservationIgnored var lastLibraryPage: LibraryPage = .downloads
+ /// A two-finger swipe pulling the Library in from the left of the first space, or back out
+ /// (Arc 1.171): how much of it shows, 0 the space, 1 the Library, past 1 while it
+ /// rubber-bands. nil when no such swipe is tracking or settling.
+ @ObservationIgnored var libraryReveal: CGFloat? { didSet { for f in libraryRevealObservers { f() } } }
+ /// The page the swipe brings in, the Library's width on it and the sidebar's own width.
+ @ObservationIgnored var libraryRevealPage: LibraryPage = .downloads
+ @ObservationIgnored var libraryRevealWidth: CGFloat = 0
+ @ObservationIgnored var libraryRevealBase: CGFloat = 0
+ @ObservationIgnored private var libraryRevealObservers: [() -> Void] = []
+ func observeLibraryReveal(_ f: @escaping () -> Void) { libraryRevealObservers.append(f) }
/// Tab chosen from the keyboard in another space (the tab switcher); Arc draws its
/// yellow/black dashed ring around it until the mouse picks another tab.
var keyboardFocusID: UUID?
@@ -196,6 +206,8 @@ final class SidebarActions {
/// the space, the Library's Spaces page, and deleting this space (not the focused one).
var changeSpaceIcon: (Space, NSView) -> Void = { _, _ in }
var editSpaceTheme: (Space) -> Void = { _ in }
+ /// The theme editor beside a Spaces page card.
+ var editSpaceThemeBeside: (Space, NSView) -> Void = { _, _ in }
var newProfile: (UUID) -> Void = { _ in }
var manageSpaces: () -> Void = {}
var deleteSpace: (Space) -> Void = { _ in }
diff --git a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
index 91e68ce..6d956b0 100644
--- a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
@@ -34,7 +34,7 @@ extension MainWindowController {
/// Edit Theme Color…: Arc's editor in a panel against the sidebar's edge at the window's top,
/// applying every change at once. Escape or a click outside closes it.
- func showSpaceStyleEditor(space: Space) {
+ func showSpaceStyleEditor(space: Space, beside anchor: NSView? = nil) {
guard let window else { return }
if let open = window.childWindows?.first(where: { $0 is StyleEditorPanel }) { open.close() }
let store = self.store, id = space.id
@@ -45,7 +45,9 @@ extension MainWindowController {
}
// The card sits 12 pt into its 382 × 534 pt window (19 pt above the bottom), room for the shadow.
let size = NSSize(width: 382, height: 534)
- let x = (window.frame.minX + (shell.sidebarVisible ? shell.sidebarWidth : 0)).rounded()
+ // From a Spaces page card Arc puts it flush with the card's right edge.
+ let x = (anchor.flatMap { v in v.window.map { $0.convertToScreen(v.convert(v.bounds, to: nil)).maxX } }
+ ?? window.frame.minX + (shell.sidebarVisible ? shell.sidebarWidth : 0)).rounded()
let panel = StyleEditorPanel(contentRect: NSRect(x: x, y: window.frame.maxY - size.height, width: size.width, height: size.height))
let host = NSHostingView(rootView: editor.shadow(color: .black.opacity(0.3), radius: 10, y: 4)
.padding(.top, 12).padding(.horizontal, 13.5).padding(.bottom, 19))
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 7e99f06..76860d6 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -31,6 +31,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
private var swipeTravel: CGFloat = 0
private var swipeSamples: [(time: TimeInterval, dx: CGFloat)] = []
private var swipeDetent = 0
+ /// The Library's reveal a swipe started from: 0 on the first space, 1 in the Library; nil
+ /// when the swipe can only page between spaces.
+ private var librarySwipeFrom: CGFloat?
+ private var librarySettleSpring: (start: CFTimeInterval, from: CGFloat, velocity: CGFloat, target: CGFloat)?
+ private var librarySettleLink: CADisplayLink?
+ /// Shows the lists' overlay knob again once a swipe's scroller flash has faded.
+ private var swipeKnobReveal: DispatchWorkItem?
private var enteredFullscreenForContent = false
/// The tab whose page (a video) is in element fullscreen.
private var contentFullscreenTab: UUID?
@@ -204,6 +211,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
sidebarActions.editSpace = { [weak self] s in self?.showSpaceEditor(space: s) }
sidebarActions.changeSpaceIcon = { [weak self] s, anchor in self?.showSpaceIconPicker(space: s, anchor: anchor) }
sidebarActions.editSpaceTheme = { [weak self] s in self?.showSpaceStyleEditor(space: s) }
+ sidebarActions.editSpaceThemeBeside = { [weak self] s, card in self?.showSpaceStyleEditor(space: s, beside: card) }
sidebarActions.newProfile = { [weak self] id in self?.showNewProfileDialog(forSpace: id) }
sidebarActions.manageSpaces = { [weak self] in self?.showManageSpaces() }
sidebarActions.deleteSpace = { [weak self] s in self?.app.confirmDeleteSpace(s) }
@@ -1435,12 +1443,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
/// The sidebar's width with the Library in it: 70 pt wider for the rail, or on the Spaces page
- /// wide enough for every space's card (Arc), leaving the page at least 320 pt.
+ /// wide enough for every space's card, leaving the page 56 pt (Arc 1.171; the cards scroll
+ /// sideways when they don't fit).
private func libraryWidth(_ page: LibraryPage) -> CGFloat {
let base = CGFloat(store.prefs.sidebarWidth) + LibraryMetrics.extraWidth
guard page == .spaces else { return base }
let n = store.orderedSpaces.filter { !store.isIncognito(space: $0.id) }.count
- let room = (window?.frame.width ?? 1280) - 320
+ let room = (window?.frame.width ?? 1280) - SpacesManagerMetrics.pageRoom
return max(base, min(SpacesManagerMetrics.width(spaces: n), room))
}
@@ -1534,6 +1543,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
// phase switch below; a stale .horizontal would eat the page's momentum and
// scrolling would stop dead the moment the fingers lift.
if event.phase == .began || event.phase == .mayBegin { self.swipeAxis = .vertical }
+ // A mouse wheel only ever scrolls.
+ if !event.hasPreciseScrollingDeltas { self.showListKnobs() }
// The momentum tail of a space swipe belongs to the swipe, not the tab list.
if !event.momentumPhase.isEmpty { return self.swipeAxis == .horizontal ? nil : event }
// The floating sidebar is in its own panel (FloatingSidebarController): its swipes
@@ -1543,11 +1554,16 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
event.hasPreciseScrollingDeltas else { return event }
switch event.phase {
case .mayBegin, .began:
- // The Library's lists don't page between spaces.
- let overSidebar = (self.shell.sidebarVisible || self.shell.floatingSidebar) && event.window === host.window
+ let inSidebar = (self.shell.sidebarVisible || self.shell.floatingSidebar) && event.window === host.window
&& host.bounds.contains(host.convert(event.locationInWindow, from: nil))
- && self.sidebarUI.libraryPage == nil
+ // In the Library a swipe can only take it back out; on the Spaces page the cards
+ // scroll first, and only a swipe that starts with them at their end leaves (Arc).
+ var overSidebar = inSidebar
+ if inSidebar, let page = self.sidebarUI.libraryPage {
+ overSidebar = page != .spaces || self.spacesStripAtEnd(event)
+ }
self.swipeAxis = overSidebar ? .undecided : .vertical
+ if overSidebar { self.hideListKnobs() }
self.swipeX = 0
self.swipeY = 0
return event
@@ -1559,8 +1575,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
self.swipeX += event.scrollingDeltaX
self.swipeY += event.scrollingDeltaY
guard max(abs(self.swipeX), abs(self.swipeY)) > 6 else { return event }
- guard abs(self.swipeX) > abs(self.swipeY) * 1.2, self.store.spaceOrder.count > 1, !self.isIncognito else {
+ // One space still swipes into the Library.
+ guard abs(self.swipeX) > abs(self.swipeY) * 1.2, !self.isIncognito,
+ self.store.spaceOrder.count > 1 || !self.shell.floatingSidebar,
+ // At the Spaces page's end a swipe back along the cards scrolls them.
+ !(self.sidebarUI.libraryPage == .spaces && self.swipeX > 0) else {
self.swipeAxis = .vertical
+ self.showListKnobs()
return event
}
self.swipeAxis = .horizontal
@@ -1573,6 +1594,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return nil
}
case .ended, .cancelled:
+ if self.swipeAxis != .vertical { self.showListKnobs(after: 1) }
guard self.swipeAxis == .horizontal else { return event }
self.endSpaceSwipe()
return nil
@@ -1582,11 +1604,144 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
}
+ private func hideListKnobs() {
+ swipeKnobReveal?.cancel()
+ swipeKnobReveal = nil
+ SidebarScroller.hiddenForSwipe = true
+ }
+
+ /// After `delay` seconds: by then the knob AppKit flashed at the touch has faded out.
+ private func showListKnobs(after delay: TimeInterval = 0) {
+ swipeKnobReveal?.cancel()
+ guard delay > 0 else { SidebarScroller.hiddenForSwipe = false; return }
+ let work = DispatchWorkItem { SidebarScroller.hiddenForSwipe = false }
+ swipeKnobReveal = work
+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: work)
+ }
+
private func beginSpaceSwipe() {
swipeTravel = 0
swipeSamples = []
swipeDetent = 0
sidebarUI.spaceSettleVelocity = 0
+ // A swipe during a Library settle picks it up where it shows.
+ stopLibrarySettle()
+ let shown = sidebarUI.libraryReveal
+ librarySwipeFrom = nil
+ guard !shell.floatingSidebar, shell.sidebarVisible || sidebarUI.libraryPage != nil else { return }
+ if let page = sidebarUI.libraryPage {
+ prepareLibraryReveal(page)
+ librarySwipeFrom = shown ?? 1
+ } else if store.spaceOrder.first == focusedSpaceID {
+ prepareLibraryReveal(sidebarUI.lastLibraryPage)
+ librarySwipeFrom = shown ?? 0
+ }
+ }
+
+ // MARK: Swiping into the Library (LibrarySwipe)
+
+ private func prepareLibraryReveal(_ page: LibraryPage) {
+ sidebarUI.libraryRevealPage = page
+ sidebarUI.libraryRevealWidth = libraryWidth(page)
+ sidebarUI.libraryRevealBase = CGFloat(store.prefs.sidebarWidth)
+ }
+
+ /// Shows reveal `r`, and like Arc the sidebar widens with it, from its own width to the
+ /// Library's, so the Library lands at its width with nothing left to resize.
+ private func setLibraryReveal(_ r: CGFloat) {
+ // Embedded pages keep their size under their cards until the swipe lands.
+ if sidebarUI.libraryReveal == nil, EmbeddedPages.isEnabled { shell.freezePages() }
+ sidebarUI.libraryReveal = r
+ shell.sidebarWidth = LibrarySwipe.sidebarWidth(reveal: r, base: sidebarUI.libraryRevealBase, library: sidebarUI.libraryRevealWidth)
+ }
+
+ /// Past the first space the fingers pull the Library in like the page before it; in the
+ /// Library they push it back out. Returns false when the swipe is one between spaces.
+ private func trackLibrarySwipe() -> Bool {
+ guard let from = librarySwipeFrom else { return false }
+ guard let r = LibrarySwipe.reveal(from: from, travel: swipeTravel, width: sidebarUI.libraryRevealWidth) else {
+ // Back on the space and beyond: the swipe heads for the next space instead.
+ if sidebarUI.libraryReveal != nil {
+ setLibraryReveal(0)
+ sidebarUI.libraryReveal = nil
+ shell.thawPages()
+ }
+ return false
+ }
+ if sidebarUI.spaceSwipe != 0 { sidebarUI.spaceSwipe = 0 }
+ setLibraryReveal(r)
+ return true
+ }
+
+ /// The release settles on the space swipe's spring, frame by frame on the display link.
+ private func endLibrarySwipe(_ r: CGFloat) {
+ librarySwipeFrom = nil
+ let width = sidebarUI.libraryRevealWidth
+ let velocity = LibrarySwipe.velocity(samples: swipeSamples, width: width)
+ let target = LibrarySwipe.target(reveal: r, velocity: velocity)
+ librarySettleSpring = (start: CACurrentMediaTime(), from: r, velocity: velocity, target: target)
+ if librarySettleLink == nil {
+ let link = shell.displayLink(target: self, selector: #selector(stepLibrarySettle))
+ link.add(to: .main, forMode: .common)
+ librarySettleLink = link
+ }
+ }
+
+ @objc private func stepLibrarySettle(_ link: CADisplayLink) {
+ guard let s = librarySettleSpring else { return stopLibrarySettle() }
+ let t = CGFloat(link.targetTimestamp - s.start)
+ if LibrarySwipe.isSettled(from: s.from, velocity: s.velocity, to: s.target, at: t, width: sidebarUI.libraryRevealWidth) {
+ stopLibrarySettle()
+ finishLibrarySwipe(at: s.target)
+ } else {
+ setLibraryReveal(LibrarySwipe.settle(from: s.from, velocity: s.velocity, to: s.target, at: t))
+ }
+ }
+
+ private func stopLibrarySettle() {
+ librarySettleSpring = nil
+ librarySettleLink?.invalidate()
+ librarySettleLink = nil
+ }
+
+ /// Landed: the window is in the Library or on the space, at the width the swipe ends on.
+ private func finishLibrarySwipe(at target: CGFloat) {
+ var instant = Transaction()
+ instant.disablesAnimations = true
+ let width: CGFloat
+ if target >= 1 {
+ let page = sidebarUI.libraryPage ?? sidebarUI.libraryRevealPage
+ if sidebarUI.libraryPage == nil {
+ sidebarUI.lastLibraryPage = page
+ sidebarUI.downloadsListOpen = false
+ commandBar.close()
+ shell.sidebarResizable = false
+ withTransaction(instant) { sidebarUI.libraryPage = page }
+ window?.makeKey()
+ }
+ width = libraryWidth(page)
+ } else {
+ if sidebarUI.libraryPage != nil {
+ withTransaction(instant) { sidebarUI.libraryPage = nil }
+ shell.sidebarResizable = true
+ currentBrowser?.setFocused(true)
+ }
+ width = CGFloat(store.prefs.sidebarWidth)
+ }
+ sidebarUI.libraryReveal = nil
+ shell.sidebarWidth = width
+ shell.thawPages()
+ }
+
+ /// The Spaces page's cards under the pointer are scrolled to their end (or there are none).
+ private func spacesStripAtEnd(_ event: NSEvent) -> Bool {
+ guard let root = shell.sidebarHost.window?.contentView?.superview else { return false }
+ var v = root.hitTest(event.locationInWindow)
+ while let view = v, !(view is NSScrollView && (view as? NSScrollView)?.hasHorizontalScroller == true) { v = view.superview }
+ // Arc ignores a swipe over the Library's rail.
+ guard let strip = v as? NSScrollView else { return false }
+ let clip = strip.contentView
+ return clip.bounds.minX >= (strip.documentView?.frame.width ?? 0) - clip.bounds.width - 1
}
/// A space swipe of `steps` trackpad samples `dx` apart, 8 ms apart (cra://debug?swipe=).
@@ -1605,6 +1760,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
swipeTravel += dx
swipeSamples.append((time, dx))
swipeSamples.removeAll { time - $0.time > 0.08 }
+ if trackLibrarySwipe() { return }
let index = CGFloat(store.spaceOrder.firstIndex(of: focusedSpaceID) ?? 0)
let first = -index, last = CGFloat(store.spaceOrder.count - 1) - index
// Content follows the fingers (natural scrolling: fingers left = next space).
@@ -1624,6 +1780,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
private func endSpaceSwipe() {
HitchMonitor.mark("swipe-lift")
+ if let r = sidebarUI.libraryReveal, librarySwipeFrom != nil { return endLibrarySwipe(r) }
+ librarySwipeFrom = nil
let width = max(1, shell.sidebarWidth)
let pages = sidebarUI.spaceSwipe
let span = (swipeSamples.last?.time ?? 0) - (swipeSamples.first?.time ?? 0)
@@ -2098,6 +2256,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
func windowDidResize(_ notification: Notification) {
guard (notification.object as? NSWindow) === window else { return }
+ // Arc's Spaces page keeps the page its 56 pt while the window resizes.
+ if sidebarUI.libraryPage == .spaces, sidebarUI.libraryReveal == nil { shell.sidebarWidth = libraryWidth(.spaces) }
shell.needsLayout = true
browsers.layoutVisible()
if commandBar.isOpen { positionCommandPanel() }
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 536431c..1f59bde 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -1966,3 +1966,81 @@ are disabled then).
(example.org), magnifier for a search row ("hello world", "x", "youtulocalhost:3000"). ⌘L untouched or
emptied: the page's favicon (GitHub), a globe on a page without one (example.com). ⌘T empty: magnifier,
though its top row is a tab with a favicon. Cra: CommandBarGlyph; `info.circle` is gone.
+
+## Swiping into the Library and the Spaces page overflow (Arc 1.171, 1 Nov 2026)
+
+Offline fake-home Arc (8 hand-built spaces, network denied), 1280×1084 then 1100×1084 pt window on the 2x display.
+Swipes were synthesized as HID pixel scroll events (phases began/changed/ended, ~8–10 ms apart) over the sidebar;
+a probe app confirmed such an event arrives as `scrollingDeltaX` = the posted value, precise, so "px" below means
+scrollingDeltaX points. Recorded app-only at 120 fps; positions from 1-px row crops (card edge, sidebar/page edge),
+curves fitted per frame. "p" = Library reveal progress, 0 = space, 1 = Library open.
+
+**Swipe into the Library**
+- [O static] `ARCUI.PageSwipeController` {pages: [Page {identifier, width}], trackingState {isTracking,
+ isAnimating}, pageOrigins, presentationAdoptionRange, settlingAnimationSession, SettlingAnimation {fromPosition,
+ targetPosition, positions, keyTimes, duration} (a sampled keyframe settle), PagingPosition {floorPageID,
+ ceilPageID, progress}, nonGesturalScrollState {cumulativeDistance, lastEventTime, lastTriggerTime},
+ performsPageDetentHaptics}. The Library is a page before the first space, with its own width.
+- [O] On the first space, fingers moving right (positive scrollingDeltaX) pull the Library in; on any other space
+ the same gesture goes to the previous space. Fingers moving left inside the Library take it back out. Only over
+ the sidebar (the page area was not tried).
+- [O] Tracking is linear: the Library content slides in from the left as one piece (rail + list, full opacity),
+ its offset = p × Library width, p ≈ px / 834 (so 0.50 pt per px for the 417 pt Library, ~1.2–1.3 pt per px for a
+ 1044 pt Spaces page; measured 1/834, 1/870, 1/808). A space-to-space swipe measured 0.49 pt per px (one take).
+- [O] The sidebar widens during the drag, not at commit: width = 347 + (Lib − 347) × p (347→417 at p 1; 1044 pt
+ for a Spaces page), the web page column shrinking with it. Library open → swipe out mirrors it exactly.
+- [O] The space's own content fades, alpha ≈ max(0, 1 − 2p) (row contrast 1.00/0.60/0.29/0.08/0 at p 0/0.2/0.36/
+ 0.46/0.5), and shrinks a little: scale ≈ 1 − 0.1 p about a point near (417 pt, window mid-height) [I, fitted from
+ the selected row, favourites card and traffic-light positions]. The traffic lights travel with that content and
+ are gone mid-swipe; they reappear on the Library. No window tint/background change: the Library sits on the
+ space's own theme.
+- [O] Commit, slow release (no velocity): p > 0.5. 412 px (p 0.494) snaps back, 424 px (0.508) opens; the same 0.5
+ on the way out (400 px stays, 440 px leaves); toward a 1044 pt Spaces page 400 px stays, 460 px opens.
+- [O] Commit with velocity, 417 pt Library: any release still moving opens it: 80 px at ~200 px/s, 30 px at
+ ~1250 px/s, 240 px with a 60 ms stop before lifting; a 150 ms stop (240 px) snaps back. Toward a 1044 pt Spaces
+ page flicks of 80, 180 and 300 px at ~3750 px/s all snapped back [U why: velocity projection apparently in points].
+- [O] Settle (open, cancel, and close alike): critically damped spring, ω ≈ 30.6 rad/s (ζ 0.96–1.0, no overshoot),
+ i.e. stiffness ≈ 935, damping ≈ 61, mass 1 (SwiftUI `.spring(response: 0.205, dampingFraction: 1)`), within
+ 0.2–0.25 px rms; ~0.2 s to within 1 %, ~0.27 s to rest. It starts from the release velocity: a 300 px/s-ish
+ release starts gently, a flick (fit v0 = 25 × displacement/s) leaves at once. Cancel = same spring back to p 0.
+- [O] Rubber band past the Library (fingers right while it is open): the whole Library moves right at ~0.07 pt per
+ px (300 px → 20.5 pt; ~0.14 of the unbanded 0.5, nearly linear over that range, fits D(1 − 1/(0.15x/D + 1)),
+ D 215, x = 0.5 px), the sidebar keeps widening by the same formula (p > 1), and springs back in ~0.2 s.
+- [U] Real-trackpad feel (momentum events were sent with one flick only; Arc does not need them to commit).
+- Frames: scratchpad `arc/rec/t2-strip.png` (paused mid-drag, at release, settling, open), `arc/rec/t4-sheet.png`
+ (swipe out), `arc/rec/t1.mov`–`t4.mov`.
+
+**Spaces page with 8 spaces**
+- [O static] `SpaceManagementViewControllerSpacesPage` holds an `NSScrollView` + `NSCollectionView`; the strip is a
+ `SpaceManagementHScrollCollectionViewItem` with its own private `ScrollView` subclass.
+- [O AX] Sidebar = window width − 56 pt whenever the cards don't fit (500 → 444, 900 → 844, 1100 → 1044, 1728 → 1672,
+ live while resizing, no maximum seen); the web page keeps a 56 pt column (8 spaces need 112 + 2208 pt, more than
+ this 1728 pt display, so the "fits" case was not reached). Rail 112 pt, strip scroll area = the rest (932 pt at
+ 1100); content 2208 = 24 + 8 × (240 + 24) + 48 pt add-space button + 24. Cards are clipped at the sidebar edge.
+- [O] Horizontal two-finger swipes scroll the strip 1:1 over a card's tab list, a card's empty body, the gaps
+ between cards alike; elastic at both ends (~17 pt stretch for 340 px), ~0.25 s spring back. A swipe that starts
+ inside the strip never leaves the Library; a new swipe that starts with the strip already at its end (pushing
+ past it) becomes the Library page swipe out (content and sidebar edge follow, then the usual settle). Over the
+ rail the same swipe did nothing (strip at its end).
+- [O] Vertical mouse wheel and vertical trackpad scroll do not move the strip. Shift + wheel scrolls it, 10 pt per
+ line; at the strip's end further Shift + wheel left the Library to the first space (non-gestural page change).
+- [O AX] Scroller: AppKit overlay AXScrollBar, horizontal, 17 pt track at the bottom (y 1060–1077 in a 1084 pt
+ window), inset 19 pt from the scroll area on each side, knob 4 pt tall (373.5 of 894 pt for 932 of 2208), shown
+ while scrolling.
+- [O] Theme editor (a card's brush, AXPress): a separate 382 × 534 pt window, left edge flush with that card's
+ right edge, top at the window top, over the neighbouring cards and the page, overhanging the browser window's right
+ edge when the card is near it (Games card at the strip end: 1339–1721 in a window ending at 1491).
+- [U] Whether the page column has a minimum when the window is narrower than 500 pt; the width rule once all
+ cards fit on a wider display.
+- Frames: `arc/rec/b1.png` (1100 pt window), `arc/rec/b3-main.png` (theme editor), `arc/rec/t10.mov`, `t12.mov`.
+- [Cra, 1 Nov 2026] Victor found Arc's half-speed, sidebar-widening drag "way too slow / laggy" and asked for the
+ space swipe's animation instead. Cra's `LibrarySwipe` (CraCore) treats the Library as the page before the first
+ space, its right edge 1:1 under the fingers, with the space swipe's rubber band, release rule (> 0.8 pages/s or
+ past half) and settle (critically damped, ω = 2π/0.4). Like Arc the sidebar widens with the reveal (base +
+ (Library − base) × r), so it lands at the Library's width with nothing left to resize (a resize after landing
+ looked ugly with a narrow sidebar). Embedded pages keep their size under their cards during the swipe
+ (`ShellView.freezePages`) and resize once when it lands: a page resize per event made Chromium lay the page out
+ each time and stalled the swipe for a second. The Library's search takes focus only after landing (focusing it
+ mid-swipe flashed a system panel). The Spaces page follows Arc: sidebar = window − 56 pt, live on resize; cards scroll
+ sideways under two fingers (over card lists too) and Shift+wheel; a swipe that starts with the cards at their
+ end leaves the Library; the brush's theme editor sits flush with the card's right edge.