1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#include "../../src/wayland/pointer.c"
#include <assert.h>
static struct yasl_mouse_event next(struct wayland_surface *surface)
{
struct yasl_input_event event;
assert(yasl_surface_input_poll(&surface->base, &event));
assert(event.surface == &surface->base && event.kind == YASL_INPUT_MOUSE);
return event.mouse;
}
int main(void)
{
struct wayland_display display = {.base.ops = &yasl_wayland_backend};
struct wayland_surface surface = {.base.display = &display.base, .conn = &display,
.scale_factor = 1.5};
struct seat seat = {.conn = &display, .tablet_focus = &surface};
struct tablet_tool tool = {.seat = &seat};
seat.tool = &tool;
tablet_tool_motion(&tool, NULL, wl_fixed_from_int(100), wl_fixed_from_int(120));
tool_pressure(&tool, NULL, 32768);
tool_tilt(&tool, NULL, wl_fixed_from_int(-35), wl_fixed_from_int(42));
tablet_tool_down(&tool, NULL, 1);
tool_frame(&tool, NULL, 0);
struct yasl_mouse_event ev = next(&surface);
assert(ev.kind == YASL_PTR_MOTION && ev.device == YASL_PTR_DEV_PEN);
assert(ev.pos.x == 150 && ev.pos.y == 180 && ev.pen.pressure == 32768);
assert(ev.pen.tilt_x == -35 && ev.pen.tilt_y == 42);
ev = next(&surface);
assert(ev.kind == YASL_PTR_PRESS && ev.button == 0 && ev.pen.pressure == 32768);
/* Stationary pressure and tilt changes are still motion samples. */
tool_pressure(&tool, NULL, 100000);
tool_tilt(&tool, NULL, wl_fixed_from_int(-120), wl_fixed_from_int(120));
tool_frame(&tool, NULL, 0);
ev = next(&surface);
assert(ev.kind == YASL_PTR_MOTION && ev.pen.pressure == 65535);
assert(ev.pos.x == 150 && ev.pos.y == 180);
assert(ev.pen.tilt_x == -90 && ev.pen.tilt_y == 90);
tablet_tool_up(&tool, NULL);
tool_frame(&tool, NULL, 0);
ev = next(&surface);
assert(ev.kind == YASL_PTR_RELEASE && ev.button == 0 && !ev.pen.pressure);
tool_type(&tool, NULL, ZWP_TABLET_TOOL_V2_TYPE_ERASER);
tool_pressure(&tool, NULL, 22000);
tool_frame(&tool, NULL, 0);
assert(next(&surface).device == YASL_PTR_DEV_ERASER);
tool_wheel(&tool, NULL, 0, 1);
tool_frame(&tool, NULL, 0);
ev = next(&surface);
assert(ev.kind == YASL_PTR_SCROLL && ev.device == YASL_PTR_DEV_ERASER);
assert(ev.scroll.x == 0 && ev.scroll.y == 1);
tablet_tool_proximity_out(&tool, NULL);
ev = next(&surface);
assert(ev.kind == YASL_PTR_LEAVE && ev.device == YASL_PTR_DEV_ERASER && !ev.pen.pressure);
assert(!seat.tool && !seat.tablet_focus && !seat.tool_buttons);
assert(!(yasl_display_caps(&display.base) & YASL_CAP_TABLET));
display.tablet_mgr = (void *)&display; /* Capability depends on protocol availability. */
assert(yasl_display_caps(&display.base) & YASL_CAP_TABLET);
seat.pointer_focus = &surface;
/* A compositor may describe the same detent in three ways. value120 wins,
* and both axes belong to one event, without whole-line truncation. */
pointer_axis(&seat, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(10));
pointer_axis_discrete(&seat, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 1);
pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 30);
pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -60);
pointer_frame(&seat, NULL);
ev = next(&surface);
assert(ev.kind == YASL_PTR_SCROLL && ev.device == YASL_PTR_DEV_MOUSE);
assert(ev.scroll.x == -0.5 && ev.scroll.y == 0.25);
struct yasl_input_event unused;
assert(!yasl_surface_input_poll(&surface.base, &unused));
pointer_frame(&seat, NULL);
assert(!yasl_surface_input_poll(&surface.base, &unused));
/* Stops preserve offsets from the same frame. Repeated tiny movements
* must be visible immediately rather than held until a whole detent. */
for (int i = 0; i < 3; i++) {
pointer_axis_source(&seat, NULL, WL_POINTER_AXIS_SOURCE_FINGER);
pointer_axis(&seat, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_double(1.25));
pointer_axis(&seat, NULL, 0, WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_double(-2.5));
pointer_axis_stop(&seat, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL);
pointer_frame(&seat, NULL);
ev = next(&surface);
assert(ev.scroll.x == -0.25 && ev.scroll.y == 0.125);
}
pointer_axis_discrete(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 2);
pointer_frame(&seat, NULL);
ev = next(&surface);
assert(ev.scroll.x == 2 && ev.scroll.y == 0);
pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 60);
seat_pointer_reset(&seat);
pointer_frame(&seat, NULL);
assert(!yasl_surface_input_poll(&surface.base, &unused));
input_queue_clear(&surface.input);
return 0;
}
|