summaryrefslogtreecommitdiff
path: root/tests/x11
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
commit482f799d356a8fbb8f585c4de7cc0992b8dc6fd3 (patch)
tree85551a69e3c356da7b9b514224e25a6c2f8d29b9 /tests/x11
parent537b2d768b31deb0f95c5122e0d562e4406ae9a0 (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')
-rw-r--r--tests/x11/test_input.c30
-rw-r--r--tests/x11/test_tablet.c66
-rw-r--r--tests/x11/test_tablet_native.c30
3 files changed, 53 insertions, 73 deletions
diff --git a/tests/x11/test_input.c b/tests/x11/test_input.c
index 80a6451..bbcbf45 100644
--- a/tests/x11/test_input.c
+++ b/tests/x11/test_input.c
@@ -54,14 +54,14 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface *
PropModeReplace, (const unsigned char *)cases[i].bytes, (int)cases[i].len);
XSelectionEvent reply = {.requestor = pending->window, .property = property};
selection_notify(d, &reply);
- struct yasl_input_event event;
+ struct yasl_event event;
if (cases[i].expected) {
- assert(yasl_surface_input_poll(&s->base, &event));
- assert(event.kind == YASL_INPUT_PASTE);
- assert(event.paste.len == strlen(cases[i].expected));
- assert(strcmp(event.paste.text, cases[i].expected) == 0);
+ assert(yasl_surface_poll_event(&s->base, &event));
+ assert(event.type == YASL_EVENT_PASTE);
+ assert(event.text.len == strlen(cases[i].expected));
+ assert(strcmp(event.text.data, cases[i].expected) == 0);
}
- assert(!yasl_surface_input_poll(&s->base, &event));
+ assert(!yasl_surface_poll_event(&s->base, &event));
}
}
@@ -98,18 +98,18 @@ int main(void)
XKeyEvent native = {.type = KeyPress, .display = d->native,
.window = s->window, .keycode = code};
key_event(s, &native, false);
- struct yasl_input_event event;
- assert(yasl_surface_input_poll(surface, &event));
- assert(event.kind == YASL_INPUT_KEY && event.key.key == YASL_KEY_A);
+ struct yasl_event event;
+ assert(yasl_surface_poll_event(surface, &event));
+ assert(event.type == YASL_EVENT_KEY && event.key.key == YASL_KEY_A);
assert(event.key.codepoint == cases[i].label);
- assert(yasl_surface_input_poll(surface, &event));
- assert(event.kind == YASL_INPUT_TEXT && event.text.len == strlen(cases[i].text));
- assert(strcmp(event.text.text, cases[i].text) == 0);
- assert(!yasl_surface_input_poll(surface, &event));
+ assert(yasl_surface_poll_event(surface, &event));
+ assert(event.type == YASL_EVENT_TEXT && event.text.len == strlen(cases[i].text));
+ assert(strcmp(event.text.data, cases[i].text) == 0);
+ assert(!yasl_surface_poll_event(surface, &event));
native.type = KeyRelease;
key_event(s, &native, false);
- assert(yasl_surface_input_poll(surface, &event) && event.kind == YASL_INPUT_KEY);
- assert(!yasl_surface_input_poll(surface, &event));
+ assert(yasl_surface_poll_event(surface, &event) && event.type == YASL_EVENT_KEY);
+ assert(!yasl_surface_poll_event(surface, &event));
}
XChangeKeyboardMapping(d->native, code, width, saved, 1);
XSync(d->native, False);
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};
diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c
index 078606a..b0d1366 100644
--- a/tests/x11/test_tablet_native.c
+++ b/tests/x11/test_tablet_native.c
@@ -70,32 +70,12 @@ static void native_draw(struct yasl_surface *surface, struct yasl_frame *frame,
static void native_configure(struct yasl_surface *surface, struct yasl_geometry geometry, void *ud)
{
input(ud, &(struct yasl_event){.surface = surface, .type = YASL_EVENT_WINDOW_RESIZE,
- .resize = {.size = geometry.size, .scale_120 = geometry.scale_120}});
+ .resize = {.geometry = geometry}});
}
-static void native_input(struct app *app, const struct yasl_input_event *raw)
+static void native_input(struct app *app, const struct yasl_event *event)
{
- struct yasl_event event = {.surface = raw->surface};
- if (raw->kind == YASL_INPUT_RESET) event.type = YASL_EVENT_INPUT_RESET;
- else if (raw->kind == YASL_INPUT_FOCUS) {
- event.type = YASL_EVENT_WINDOW_FOCUS;
- event.focus.focused = raw->focus.focused;
- } else if (raw->kind == YASL_INPUT_MOUSE) {
- if (raw->mouse.kind == YASL_PTR_MOTION) {
- event.type = YASL_EVENT_MOUSE_MOTION;
- event.mouse_motion.pos = raw->mouse.pos;
- event.mouse_motion.device = raw->mouse.device;
- event.mouse_motion.pen = raw->mouse.pen;
- } else if (raw->mouse.kind == YASL_PTR_PRESS || raw->mouse.kind == YASL_PTR_RELEASE) {
- event.type = YASL_EVENT_MOUSE_BUTTON;
- event.mouse_button.pos = raw->mouse.pos;
- event.mouse_button.device = raw->mouse.device;
- event.mouse_button.button = raw->mouse.button;
- event.mouse_button.pressed = raw->mouse.kind == YASL_PTR_PRESS;
- event.mouse_button.pen = raw->mouse.pen;
- } else if (raw->mouse.kind == YASL_PTR_LEAVE) event.type = YASL_EVENT_MOUSE_LEAVE;
- }
- input(app, &event);
+ input(app, event);
}
static void pump(int fd, struct yasl_display *display, struct yasl_surface *surface, struct app *app)
@@ -109,8 +89,8 @@ static void pump(int fd, struct yasl_display *display, struct yasl_surface *surf
* Round-trip on YASL's X connection before draining its event queue. */
XSync(yasl_display_get_native_handle(display), False);
assert(yasl_display_dispatch(display, 0) == 0);
- struct yasl_input_event event;
- while (yasl_surface_input_poll(surface, &event)) {
+ struct yasl_event event;
+ while (yasl_surface_poll_event(surface, &event)) {
native_input(app, &event);
yasl_surface_schedule_redraw(surface);
}