Skip to content

Scroll: a notched mouse wheel glides as Chromium's does, on the device grid - #1150

Merged
Hona merged 5 commits into
devfrom
scroll-wheel
Nov 18, 2026
Merged

Hona merged 5 commits into
devfrom
scroll-wheel

Conversation

@Hona

@Hona Hona commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

A notched mouse wheel now glides instead of jumping, on Chromium's curve: the ease the owner asked for on 16 Nov ("wheel jumps", "everywhere").

What's in:

  • Windows and Linux: whole notches of a mouse wheel that no on_wheel handler takes ease to where they send a viewport, vertically and sideways. A notch is a run of whole-line deltas (WheelEvent::notch); the run's first delta decides and the run keeps it, so a fast touchpad swipe's whole-line delta stays precise.
    • Linux follows winit's deltas: a wheel's detents are whole lines (X11's buttons 4 to 7 and XInput2's position over its increment, Wayland's discrete values), and a touchpad's are fractions (XInput2) or pixels (Wayland's finger and continuous sources). It isn't driven here: no Linux machine with a desktop is available to me. A high-resolution wheel on XInput2 (fractional value120) stays 1:1, unlike Chromium, which eases it.
  • Unchanged: precise touchpads and macOS still move 1:1, as the platform's own momentum does. The web build's in-canvas scrollers don't ease yet.
  • Not here:
    • keys: official eases PageUp, PageDown, Space, Home, End and the arrows over 150 ms; that's the next PR;
    • mounting a virtual list's rows ahead of the ease, toward its target: a PR straight after, for SCALE to read.

The curve (runtime/scroll/wheel.rs, from cc/animation/scroll_offset_animation_curve.cc, kInverseDelta):

  • Shape: cubic-bezier(0.42, 0, 0.58, 1), its duration from the whole remaining travel in device px: 200 ms up to 120 px, 100 ms from 480. One notch takes 200, 191.7 and 181.3 ms at 1×, 1.5× and 1.875×.
  • The first frame: an ease from rest starts at its first frame, which draws where it was, as Chromium's does. Official's recording reads 0 at 13 ms after the notch and 5 px at 38 ms.
  • Retargeting: a notch that comes while it moves sends it on from where it is, with the speed it had (UpdateTarget, EaseInOutWithInitialSlope, the 2.5× velocity bound). Stacked notches run as one motion, and a notch back turns it round. A retarget keeps the frame's catch-up, so the frame after a stacked notch is a whole step at 60 Hz. A notch that sends it back to where it is (a flick back before the next frame) lands it there. Two notches before the first frame still start on it. In the rare case where the velocity bound leaves a segment no time (wheel.rs:146), it stays where it is; Chromium jumps to the new target.
  • Where it lands: every frame is on the device grid, (v * scale).round() / scale: steps of 2/3 pt at 1.5× and 8/15 pt at 1.875×. So it lands on the grid point nearest the notch's target, not exactly on the target. The exception is within a device pixel of an end, where it lands exactly on the end, so the next run hands on and a following list pins.
  • A list that grows: an ease sent to the end of a viewport that follows its bottom remembers it. While the end grows under it (a reply streaming), it takes its target with the end and pins on the frame it gets there, though each growth restarts its segment.

Which viewport: the one #1137's chain picks: the topmost hit under the pointer, then its scroll ancestors. A gliding viewport counts its room from where its ease is heading.

What stays instant (A11Y): only a notched wheel eases. ScrollMode::Wheel and XMotion::Wheel are started only by Runtime::wheel_notch and the horizontal notch path. Anything else takes the viewport over at once: a focus move, Tab's reveal, Tx::scroll_to and scroll_into_view, AccessKit's scroll actions, Find, a hand, a key or a fling.

  • A scroll_to glide that starts during an ease keeps the ease's speed.
  • An app's keep (rows above measured, an anchor holding what's on screen) moves the ease with it, as Chromium's ApplyAdjustment moves a running smooth scroll.
  • Reduced motion lands at once, including mid-ease, and so does Runtime::set_wheel_glide(false).

Frames and drawing (both reads):

  • The clock: the ease uses the same per-frame clock as growth (Step growth by each frame's own time #1067). After it lands or is cut short, there are no wakes.
  • Every eased frame is an ordinary scroll frame (AnimSource::SCROLL), never a loop-only one, and everything that reads the offset reads what is drawn.
  • The cost: every notch is now 6 to 48 scroll frames. On blade's Iris at 240 Hz, a scroll frame takes 5.82 ms of GPU at 1440×960 against a 4.17 ms budget. So most refreshes of an ease are missed until perf(render): pin the frame pass's fragment shader per kind on Windows #1140 (2.55 ms) is in, and at 2560×1440 even then (6.47 ms). The measured rows follow.
  • on_scroll_offset now fires on every eased frame, up to 48 a notch at 240 Hz. Every handler in the app is cheap per call or already coalesced:
    • the timeline's load-older and message-nav watchers: an edge-triggered flag and a Cell;
    • the side panels' offset Cell;
    • the switcher band's state step, which wakes only when its state says to;
    • the composer attachments' fade flags;
    • the office pages' viewer, which asks for each page's scene once;
    • the office sheet's view update. None persists anything or calls the server, but this one sends the document worker a render job (show_sheet) for each new rounded viewport: up to 48 a notch. The worker drains its queue and renders only the newest frame (office/worker.rs), so superseded ones are dropped; a driven row counts them.

State: the ease is a mode of the viewport's own state machine, not a flag: ScrollMode::Wheel(WheelCurve) vertically and XMotion::Wheel(WheelCurve) sideways. XMotion replaces the axis's separate velocity and glide fields. A run's kind is DeltaKind: Idle, Notched or Precise.

Tests: no test is added. One line of test code changes: mode.rs:339, a match arm in the existing test module that the new ScrollMode::Wheel variant forces.

Driven rows (headless capture tickets on blade; offsets per frame from the app's trace, and pixels where marked). Every app is OpenCode (Rune) dev 8ad4ab46, release-quick, with Rune patched to a clean worktree (no uncommitted changes) unless the row says otherwise:

Row App Result
One notch, Settings 960×540, 144 Hz ease-app-0fc1193e Lands on 100 exactly at 1× and 1.5×, and on 100.27 (the nearest device pixel) at 1.875×. Visible motion takes 174–181 ms, within 0.13–0.18 of official's recording's progress.
One notch at 60 and 240 Hz, 1.5× ease-app-0fc1193e Lands on 100 at both. Visible motion takes 183 and 180 ms, within 0.12 and 0.21 of official's.
Three stacked, a notch mid-ease, a reversal, at 60, 144 and 240 Hz, 1.5×; 144 Hz at 1.875× ease-app-0fc1193e Stacked notches run as one motion and land on 300. A notch mid-ease lands on 200. A reversal turns round and lands back on 0.
A run of notches into the end ease-app-0fc1193e Stops on the end: 1930.67 at 1.5×, 1927.73 at 1.875×.
Whole device pixels ease-app-0fc1193e Settings at 1.5× (60, 144, 240 Hz) and 1.875× (144 Hz), and the timeline at 1×, 1.5× and 1.875×: no step between frames is off the device grid. The only exception is a last step onto an end, which lands on the end exactly.
Timeline, up from its end, 144 Hz ease-app-0fc1193e The same: one notch, stacked notches and a notch mid-ease land a whole number of notches up. A reversal lands back on the end.
The settled frame on screen ease-app-0fc1193e One notch, captured 2.8 s after it settled, against the same notch with Reduce Motion (the view placed at the offset at once). Inside the scrolled view, 0 pixels differ at 1× and 1.5×. The only differences are 25 px (1×) and 44 px (1.5×) in one box in the title bar, one level apart (20 vs 21), outside the scroll view. The control without a notch differs by 90,643 and 191,663 px. The window only skips presenting a frame whose instances are byte-identical to the last presented one (Presented::same), so the landing frame is presented.
Reduce Motion, 1.5× ease-app-0fc1193e Each notch jumps in one frame and lands exactly on 100, 200, 300 and 0.
The Shell console handing on ease-app-0fc1193e A run eases the console to its end (100), then back to 0. After the rest, the next run moves the timeline (1191.6 to 1092).
The / list ease-app-0fc1193e The list moved 899 pt; the timeline behind it 0.
A sticky header (Settings 1440×900, its full layout) ease-app-0fc1193e and ease-1147-d777e8c4 The header band's pixels are unchanged in all 72 frames across one notch and three stacked, at 1× and 1.875×, on both apps. The row below it, as the control, changed in 63–64 frames.
The pinned build's three checks pin-db591e09 The Shell console (100, then 0, then the timeline 1192.6 to 1092.6), the / list (800 pt; the timeline 0) and the app menu (0 and 0) all pass.
The Office sheet ease-app-0fc1193e (counted from the rows) One render job per eased frame with a new rounded viewport: about 11, 25 and 41 a notch at 60, 144 and 240 Hz. The worker drains its queue and renders only the newest.

Rows while a reply streams (fixture-stream-rows.ts). The fixture's session scene, at 800×360, 144 Hz, 1× and 1.5×. A prompt sent from the composer at 1.25 s brings a reply that streams from about 1.5 s to 2.8 s. "On the end" means the content's lowest drawn edge sits where it did while the list was pinned before any notch.

Row App Result
A notch into a following list's end while the reply grows ease-app-0fc1193e Two notches up, then three down and one past (the last at 2150 ms). The offset first equals the end at 2361 ms, 30 frames after the last notch. It then equals the growing end on all 150 later frames: it rose 66.37 pt as the reply grew 66.37 pt (65.91 for 65.91 at 1.5×). The trace has no mode field, so this exact equality on every later frame is the evidence that the list is pinned from that frame; an ease trailing the end would lag.
An extra notch at the end while it streams ease-app-0fc1193e The offset follows the reply exactly (89.02 pt for 89.02 pt). Twelve frames (2104–2354 ms) trail the end by up to 17.55 pt. The same reply with no notch has the same 12 frames at the same times, so that is the list trailing a burst of the reply, not the notch.
An ease during growth ease-app-0fc1193e; control keep-rq (#1137, no ease) One notch up while the reply streams, against the same notch with nothing streaming: the ease itself matches. The streaming run then drifts 7.83 pt further as it settles (7.5 at 1.5×). The #1137 build's instant notch drifts the same way, 8.07 pt on the same curve, settling by about 2.2 s. So the drift is the pinned list's slack settling after a wheel takes it off a streaming end. It's there before the ease too.

Owed:

  • A three-notch ease into an unmounted part of the 10,000-message transcript: this needs STREAM's drive-server.ts 10k session, which a headless run can't open yet (--session looks the id up in a list a headless run hasn't filled).
  • Missed refreshes and GPU time per eased frame at 240 Hz, at 1440×960 and 2560×1440, with and without perf(render): pin the frame pass's fragment shader per kind on Windows #1140. This is one timing ticket on blade's own screen, in GPUI's ordered list.

Hona added 3 commits November 18, 2026 09:24
Whole notches of a mouse wheel (`WheelEvent::notch`, whole-line deltas on Windows) that no
`on_wheel` handler takes ease to where they send a viewport on Chromium's mouse-wheel curve
(cc/animation/scroll_offset_animation_curve.cc, kInverseDelta): cubic-bezier(0.42, 0, 0.58, 1)
over 200 ms up to 120 device pixels, 100 ms from 480. A notch that comes while it moves sends it
on from where it is with the speed it had (UpdateTarget, EaseInOutWithInitialSlope and the 2.5x
velocity bound), so stacked notches run as one motion and a notch back turns it round. The ease
is `ScrollMode::Wheel` on the vertical axis and `XMotion::Wheel` on the horizontal one, whose
velocity and optional glide are now one `XMotion`. It steps at every frame; a hand, a key, a
fling or `Tx::scroll_to` take the viewport over at once; reduced motion, or
`Runtime::set_wheel_glide(false)`, lands it at once. macOS, Linux, precise trackpads and
free-spinning wheels move 1:1 as before.

A run of notches picks and keeps its viewport as #1123's deltas do (`Runtime::wheel_run`); a
viewport that is gliding counts its room from where its ease heads, so a run that begins while
one glides to its end starts on the viewport around it.
…takes no catch-up time

As Chromium's scroll offsets are (measured at 1.875x: every offset of a notch's ease is a whole
device pixel), so everything in the viewport moves by the same whole pixels each frame and draws
as it did instead of at a new fraction of a pixel every frame. The time a frame charges to motion
that was already running (`frame::clock::split`'s catch-up) no longer advances an ease a notch
started or retargeted since the last frame.
…e or an anchor holds

What moved the offset under a running ease since it last stepped (rows mounting and measuring
above the reader, content arriving above, an anchor keeping what's on screen) now moves the
ease's start and end by the same amount, as Chromium's ApplyAdjustment does, so the next frame
doesn't pull the content back by what the measurement moved.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 23:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Hona added 2 commits November 18, 2026 10:36
…me, and stays put when sent back

The two reads of #1150, together:

- An extra notch at an end no longer starts an empty ease that lets go of a streaming reply: a
  notch with no ease running starts from a finished curve (`WheelCurve::still`), and one that
  sends it nowhere new changes no mode.
- An ease sent to the end of a viewport that follows its bottom remembers it (`to_end`): as the
  end grows under it (a reply streaming) it takes its target with the end, lands there and pins.
- Within a device pixel of the end, the end wins over the device grid (`on_grid_or_end`), so the
  room test hands the next run on and the pin threshold holds at any zoom.
- A notch that sends a running ease back to where it is (a flick back before the next frame)
  lands it where it is, as Chromium's stays put, rather than finishing the ease before it.
- A retarget of a moving ease is the same motion going on and keeps the frame's catch-up (it
  was a half step at 60 Hz after each stacked notch); a zero step doesn't count as a frame; and an
  ease from rest starts at its first frame, which draws where it was, as Chromium's does.
- A notch or not is decided by a run's first delta and kept for the run (`DeltaKind`), so a fast
  touchpad swipe's whole-line delta doesn't start an ease the next fraction throws away.
- Linux eases too: winit gives a wheel's detents there as whole lines (X11 buttons 4-7 and
  XInput2's position over its increment, Wayland's discrete values) and a touchpad's as fractions
  or pixels.
- A `scroll_to` glide that starts during an ease keeps the ease's speed, and an app's keep (rows
  above measured, an anchor holding what's on screen) moves the ease with it rather than ending it,
  as Chromium's `ApplyAdjustment` does.
The first read's confirmation of #1150 at 5e4e46b:

- An ease sent to the end of a viewport that follows its bottom pins on the frame it gets there.
  The end growing under it restarts its segment every frame a reply grows, so waiting for the
  curve to finish left the list trailing the end until the stream paused.
- A retarget keeps whether its ease's first frame has come: two notches before that frame still
  start the ease on it, rather than the second's retarget charging that frame's catch-up.
- A run of wheel deltas is notched only while every delta is whole: a touchpad swipe whose first
  delta was exactly a line is precise from its first fraction on.
@Hona

Hona commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Windows whole suite (-p rune -p rune-kit) on adais, judged against dev's own failures at 32eb7811 (this lane, whole suite) and eb5ae6c9 (FUNCTION's run, rune only) and 3468f3a3 and cca5df6f: #1150 0fc1193e (18 Nov 12:26): 2841 passed, 18 failed in 170 binaries; also on dev: alloc::disabled_trace_hooks_neither_format_nor_allocate, canvas_input::the_middle_button_drags_only_elements_that_take_it, rune::edit::tests::hidden_multiline_pristine_replace_and_delete, rune::edit::tests::pill_edge_cases_words_lines_bidi_and_direct_text_mutation, rune::edit::tests::the_caret_steps_over_a_pill_in_one_move, rune::input::keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, rune::native_surface::gpu_tests::mirrored_video_is_exact_cropped_centred_and_toggles_without_a_new_frame, rune::native_surface::gpu_tests::video_gpu_colour_sharpness_geometry_and_lifetime, rune::render::breaker::tests::a_refused_blur_pipeline_draws_unblurred, rune::render::layers::cache_tests::live_scale_zoom_sweep_buckets_during_motion_and_settles_crisp, rune::render::layers::rebind_tests::a_texture_switch_binds_no_parked_target_until_one_returns, rune::render::layers::tests::clipped_single_draw_fades_do_not_allocate_targets, rune::runtime::tests::layout_rows::send_flight_follows_the_measured_bubble_while_earlier_rows_land, rune::runtime::tests::picture_scale::a_changing_static_scale_keeps_the_glyph_atlas_bounded, rune::runtime::tests::picture_scale::text_inside_a_scale_draws_at_that_size, rune::runtime::tests::scroll_children::scroll_xy_with_direct_children_scrolls_both_axes_and_warns_on_trailing_growth_sibling, rune::text::macos::smoothing::tests::pipelines_never_share_masks, selectable_text::copy_select_all_and_the_context_menu; none new. Base 47eaa86e. Proof 22729512.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants