Smooth wheel scrolling: route scroll over sliders to the list or the volume #5

Merged
nandi merged 1 commits from geordi/smooth-wheel-scroll into main 2026-11-23 06:55:50 +00:00
Owner

Root causes (from GTK 4.22.4 source)

  • Sliders swallow list scrolling. GtkRange adds its own GtkEventControllerScroll whose handler always returns GDK_EVENT_STOP. GtkScrolledWindow only grabs scroll events in the capture phase once its own smooth-scroll sequence is running. Mouse wheels (X11, and Wayland value120 events) are not smooth sequences, so each detent over a slider went to the slider: the list stopped and that stream's volume changed.
  • 10% per detent. scroll_delta_to_value() multiplies a wheel delta by the page increment. gtk_scale_new_with_range(…, step=1) sets that to 10 * step, so each notch moved 10%.
  • Touchpad dead zone. For pixel (touchpad) deltas on a horizontal scale, GtkRange uses only dx. A vertical swipe that starts over a slider changed nothing but was still swallowed, so the list didn't scroll and got no kinetic momentum. A horizontal wheel (tilt) was ignored too.
  • Meters and model updates are not the cause. Renders only happen for diffed rows. reorder_child_after, gtk_label_set_text, set_sensitive and set_active are no-ops when nothing changed. GtkLevelBar updates only queue_allocate its trough (no queue_resize) at 25 Hz, and only when the level changes. Nothing there needed changing.

Change

Sliders replace GtkRange's scroll controller with one that asks MoonBit synchronously (@model.SliderWheel, pure and unit-tested) where each event goes:

  • While the list is moving (it moved, or was handed a scroll, less than 600 ms ago, kinetic deceleration included), events keep scrolling the list.
  • Otherwise a mouse wheel changes the volume by 2% per detent. High-resolution wheels move in proportion, with no rounding, and the tilt wheel works too.
  • A touchpad gesture is decided at its first movement and locked until it ends. Mainly vertical scrolls the list (with GTK's kinetic scrolling). Mainly horizontal moves the knob with the fingers (PHYSICAL_DIRECTION, on GTK ≥ 4.20) and gets no momentum.

Verification

  • moon fmt --check, moon check --target native --deny-warn, moon test --target wasm-gc (42 passed, 8 new in model/wheel_test.mbt), tools/test-container.py, tools/smoke-test.sh with screenshots: all pass.
  • Measured under Xvfb with XTest wheel clicks, 8 playback streams and a private PipeWire, using a trace build (not committed):
Scenario Before After
12 wheel-down notches, pointer parked over row 1's title list moved 3×, then sliders ate 9 notches (one stream 100% → 20%) list scrolled to the end (10 moves), no volume changed
Keep wheeling 300 ms after a list scroll, slider under pointer 3 notches went to the slider (100 → 70%) list kept scrolling
Pointer resting on a slider, 3 up / 3 down 10% steps 2% steps
Tilt wheel right ×2 on a slider nothing +2% each

Touchpad and high-resolution wheel paths can't be produced with XTest. The unit tests and the GTK source cover them.

🤖 Generated with Claude Code

## Root causes (from GTK 4.22.4 source) - **Sliders swallow list scrolling.** `GtkRange` adds its own `GtkEventControllerScroll` whose handler always returns `GDK_EVENT_STOP`. `GtkScrolledWindow` only grabs scroll events in the capture phase once *its own* smooth-scroll sequence is running. Mouse wheels (X11, and Wayland `value120` events) are not smooth sequences, so each detent over a slider went to the slider: the list stopped and that stream's volume changed. - **10% per detent.** `scroll_delta_to_value()` multiplies a wheel delta by the page increment. `gtk_scale_new_with_range(…, step=1)` sets that to `10 * step`, so each notch moved 10%. - **Touchpad dead zone.** For pixel (touchpad) deltas on a horizontal scale, GtkRange uses only `dx`. A vertical swipe that starts over a slider changed nothing but was still swallowed, so the list didn't scroll and got no kinetic momentum. A horizontal wheel (tilt) was ignored too. - **Meters and model updates are not the cause.** Renders only happen for diffed rows. `reorder_child_after`, `gtk_label_set_text`, `set_sensitive` and `set_active` are no-ops when nothing changed. `GtkLevelBar` updates only `queue_allocate` its trough (no `queue_resize`) at 25 Hz, and only when the level changes. Nothing there needed changing. ## Change Sliders replace GtkRange's scroll controller with one that asks MoonBit synchronously (`@model.SliderWheel`, pure and unit-tested) where each event goes: - While the list is moving (it moved, or was handed a scroll, less than 600 ms ago, kinetic deceleration included), events keep scrolling the list. - Otherwise a mouse wheel changes the volume by **2% per detent**. High-resolution wheels move in proportion, with no rounding, and the tilt wheel works too. - A touchpad gesture is decided at its first movement and locked until it ends. Mainly vertical scrolls the list (with GTK's kinetic scrolling). Mainly horizontal moves the knob with the fingers (`PHYSICAL_DIRECTION`, on GTK ≥ 4.20) and gets no momentum. ## Verification - `moon fmt --check`, `moon check --target native --deny-warn`, `moon test --target wasm-gc` (42 passed, 8 new in `model/wheel_test.mbt`), `tools/test-container.py`, `tools/smoke-test.sh` with screenshots: all pass. - Measured under Xvfb with XTest wheel clicks, 8 playback streams and a private PipeWire, using a trace build (not committed): | Scenario | Before | After | |---|---|---| | 12 wheel-down notches, pointer parked over row 1's title | list moved 3×, then sliders ate 9 notches (one stream 100% → 20%) | list scrolled to the end (10 moves), no volume changed | | Keep wheeling 300 ms after a list scroll, slider under pointer | 3 notches went to the slider (100 → 70%) | list kept scrolling | | Pointer resting on a slider, 3 up / 3 down | 10% steps | 2% steps | | Tilt wheel right ×2 on a slider | nothing | +2% each | Touchpad and high-resolution wheel paths can't be produced with XTest. The unit tests and the GTK source cover them. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nandi added 1 commit 2026-11-23 06:45:09 +00:00
Smooth wheel scrolling: route scroll over sliders to the list or the volume
CI / native (pull_request) Successful in 1m15s
CI / check (pull_request) Successful in 9s
cff5f49dc3
GtkRange's built-in scroll controller moved a slider by its page increment
(10%) per wheel detent, ignored the tilt wheel and returned GDK_EVENT_STOP
for every scroll event, including a touchpad's vertical swipe it did nothing
with. So scrolling a list stopped dead whenever a slider passed under the
pointer and changed that stream's volume instead.

Sliders now replace that controller with one that asks MoonBit
(@model.SliderWheel) synchronously where each event goes:
- while the list is moving (it moved or was sent a scroll < 600 ms ago,
  kinetic deceleration included) events keep scrolling the list;
- otherwise a mouse wheel changes the volume by 2% per detent, fractional
  for high-resolution wheels, tilt wheel included;
- a touchpad gesture is decided at its first movement: mainly vertical
  scrolls the list (kinetic), mainly horizontal moves the knob with the
  fingers (physical direction).

Measured under Xvfb with XTest and 8 playback streams: 12 wheel notches
over a row title used to scroll 3 times and drop a stream from 100% to 20%;
now the list scrolls to the end and no volume changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nandi merged commit d360b51bb2 into main 2026-11-23 06:55:50 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: geordi/moonmix#5