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/x11/test_tablet.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/x11/test_tablet.c')
| -rw-r--r-- | tests/x11/test_tablet.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/tests/x11/test_tablet.c b/tests/x11/test_tablet.c index 12c183e..243ae00 100644 --- a/tests/x11/test_tablet.c +++ b/tests/x11/test_tablet.c @@ -1,12 +1,12 @@ /* Exercise native XI2 samples through the backend and public input queue. */ #include "../../src/platform/x11/window.c" -static struct yasl_mouse_event next(struct x11_surface *surface) +static struct yasl_event next(struct x11_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; + struct yasl_event event; + assert(yasl_surface_poll_event(&surface->base, &event)); + assert(event.surface == &surface->base); + return event; } struct drag_test_recorder { @@ -166,9 +166,9 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) xi_event(d, &cookie); assert(end_reason == YASL_DRAG_CANCELLED); assert(!d->drag.active); - struct yasl_input_event reset_ev; - assert(yasl_surface_input_poll(&s->base, &reset_ev)); - assert(reset_ev.kind == YASL_INPUT_RESET); + struct yasl_event reset_ev; + assert(yasl_surface_poll_event(&s->base, &reset_ev)); + assert(reset_ev.type == YASL_EVENT_INPUT_RESET); /* 4. Drag image parameter */ uint32_t pixels[16] = {0xFF00FF00}; @@ -246,13 +246,13 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) assert(drec.leave_count == 2); assert(d->pending_drop.active); - /* Push YASL_INPUT_DROP_FILES */ - push(s, (struct yasl_input_event){.kind = YASL_INPUT_DROP_FILES}, "file:///sample.png\r\n", 20); - struct yasl_input_event drop_ev; - assert(yasl_surface_input_poll(&s->base, &drop_ev)); - assert(drop_ev.kind == YASL_INPUT_DROP_FILES); - assert(drop_ev.drop_files.len == 20); - assert(!strcmp(drop_ev.drop_files.files, "file:///sample.png\r\n")); + /* Push YASL_EVENT_DROP */ + push(s, (struct yasl_event){.type = YASL_EVENT_DROP}, "file:///sample.png\r\n", 20); + struct yasl_event drop_ev; + assert(yasl_surface_poll_event(&s->base, &drop_ev)); + assert(drop_ev.type == YASL_EVENT_DROP); + assert(drop_ev.text.len == 20); + assert(!strcmp(drop_ev.text.data, "file:///sample.png\r\n")); /* Clean up s2 */ s->next = NULL; @@ -290,10 +290,10 @@ int main(void) .mods.effective = ShiftMask, .valuators = {sizeof(mask), mask, values}}; XGenericEventCookie cookie = {.evtype = XI_ButtonPress, .data = &sample}; xi_event(&display, &cookie); - struct yasl_mouse_event ev = next(&surface); - assert(ev.kind == YASL_PTR_PRESS && ev.button == 0 && ev.device == YASL_PTR_DEV_PEN); - assert(ev.pos.x == 201 && ev.pos.y == 175 && ev.mods == YASL_MOD_SHIFT); - assert(ev.pen.pressure == 32768 && ev.pen.tilt_x == -35 && ev.pen.tilt_y == 42); + struct yasl_event ev = next(&surface); + assert(ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY && ev.pointer.device == YASL_PTR_DEV_PEN); + assert(ev.pointer.pos.x == 201 && ev.pointer.pos.y == 175 && ev.pointer.mods == YASL_MOD_SHIFT); + assert(ev.pointer.pen.pressure == 32768 && ev.pointer.pen.tilt_x == -35 && ev.pointer.pen.tilt_y == 42); /* XI2 sends only changed axes, with values packed in mask order. */ mask[0] = 0; @@ -302,14 +302,14 @@ int main(void) sample.evtype = cookie.evtype = XI_Motion; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.kind == YASL_PTR_MOTION && ev.pen.pressure == 65535); - assert(ev.pen.tilt_x == -35 && ev.pen.tilt_y == 42); + assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + assert(ev.pointer.pen.tilt_x == -35 && ev.pointer.pen.tilt_y == 42); values[0] = 5000; xi_event(&display, &cookie); - assert(next(&surface).pen.pressure == 65535); + assert(next(&surface).pointer.pen.pressure == 65535); values[0] = -50; xi_event(&display, &cookie); - assert(next(&surface).pen.pressure == 0); + assert(next(&surface).pointer.pen.pressure == 0); info.name = "Tablet ERASER"; pointer_info(&display, &pointer, &info); @@ -318,20 +318,20 @@ int main(void) sample.evtype = cookie.evtype = XI_ButtonPress; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.device == YASL_PTR_DEV_ERASER && ev.pen.pressure > 0); + assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.pointer.pen.pressure > 0); /* Release must clear pressure even when the driver omits that valuator. */ sample.valuators.mask_len = 0; sample.evtype = cookie.evtype = XI_ButtonRelease; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.kind == YASL_PTR_RELEASE && ev.button == 0 && ev.pen.pressure == 0); - assert(ev.device == YASL_PTR_DEV_ERASER); + assert(ev.type == YASL_EVENT_POINTER_UP && ev.pointer.button == YASL_BUTTON_PRIMARY && ev.pointer.pen.pressure == 0); + assert(ev.pointer.device == YASL_PTR_DEV_ERASER); XIEnterEvent crossing = {.sourceid = 8, .event = 42, .event_x = 200, .event_y = 175}; cookie = (XGenericEventCookie){.evtype = XI_Leave, .data = &crossing}; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.kind == YASL_PTR_LEAVE && ev.device == YASL_PTR_DEV_ERASER && !ev.pen.pressure); + assert(ev.type == YASL_EVENT_POINTER_LEAVE && ev.pointer.device == YASL_PTR_DEV_ERASER && !ev.pointer.pen.pressure); /* No tablet axes must produce an ordinary, pressure-free mouse. */ info.num_classes = 0; @@ -340,19 +340,19 @@ int main(void) sample.detail = 3; xi_pointer_event(&surface, &sample); ev = next(&surface); - assert(ev.device == YASL_PTR_DEV_MOUSE && ev.button == 2 && ev.pen.pressure == 0); + assert(ev.pointer.device == YASL_PTR_DEV_MOUSE && ev.pointer.button == YASL_BUTTON_SECONDARY && ev.pointer.pen.pressure == 0); for (int button = 4; button <= 7; button++) { sample.detail = button; sample.evtype = XI_ButtonPress; xi_pointer_event(&surface, &sample); ev = next(&surface); - assert(ev.kind == YASL_PTR_SCROLL); - assert(ev.scroll.x == (button == 6 ? -1 : button == 7 ? 1 : 0)); - assert(ev.scroll.y == (button == 4 ? -1 : button == 5 ? 1 : 0)); + assert(ev.type == YASL_EVENT_POINTER_SCROLL); + assert(ev.pointer.scroll.x == (button == 6 ? -1 : button == 7 ? 1 : 0)); + assert(ev.pointer.scroll.y == (button == 4 ? -1 : button == 5 ? 1 : 0)); sample.evtype = XI_ButtonRelease; xi_pointer_event(&surface, &sample); - struct yasl_input_event unused; - assert(!yasl_surface_input_poll(&surface.base, &unused)); + struct yasl_event unused; + assert(!yasl_surface_poll_event(&surface.base, &unused)); } assert(pointer_button(2) == 1 && pointer_button(8) == 3); pointer.pressure = (struct tablet_axis){2, 1, 1, 50}; |
