Smooth wheel scrolling: route scroll over sliders to the list or the volume
CI / check (pull_request) Successful in 9s
CI / native (pull_request) Successful in 1m15s

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>
This commit is contained in:
SpriteandClaude Opus 5.5 committed 2026-11-23 06:44:52 +00:00
1 parent 0760d7ba6c
commit cff5f49dc3
9 files changed
+511 -15

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
///|
/// Long enough that the list is not scrolling any more.
const IDLE : Int64 = 10_000_000L
///|
test "a mouse wheel over an idle list changes the volume 2% per detent" {
let w = @model.SliderWheel::new()
// GTK: dy < 0 is up.
assert_eq(w.scroll(Wheel, 0.0, -1.0, IDLE, 50.0, 400.0), Some(52.0))
assert_eq(w.scroll(Wheel, 0.0, 1.0, IDLE, 50.0, 400.0), Some(48.0))
// Tilt wheel: right is louder.
assert_eq(w.scroll(Wheel, 1.0, 0.0, IDLE, 50.0, 400.0), Some(52.0))
}
///|
test "high-resolution wheels move by fractions of a step, unrounded" {
let w = @model.SliderWheel::new()
let mut v = 50.0
// One detent reported as eight 1/8 events (value120 = 15 each).
for _ in 0..<8 {
v = w.scroll(Wheel, 0.0, -0.125, IDLE, v, 400.0).unwrap()
}
assert_true((v - 52.0).abs() < 1.0e-9)
assert_eq(w.scroll(Wheel, 0.0, -0.125, IDLE, 50.0, 400.0), Some(50.25))
}
///|
test "the wheel keeps scrolling the list while it is moving" {
let w = @model.SliderWheel::new()
assert_eq(w.scroll(Wheel, 0.0, 1.0, 0L, 50.0, 400.0), None)
assert_eq(
w.scroll(Wheel, 0.0, 1.0, @model.LIST_LATCH_US - 1L, 50.0, 400.0),
None,
)
assert_eq(
w.scroll(Wheel, 0.0, 1.0, @model.LIST_LATCH_US, 50.0, 400.0),
Some(48.0),
)
}
///|
test "volume is clamped to the slider range" {
let w = @model.SliderWheel::new()
assert_eq(w.scroll(Wheel, 0.0, 1.0, IDLE, 1.0, 400.0), Some(0.0))
assert_eq(
w.scroll(Wheel, 0.0, -1.0, IDLE, @model.MAX_PERCENT - 1.0, 400.0),
Some(@model.MAX_PERCENT),
)
}
///|
test "a vertical touchpad swipe over a slider scrolls the list" {
let w = @model.SliderWheel::new()
w.reset()
assert_eq(w.scroll(Pixels, 0.4, 6.0, IDLE, 50.0, 300.0), None)
// Locked for the whole gesture, even if it turns sideways.
assert_eq(w.scroll(Pixels, 9.0, 0.0, IDLE, 50.0, 300.0), None)
w.reset()
}
///|
test "a horizontal touchpad swipe moves the knob with the fingers" {
let w = @model.SliderWheel::new()
w.reset()
// 300 px wide slider spanning 0..150%: 2 px = 1%.
assert_eq(w.scroll(Pixels, 10.0, 1.0, IDLE, 50.0, 300.0), Some(55.0))
// Vertical drift in the same gesture does not hand it to the list and
// does not change the volume.
assert_eq(w.scroll(Pixels, 0.0, 8.0, IDLE, 55.0, 300.0), Some(55.0))
assert_eq(w.scroll(Pixels, -3.0, 0.0, IDLE, 55.0, 300.0), Some(53.5))
w.reset()
// A new gesture is decided afresh.
assert_eq(w.scroll(Pixels, 0.0, 5.0, IDLE, 53.5, 300.0), None)
}
///|
test "a touchpad gesture starting while the list moves stays with the list" {
let w = @model.SliderWheel::new()
w.reset()
assert_eq(w.scroll(Pixels, 12.0, 0.0, 1_000L, 50.0, 300.0), None)
assert_eq(w.scroll(Pixels, 12.0, 0.0, IDLE, 50.0, 300.0), None)
}
///|
test "wheel_delta_percent tolerates an unallocated slider" {
assert_eq(@model.wheel_delta_percent(Pixels, 2.0, 0.0, 0.0), 1.0)
assert_eq(@model.wheel_delta_percent(Wheel, 0.0, -0.5, 0.0), 1.0)
}