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
|
#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);
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);
input_queue_clear(&surface.input);
return 0;
}
|