diff options
Diffstat (limited to 'tests/wayland/test_tablet.c')
| -rw-r--r-- | tests/wayland/test_tablet.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/wayland/test_tablet.c b/tests/wayland/test_tablet.c new file mode 100644 index 0000000..449c446 --- /dev/null +++ b/tests/wayland/test_tablet.c @@ -0,0 +1,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; +} |
