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.
Shift + wheel pages spaces the same way as Arc with natural scrolling on
Victorb955d1d7038e
diff --git a/Packages/CraCore/Sources/CraCore/WheelSpaceSwitch.swift b/Packages/CraCore/Sources/CraCore/WheelSpaceSwitch.swiftindex 35146a2..b6507f1 100644--- a/Packages/CraCore/Sources/CraCore/WheelSpaceSwitch.swift+++ b/Packages/CraCore/Sources/CraCore/WheelSpaceSwitch.swift@@ -11,9 +11,9 @@ public struct WheelSpaceSwitch: Sendable {/// More than this many lines (AppKit's `scrollingDeltaX` for a wheel) switch: one slow/// notch does nothing, a flick does (Arc: 1 line never, 2 lines always).public static let distance: CGFloat = 1- /// A longer gap between wheel events forgets what had added up (Arc: two notches 35 ms- /// apart switch, 45 ms apart half the time, 65 ms apart never).- public static let pause: TimeInterval = 0.045+ /// A longer gap between wheel events forgets what had added up (Arc's constant: 0.05 s;+ /// two notches 35 ms apart switch, 65 ms apart never).+ public static let pause: TimeInterval = 0.05/// After a switch the wheel does nothing for this long (Arc: one switch for a 0.245 s burst,/// two for 0.254 s).public static let cooldown: TimeInterval = 0.25@@ -25,15 +25,20 @@ public struct WheelSpaceSwitch: Sendable {public init() {}/// Feeds one wheel event of `dx` lines at `time`. Returns the page step it makes: +1 toward- /// the next space, −1 toward the previous one (a positive `dx`, as two fingers moving right- /// go back), 0 none.- public mutating func step(dx: CGFloat, at time: TimeInterval) -> Int {- defer { lastEventTime = time }- guard dx != 0, time - lastTriggerTime >= Self.cooldown else { return 0 }- if time - lastEventTime > Self.pause || (dx > 0) != (cumulativeDistance > 0) { cumulativeDistance = 0 }+ /// the next space, −1 toward the previous one, 0 none. `inverted` is the event's+ /// `isDirectionInvertedFromDevice` (natural scrolling, on by default in macOS), which flips+ /// `dx` back to the wheel's own direction. Like Arc 1.171 the direction is the sign of the+ /// total XOR `inverted`: a negative `dx` from a device that isn't inverted goes to the next+ /// space, so the same wheel turn pages the same way whatever the scroll direction setting+ /// (issue #93).+ public mutating func step(dx: CGFloat, inverted: Bool, at time: TimeInterval) -> Int {+ // Arc returns before noting the time, so the cooldown's events count for nothing.+ guard dx != 0, time - lastTriggerTime > Self.cooldown else { return 0 }+ if time - lastEventTime > Self.pause { cumulativeDistance = 0 }+ lastEventTime = timecumulativeDistance += dxguard abs(cumulativeDistance) > Self.distance else { return 0 }- let step = cumulativeDistance > 0 ? -1 : 1+ let step = (cumulativeDistance < 0) != inverted ? 1 : -1cumulativeDistance = 0lastTriggerTime = timereturn stepdiff --git a/Packages/CraCore/Tests/CraCoreTests/WheelSpaceSwitchTests.swift b/Packages/CraCore/Tests/CraCoreTests/WheelSpaceSwitchTests.swiftindex 48b716e..b9caac8 100644--- a/Packages/CraCore/Tests/CraCoreTests/WheelSpaceSwitchTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/WheelSpaceSwitchTests.swift@@ -5,9 +5,9 @@ import Testing/// Shift + wheel (or a sideways wheel) over the sidebar switches spaces like Arc 1.171 (issue #93).struct WheelSpaceSwitchTests {/// Feeds `(dx, time)` events and returns the steps they make.- private func steps(_ events: [(CGFloat, Double)]) -> [Int] {+ private func steps(_ events: [(CGFloat, Double)], inverted: Bool = false) -> [Int] {var wheel = WheelSpaceSwitch()- return events.map { wheel.step(dx: $0.0, at: $0.1) }+ return events.map { wheel.step(dx: $0.0, inverted: inverted, at: $0.1) }}@Test func oneSlowNotchDoesNothing() {@@ -28,8 +28,25 @@ struct WheelSpaceSwitchTests {#expect(steps([(1, 10), (1, 10.02)]) == [0, -1])}- @Test func aTurnStartsTheCountAfresh() {+ /// With natural scrolling (macOS's default) the deltas arrive flipped and the event says so;+ /// the same wheel turn still pages the same way (Arc 1.171 XORs the sign with+ /// isDirectionInvertedFromDevice; issue #93, reversed in Cra 0.1.27).+ @Test func naturalScrollingPagesTheSameWay() {+ #expect(steps([(2, 10)], inverted: true) == [1])+ #expect(steps([(-2, 10)], inverted: true) == [-1])+ #expect(steps([(1, 10), (1, 10.02)], inverted: true) == [0, 1])+ }++ /// A turn subtracts from what had added up rather than starting afresh (Arc keeps one sum).+ @Test func aTurnCancelsOut() {#expect(steps([(-1, 10), (1, 10.02), (-1, 10.04)]) == [0, 0, 0])+ #expect(steps([(-0.8, 10), (0.5, 10.02), (-0.8, 10.04)]) == [0, 0, 1])+ }++ /// Arc forgets the sum after 0.05 s without a wheel event.+ @Test func aPauseForgets() {+ #expect(steps([(-1, 10), (-1, 10.045)]) == [0, 1])+ #expect(steps([(-1, 10), (-1, 10.055)]) == [0, 0])}/// One switch per quarter second, however fast the wheel spins (Arc: a 0.245 s burst ofdiff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex ab1b39f..127b942 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -1829,6 +1829,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMreturn clip.bounds.minX >= (strip.documentView?.frame.width ?? 0) - clip.bounds.width - 1}+ /// Whether the Spaces page's cards under the pointer can still scroll the way a wheel of `dx`+ /// moves them (a negative `dx` toward the last card, as the scroll view applies it).+ private func spacesStripCanScroll(_ event: NSEvent, dx: CGFloat) -> Bool {+ guard let strip = spacesStrip(at: event) else { return false }+ return dx < 0 ? !spacesStripAtEnd(event) : strip.contentView.bounds.minX > 1+ }+/// The Spaces page's row of cards under the pointer.private func spacesStrip(at event: NSEvent) -> NSScrollView? {guard let root = shell.sidebarHost.window?.contentView?.superview else { return nil }@@ -1846,10 +1853,11 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMguard shell.sidebarVisible || shell.floatingSidebar, event.window != nil, event.window === host.window,host.bounds.contains(host.convert(event.locationInWindow, from: nil)), !isIncognito else { return false }let dx = event.scrollingDeltaX- // On the Spaces page the cards scroll first; at their end the wheel leaves the Library, and- // over the rail it leaves at once (Arc).- if sidebarUI.libraryPage == .spaces, spacesStrip(at: event) != nil, dx > 0 || !spacesStripAtEnd(event) { return false }- let step = wheelSpaceSwitch.step(dx: dx, at: event.timestamp)+ // On the Spaces page the cards scroll first; once they can't scroll that way the wheel pages,+ // which leaves the Library when it heads for the next space, and over the rail it leaves at+ // once (Arc).+ if sidebarUI.libraryPage == .spaces, spacesStripCanScroll(event, dx: dx) { return false }+ let step = wheelSpaceSwitch.step(dx: dx, inverted: event.isDirectionInvertedFromDevice, at: event.timestamp)guard step != 0 else { return true }let order = store.spaceOrder// Where the Library is headed, if it is sliding.diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 2e2a527..eb1a0b1 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -2556,7 +2556,16 @@ tap with a real Shift key held around them; the space read from each window's `sone switch per 0.25 s. Ten 1-line events 30 ms apart (first switch at the 2nd event) switched once, so whatarrives during the cooldown is dropped.- [O 120 fps] The switch animates like a space change: the header slides in and the tint follows, ~0.15–0.2 s.-- Cra: `WheelSpaceSwitch` (CraCore) with distance > 1 line, pause 45 ms, cooldown 0.25 s; the window controller's+- [O static, 4 Nov 2026, issue #93 follow-up] The handler (arm64 0x100a2193c in Arc 1.171's main binary, called+ with the event; `CACurrentMediaTime` for the clock): within 0.25 s of the last switch it returns before noting+ the time; a gap over 0.05 s (the constant is 0.05) zeroes the sum; then time = now, sum += `scrollingDeltaX`,+ and past |1| it pages, zeroes the sum and notes the switch. One sum: a turn subtracts, it doesn't restart.+ Direction (0x100a21b00): sum < 0 → next unless `isDirectionInvertedFromDevice`, sum > 0 → previous unless+ inverted, so the sign is XORed with natural scrolling. The probe above posted synthetic wheels (not inverted),+ which is why "negative = next" held; a real mouse with natural scrolling on (macOS's default) sends inverted,+ flipped deltas, and Cra 0.1.27 ignored the flag and paged backwards (reported on #93 by Anoninz). CGEvent field+ 137 = 1 makes a synthetic wheel report `isDirectionInvertedFromDevice`.+- Cra: `WheelSpaceSwitch` (CraCore) with distance > 1 line, pause 0.05 s, cooldown 0.25 s, direction XOR inverted; the window controller'sscroll monitor feeds it non-precise horizontal wheels over the sidebar (docked or floating, not incognito). Astep focuses the space on Cra's usual space-change spring (Dia's 0.4 s, slower than Arc's here), or slides theLibrary in or out like its button. On the Spaces page the cards take the wheel first (10 pt per line, as in Arc)