diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
| commit | 482f799d356a8fbb8f585c4de7cc0992b8dc6fd3 (patch) | |
| tree | 85551a69e3c356da7b9b514224e25a6c2f8d29b9 /tests/common/test_tablet_example.c | |
| parent | 537b2d768b31deb0f95c5122e0d562e4406ae9a0 (diff) | |
Migrate tests to the unified event API
Port backend, input, tablet and app tests from yasl_input_event and
YASL_INPUT_* to struct yasl_event and YASL_EVENT_*. The input allocation
test links input.c on its own, so it stubs yasl_loop_now_ns() for the new
event timestamps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/common/test_tablet_example.c')
| -rw-r--r-- | tests/common/test_tablet_example.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/tests/common/test_tablet_example.c b/tests/common/test_tablet_example.c index 77e79f6..e291b2a 100644 --- a/tests/common/test_tablet_example.c +++ b/tests/common/test_tablet_example.c @@ -3,23 +3,18 @@ #undef main #include <assert.h> -static void pointer(struct app *app, enum yasl_pointer_kind kind, - enum yasl_pointer_device device, int button, int x, int y, uint16_t pressure) +static void pointer(struct app *app, enum yasl_event_type type, + enum yasl_pointer_device device, enum yasl_pointer_button button, int x, int y, uint16_t pressure) { - struct yasl_event event = {0}; - if (kind == YASL_PTR_MOTION) { - event.type = YASL_EVENT_MOUSE_MOTION; - event.mouse_motion.pos = (struct yasl_vector2i){x, y}; - event.mouse_motion.device = device; - event.mouse_motion.pen.pressure = pressure; - } else { - event.type = YASL_EVENT_MOUSE_BUTTON; - event.mouse_button.pos = (struct yasl_vector2i){x, y}; - event.mouse_button.device = device; - event.mouse_button.button = button; - event.mouse_button.pressed = kind == YASL_PTR_PRESS; - event.mouse_button.pen.pressure = pressure; - } + struct yasl_event event = { + .type = type, + .pointer = { + .pos = (struct yasl_vector2i){x, y}, + .device = device, + .button = button, + .pen = { .pressure = pressure }, + }, + }; input(app, &event); } @@ -27,36 +22,36 @@ int main(void) { struct app app = {0}; assert(resize_canvas(&app, (struct yasl_geometry){{400, 300}, 120})); - pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 3, 80, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_BACK, 80, 160, 65535); /* Hover never paints. */ assert(app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER); - pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_PEN, 2, 80, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_PEN, YASL_BUTTON_SECONDARY, 80, 160, 65535); /* Side button isn't the tip. */ assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER); - pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_PEN, 0, 80, 160, 0); + pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 80, 160, 0); assert(app.down && app.canvas[(size_t)160 * app.geometry.size.x + 80] == INK && app.canvas[(size_t)160 * app.geometry.size.x + 90] == PAPER); - pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 0, 80, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 80, 160, 65535); /* Stationary pressure widens brush. */ assert(app.canvas[(size_t)160 * app.geometry.size.x + 100] == INK); - pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 0, 180, 160, 20000); + pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 180, 160, 20000); /* Segments are continuous. */ assert(app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK); - pointer(&app, YASL_PTR_RELEASE, YASL_PTR_DEV_PEN, 0, 180, 160, 0); - pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 3, 250, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_UP, YASL_PTR_DEV_PEN, YASL_BUTTON_PRIMARY, 180, 160, 0); + pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_PEN, YASL_BUTTON_BACK, 250, 160, 65535); assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 250] == PAPER); - pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_ERASER, 0, 80, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_ERASER, YASL_BUTTON_PRIMARY, 80, 160, 65535); assert(app.canvas[(size_t)160 * app.geometry.size.x + 80] == PAPER && app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK); struct yasl_event reset = {.type = YASL_EVENT_INPUT_RESET}; input(&app, &reset); - pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_ERASER, 0, 130, 160, 65535); + pointer(&app, YASL_EVENT_POINTER_MOTION, YASL_PTR_DEV_ERASER, YASL_BUTTON_PRIMARY, 130, 160, 65535); assert(!app.down && app.canvas[(size_t)160 * app.geometry.size.x + 130] == INK); - pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_MOUSE, 0, 300, 200, 0); + pointer(&app, YASL_EVENT_POINTER_DOWN, YASL_PTR_DEV_MOUSE, YASL_BUTTON_PRIMARY, 300, 200, 0); assert(app.canvas[(size_t)200 * app.geometry.size.x + 300] == INK); - struct yasl_event blur = {.type = YASL_EVENT_WINDOW_FOCUS, .focus.focused = false}; + struct yasl_event blur = {.type = YASL_EVENT_FOCUS, .focus.focused = false}; input(&app, &blur); assert(!app.down); assert(resize_canvas(&app, (struct yasl_geometry){{800, 600}, 240})); |
