1package wayland
2
3import (
4 "testing"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9// High-resolution wheels send fractions of a detent: pre-v8 clients get a
10// discrete step once 120 builds up; a direction change drops the rest.
11func TestWheelSteps(t *testing.T) {
12 s := &Server{}
13 var values [2]float64
14 wheel := func(v, h int32) (steps [2]int32) {
15 steps, values = s.seat.wheelSteps(ports.PointerAxis{
16 Vertical: ports.ScrollAxis{Set: v != 0, V120: v, Value: float64(v) / 8},
17 Horizontal: ports.ScrollAxis{Set: h != 0, V120: h},
18 })
19 return steps
20 }
21 for i, tc := range []struct {
22 v, h int32
23 want [2]int32
24 }{
25 {60, 0, [2]int32{}},
26 {60, 0, [2]int32{1, 0}},
27 {180, 0, [2]int32{1, 0}},
28 {60, 0, [2]int32{1, 0}},
29 {-60, 240, [2]int32{0, 2}},
30 {-60, 0, [2]int32{-1, 0}},
31 {30, -30, [2]int32{}},
32 } {
33 if got := wheel(tc.v, tc.h); got != tc.want {
34 t.Fatalf("step %d: got %v, want %v", i, got, tc.want)
35 }
36 }
37 // The held value sums the frames since the last step.
38 *s = Server{}
39 wheel(60, 0)
40 if s.seat.wheelHeld[0] != 7.5 {
41 t.Fatal("held", s.seat.wheelHeld[0])
42 }
43 if wheel(60, 0) != [2]int32{1, 0} || s.seat.wheelHeld[0] != 0 || values[0] != 15 {
44 t.Fatal("held after step", s.seat.wheelHeld[0])
45 }
46 // A direction change drops what was held the other way.
47 wheel(60, 0)
48 if wheel(-180, 0) != [2]int32{-1, 0} || values[0] != -22.5 {
49 t.Fatal("after reversal", values)
50 }
51 if steps, _ := s.seat.wheelSteps(ports.PointerAxis{Source: ports.AxisFinger, Vertical: ports.ScrollAxis{Set: true, V120: 240}}); steps != [2]int32{} {
52 t.Fatal("finger scroll made discrete steps")
53 }
54}