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 | |
| 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')
| -rw-r--r-- | tests/benchmark.c | 14 | ||||
| -rw-r--r-- | tests/cocoa/test_cursor.m | 6 | ||||
| -rw-r--r-- | tests/cocoa/test_keyboard.m | 43 | ||||
| -rw-r--r-- | tests/cocoa/test_ownership.m | 16 | ||||
| -rw-r--r-- | tests/cocoa/test_tablet.m | 42 | ||||
| -rw-r--r-- | tests/common/test_app.c | 12 | ||||
| -rw-r--r-- | tests/common/test_backends.c | 86 | ||||
| -rw-r--r-- | tests/common/test_contracts.c | 36 | ||||
| -rw-r--r-- | tests/common/test_input_alloc.c | 15 | ||||
| -rw-r--r-- | tests/common/test_tablet_example.c | 49 | ||||
| -rw-r--r-- | tests/test_api.cpp | 8 | ||||
| -rw-r--r-- | tests/wayland/test_app_input.c | 46 | ||||
| -rw-r--r-- | tests/wayland/test_cursor.c | 16 | ||||
| -rw-r--r-- | tests/wayland/test_input.c | 8 | ||||
| -rw-r--r-- | tests/wayland/test_keyboard.c | 60 | ||||
| -rw-r--r-- | tests/wayland/test_tablet.c | 52 | ||||
| -rw-r--r-- | tests/x11/test_input.c | 30 | ||||
| -rw-r--r-- | tests/x11/test_tablet.c | 66 | ||||
| -rw-r--r-- | tests/x11/test_tablet_native.c | 30 |
19 files changed, 304 insertions, 331 deletions
diff --git a/tests/benchmark.c b/tests/benchmark.c index 7431715..1cea614 100644 --- a/tests/benchmark.c +++ b/tests/benchmark.c @@ -135,9 +135,9 @@ static void bench_input_queue_resize(void) { for (int b = 0; b < batches; b++) { struct input_queue q = {0}; for (int i = 0; i < size; i++) { - struct yasl_input_event ev = { - .kind = YASL_INPUT_MOUSE, - .mouse = { .pos = { .x = i, .y = b } }, + struct yasl_event ev = { + .type = YASL_EVENT_POINTER_MOTION, + .pointer = { .pos = { .x = i, .y = b } }, }; input_queue_push(&q, &ev); } @@ -160,13 +160,13 @@ static void bench_input_queue_push_pop(void) { uint64_t t0 = get_time_ns(); for (int r = 0; r < rounds; r++) { for (int i = 0; i < events_per_round; i++) { - struct yasl_input_event ev = { - .kind = YASL_INPUT_MOUSE, - .mouse = { .pos = { .x = i, .y = r }, .button = 1 }, + struct yasl_event ev = { + .type = YASL_EVENT_POINTER_DOWN, + .pointer = { .pos = { .x = i, .y = r }, .button = YASL_BUTTON_MIDDLE }, }; input_queue_push(&q, &ev); } - struct yasl_input_event out; + struct yasl_event out; while (input_queue_pop(&q, &out)) { /* consume */ } diff --git a/tests/cocoa/test_cursor.m b/tests/cocoa/test_cursor.m index aaca815..4054d59 100644 --- a/tests/cocoa/test_cursor.m +++ b/tests/cocoa/test_cursor.m @@ -37,10 +37,10 @@ int main(void) [view mouseMoved:motion]; [view cursorUpdate:cursor]; assert([NSCursor currentCursor] == hidden); - struct yasl_input_event event; + struct yasl_event event; bool moved = false; - while (yasl_surface_input_poll(surface, &event)) - if (event.kind == YASL_INPUT_MOUSE && event.mouse.kind == YASL_PTR_MOTION) + while (yasl_surface_poll_event(surface, &event)) + if (event.type == YASL_EVENT_POINTER_MOTION) moved = true; assert(moved); diff --git a/tests/cocoa/test_keyboard.m b/tests/cocoa/test_keyboard.m index d6a1336..f93a745 100644 --- a/tests/cocoa/test_keyboard.m +++ b/tests/cocoa/test_keyboard.m @@ -31,18 +31,18 @@ } @end -static struct yasl_input_event next(struct yasl_surface *surface, enum yasl_input_kind kind) +static struct yasl_event next(struct yasl_surface *surface, enum yasl_event_type type) { - struct yasl_input_event event; - assert(yasl_surface_input_poll(surface, &event)); - assert(event.kind == kind && event.surface == surface); + struct yasl_event event; + assert(yasl_surface_poll_event(surface, &event)); + assert(event.type == type && event.surface == surface); return event; } static void empty(struct yasl_surface *surface) { - struct yasl_input_event event; - assert(!yasl_surface_input_poll(surface, &event)); + struct yasl_event event; + assert(!yasl_surface_poll_event(surface, &event)); } int main(void) @@ -55,8 +55,8 @@ int main(void) assert(surface); NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); NSView<NSTextInputClient> *view = (id)window.contentView; - struct yasl_input_event event; - while (yasl_surface_input_poll(surface, &event)) {} + struct yasl_event event; + while (yasl_surface_poll_event(surface, &event)) {} InputSample *sample = [InputSample new]; NSEvent *native = (NSEvent *)sample; @@ -65,7 +65,7 @@ int main(void) sample.label = @"q"; sample.shiftedLabel = @"Q"; [view keyUp:native]; - event = next(surface, YASL_INPUT_KEY); + event = next(surface, YASL_EVENT_KEY); assert(event.key.key == YASL_KEY_A && event.key.native_code == 0); assert(event.key.action == YASL_KEY_RELEASE); assert(event.key.codepoint == 'q' && event.key.shifted == 'Q'); @@ -73,18 +73,18 @@ int main(void) sample.label = @"😀"; /* One scalar, two UTF-16 units. */ sample.shiftedLabel = @"ab"; [view keyUp:native]; - event = next(surface, YASL_INPUT_KEY); + event = next(surface, YASL_EVENT_KEY); assert(event.key.codepoint == 0x1f600 && event.key.shifted == 0); sample.type = NSEventTypeFlagsChanged; sample.keyCode = 56; /* Left Shift. */ sample.modifierFlags = NSEventModifierFlagShift | 0x0002; [view flagsChanged:native]; - event = next(surface, YASL_INPUT_KEY); + event = next(surface, YASL_EVENT_KEY); assert(event.key.key == YASL_KEY_LEFT_SHIFT && event.key.action == YASL_KEY_PRESS); assert(event.key.mods == YASL_MOD_SHIFT && !event.key.codepoint && !event.key.shifted); sample.modifierFlags = 0; [view flagsChanged:native]; - assert(next(surface, YASL_INPUT_KEY).key.action == YASL_KEY_RELEASE); + assert(next(surface, YASL_EVENT_KEY).key.action == YASL_KEY_RELEASE); /* Native text services own preedit and commits. Marked text is not an * insertion, and commits retain all UTF-8 bytes, including non-BMP. */ @@ -93,8 +93,8 @@ int main(void) assert(strcmp(yasl_surface_ime_preedit(surface), "é") == 0); empty(surface); [view insertText:@"😀é" replacementRange:NSMakeRange(NSNotFound, 0)]; - event = next(surface, YASL_INPUT_TEXT); - assert(event.text.len == strlen("😀é") && strcmp(event.text.text, "😀é") == 0); + event = next(surface, YASL_EVENT_TEXT); + assert(event.text.len == strlen("😀é") && strcmp(event.text.data, "😀é") == 0); assert(!yasl_surface_ime_preedit(surface)); empty(surface); @@ -104,9 +104,9 @@ int main(void) modifierFlags:0 timestamp:0 windowNumber:window.windowNumber context:nil characters:@"a" charactersIgnoringModifiers:@"a" isARepeat:NO keyCode:0]; [view keyDown:press]; - assert(next(surface, YASL_INPUT_KEY).key.key == YASL_KEY_A); - event = next(surface, YASL_INPUT_TEXT); - assert(event.text.len == 1 && event.text.text[0] == 'a'); + assert(next(surface, YASL_EVENT_KEY).key.key == YASL_KEY_A); + event = next(surface, YASL_EVENT_TEXT); + assert(event.text.len == 1 && event.text.data[0] == 'a'); empty(surface); sample.type = NSEventTypeScrollWheel; @@ -114,15 +114,14 @@ int main(void) sample.scrollingDeltaX = -2.5; sample.scrollingDeltaY = 1.25; [view scrollWheel:native]; - event = next(surface, YASL_INPUT_MOUSE); - assert(event.mouse.kind == YASL_PTR_SCROLL); - assert(event.mouse.scroll.x == 0.25 && event.mouse.scroll.y == -0.125); + event = next(surface, YASL_EVENT_POINTER_SCROLL); + assert(event.pointer.scroll.x == 0.25 && event.pointer.scroll.y == -0.125); sample.hasPreciseScrollingDeltas = NO; sample.scrollingDeltaX = 1; sample.scrollingDeltaY = -1; [view scrollWheel:native]; - event = next(surface, YASL_INPUT_MOUSE); - assert(event.mouse.scroll.x == -1 && event.mouse.scroll.y == 1); + event = next(surface, YASL_EVENT_POINTER_SCROLL); + assert(event.pointer.scroll.x == -1 && event.pointer.scroll.y == 1); sample.scrollingDeltaX = NAN; [view scrollWheel:native]; empty(surface); diff --git a/tests/cocoa/test_ownership.m b/tests/cocoa/test_ownership.m index 4e3bbd6..5fd5cbf 100644 --- a/tests/cocoa/test_ownership.m +++ b/tests/cocoa/test_ownership.m @@ -19,8 +19,8 @@ int main(void) assert(yasl_cocoa_surface_get_window(s) == window); assert(yasl_cocoa_surface_get_view(s) == window.contentView); assert([window isKindOfClass:[NSWindow class]] && window.contentView); - struct yasl_input_event event; - while (yasl_surface_input_poll(s, &event)) {} + struct yasl_event event; + while (yasl_surface_poll_event(s, &event)) {} @autoreleasepool { for (int i = 0; i < 600; i++) { char text[32]; @@ -34,19 +34,19 @@ int main(void) for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "paste-%d", i); - assert(yasl_surface_input_poll(s, &event)); - assert(event.kind == YASL_INPUT_PASTE && strcmp(event.paste.text, text) == 0); + assert(yasl_surface_poll_event(s, &event)); + assert(event.type == YASL_EVENT_PASTE && strcmp(event.text.data, text) == 0); } - const char *last = event.paste.text; - assert(!yasl_surface_input_poll(s, &event)); + const char *last = event.text.data; + assert(!yasl_surface_poll_event(s, &event)); @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, "new selection"); } assert(strcmp(last, "paste-599") == 0); @autoreleasepool { yasl_display_copy(d, YASL_CLIPBOARD, ""); yasl_display_paste(d, YASL_CLIPBOARD, s); } - assert(yasl_surface_input_poll(s, &event)); - assert(event.kind == YASL_INPUT_PASTE && !event.paste.len && !event.paste.text[0]); + assert(yasl_surface_poll_event(s, &event)); + assert(event.type == YASL_EVENT_PASTE && !event.text.len && !event.text.data[0]); yasl_surface_destroy(s); yasl_display_close(d); return 0; diff --git a/tests/cocoa/test_tablet.m b/tests/cocoa/test_tablet.m index ed6dc64..715a66e 100644 --- a/tests/cocoa/test_tablet.m +++ b/tests/cocoa/test_tablet.m @@ -35,13 +35,13 @@ } @end -static struct yasl_mouse_event next(struct yasl_surface *surface) +static struct yasl_event next(struct yasl_surface *surface) { - struct yasl_input_event event; - while (yasl_surface_input_poll(surface, &event)) - if (event.kind == YASL_INPUT_MOUSE) return event.mouse; + struct yasl_event event; + while (yasl_surface_poll_event(surface, &event)) + return event; assert(!"Expected a pointer event"); - return (struct yasl_mouse_event){0}; + return (struct yasl_event){0}; } int main(void) @@ -54,8 +54,8 @@ int main(void) assert(surface); NSWindow *window = (NSWindow *)yasl_surface_get_native_handle(surface); NSView *view = window.contentView; - struct yasl_input_event event; - while (yasl_surface_input_poll(surface, &event)) {} + struct yasl_event event; + while (yasl_surface_poll_event(surface, &event)) {} TabletSample *sample = [TabletSample new]; NSEvent *native = (NSEvent *)sample; sample.type = NSEventTypeTabletProximity; @@ -67,16 +67,16 @@ int main(void) sample.locationInWindow = NSMakePoint(100, 120); sample.sampleTilt = NSMakePoint(-0.5, 0.5); [view mouseMoved:native]; - struct yasl_mouse_event ev = next(surface); - assert(ev.device == YASL_PTR_DEV_PEN && ev.kind == YASL_PTR_MOTION && !ev.pen.pressure); - assert(ev.pen.tilt_x == -45 && ev.pen.tilt_y == -45); + struct yasl_event ev = next(surface); + assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_MOTION && !ev.pointer.pen.pressure); + assert(ev.pointer.pen.tilt_x == -45 && ev.pointer.pen.tilt_y == -45); sample.type = NSEventTypeLeftMouseDown; sample.samplePressure = 0.5; [view mouseDown:native]; ev = next(surface); - assert(ev.device == YASL_PTR_DEV_PEN && ev.kind == YASL_PTR_PRESS && ev.button == 0); - assert(ev.pen.pressure == 32767); - struct yasl_vector2i position = ev.pos; + assert(ev.pointer.device == YASL_PTR_DEV_PEN && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY); + assert(ev.pointer.pen.pressure == 32767); + struct yasl_vector2i position = ev.pointer.pos; /* Native tablet events cover stationary pressure changes. */ sample.type = NSEventTypeTabletPoint; sample.subtype = NSEventSubtypeMouseEvent; @@ -84,19 +84,19 @@ int main(void) sample.samplePressure = 1.5; [view tabletPoint:native]; ev = next(surface); - assert(ev.kind == YASL_PTR_MOTION && ev.pen.pressure == 65535); - assert(ev.pos.x == position.x && ev.pos.y == position.y); + assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + assert(ev.pointer.pos.x == position.x && ev.pointer.pos.y == position.y); sample.samplePressure = 0; /* Zero does not release a held tip button. */ [view tabletPoint:native]; - assert(next(surface).kind == YASL_PTR_MOTION); + assert(next(surface).type == YASL_EVENT_POINTER_MOTION); sample.buttonMask = 0; [view tabletPoint:native]; ev = next(surface); - assert(ev.kind == YASL_PTR_RELEASE && !ev.pen.pressure && ev.device == YASL_PTR_DEV_PEN); + assert(ev.type == YASL_EVENT_POINTER_UP && !ev.pointer.pen.pressure && ev.pointer.device == YASL_PTR_DEV_PEN); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; - assert(next(surface).kind == YASL_PTR_LEAVE); + assert(next(surface).type == YASL_EVENT_POINTER_LEAVE); sample.enteringProximity = YES; sample.tool = NSPointingDeviceTypeEraser; [view tabletProximity:native]; @@ -105,16 +105,16 @@ int main(void) sample.buttonMask = NSEventButtonMaskPenTip; [view tabletPoint:native]; ev = next(surface); - assert(ev.device == YASL_PTR_DEV_ERASER && ev.kind == YASL_PTR_PRESS && ev.pen.pressure > 0); + assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.pen.pressure > 0); sample.type = NSEventTypeTabletProximity; sample.enteringProximity = NO; [view tabletProximity:native]; ev = next(surface); - assert(ev.device == YASL_PTR_DEV_ERASER && ev.kind == YASL_PTR_LEAVE && !ev.pen.pressure); + assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.type == YASL_EVENT_POINTER_LEAVE && !ev.pointer.pen.pressure); sample.type = NSEventTypeMouseMoved; [view mouseMoved:native]; ev = next(surface); - assert(ev.device == YASL_PTR_DEV_MOUSE && !ev.pen.pressure); + assert(ev.pointer.device == YASL_PTR_DEV_MOUSE && !ev.pointer.pen.pressure); [sample release]; yasl_surface_destroy(surface); yasl_display_close(display); diff --git a/tests/common/test_app.c b/tests/common/test_app.c index 23c9a93..6972921 100644 --- a/tests/common/test_app.c +++ b/tests/common/test_app.c @@ -37,7 +37,7 @@ static uint64_t on_timer(void *ud, yasl_timer_id id, uint64_t interval_ns) return 0; /* one-shot */ } -static int on_init(void *ud, struct yasl_display *d) +static enum yasl_app_result on_init(void *ud, struct yasl_display *d) { struct test_state *state = ud; state->display = d; @@ -51,8 +51,8 @@ static int on_init(void *ud, struct yasl_display *d) assert(state->surface != NULL); yasl_surface_set_pacing(state->surface, YASL_PACING_ON_DEMAND); - yasl_surface_set_mouse_mode(state->surface, YASL_MOUSE_RELATIVE); - yasl_surface_set_mouse_mode(state->surface, YASL_MOUSE_NORMAL); + yasl_surface_set_pointer_mode(state->surface, YASL_POINTER_RELATIVE); + yasl_surface_set_pointer_mode(state->surface, YASL_POINTER_NORMAL); state->timer_id = yasl_app_add_timer(d, YASL_MS_TO_NS(20), on_timer, state); assert(state->timer_id > 0); @@ -66,15 +66,15 @@ static int on_init(void *ud, struct yasl_display *d) return YASL_APP_CONTINUE; } -static int on_event(void *ud, const struct yasl_event *ev) +static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev) { struct test_state *state = ud; if (ev->type == YASL_EVENT_USER) { - assert(ev->user.type == 42); + assert(ev->user.code == 42); assert(ev->user.payload == (void *)0x1234); state->user_event_called = true; yasl_surface_request_frame(state->surface); - } else if (ev->type == YASL_EVENT_WINDOW_CLOSE_REQUEST) { + } else if (ev->type == YASL_EVENT_WINDOW_CLOSE) { return YASL_APP_QUIT; } return YASL_APP_CONTINUE; diff --git a/tests/common/test_backends.c b/tests/common/test_backends.c index 28f2f52..74860c8 100644 --- a/tests/common/test_backends.c +++ b/tests/common/test_backends.c @@ -191,17 +191,17 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct assert(size.x == 200 && size.y == 120); /* A server-generated motion verifies the XI2 subscription and cookie * dispatch path, including source-device lookup, rather than SendEvent. */ - struct yasl_input_event pointer_event; - while (yasl_surface_input_poll(w->surface, &pointer_event)) {} + struct yasl_event pointer_event; + while (yasl_surface_poll_event(w->surface, &pointer_event)) {} XWarpPointer(native, None, window, 0, 0, 0, 0, 80, 50); XFlush(native); pump(loop, d, NULL); bool saw_motion = false; - while (yasl_surface_input_poll(w->surface, &pointer_event)) { - if (pointer_event.kind == YASL_INPUT_MOUSE && pointer_event.mouse.kind == YASL_PTR_MOTION) { - assert(pointer_event.mouse.device == YASL_PTR_DEV_MOUSE); - assert(!pointer_event.mouse.pen.pressure); - if (pointer_event.mouse.pos.x == 80 && pointer_event.mouse.pos.y == 50) + while (yasl_surface_poll_event(w->surface, &pointer_event)) { + if (pointer_event.type == YASL_EVENT_POINTER_MOTION) { + assert(pointer_event.pointer.device == YASL_PTR_DEV_MOUSE); + assert(!pointer_event.pointer.pen.pressure); + if (pointer_event.pointer.pos.x == 80 && pointer_event.pointer.pos.y == 50) saw_motion = true; } } @@ -216,22 +216,22 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct yasl_display_paste(d, YASL_CLIPBOARD, w->surface); pump(loop, d, NULL); bool saw_key = false, saw_paste = false, saw_text = false; - struct yasl_input_event event; - while (yasl_surface_input_poll(w->surface, &event)) { + struct yasl_event event; + while (yasl_surface_poll_event(w->surface, &event)) { assert(event.surface == w->surface); - if (event.kind == YASL_INPUT_KEY) { + if (event.type == YASL_EVENT_KEY) { assert(event.key.codepoint == 'a'); assert(event.key.shifted == 'A'); assert(event.key.native_code == key.xkey.keycode); saw_key = event.key.key == YASL_KEY_A; } - if (event.kind == YASL_INPUT_PASTE) { - assert(event.paste.len == strlen("clipboard text")); - assert(memcmp(event.paste.text, "clipboard text", event.paste.len) == 0); + if (event.type == YASL_EVENT_PASTE) { + assert(event.text.len == strlen("clipboard text")); + assert(memcmp(event.text.data, "clipboard text", event.text.len) == 0); saw_paste = true; } - if (event.kind == YASL_INPUT_TEXT) { - assert(event.text.len == 1 && event.text.text[0] == 'a'); + if (event.type == YASL_EVENT_TEXT) { + assert(event.text.len == 1 && event.text.data[0] == 'a'); saw_text = true; } } @@ -246,13 +246,13 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct XFlush(native); pump(loop, d, NULL); int key_count = 0, text_count = 0; - while (yasl_surface_input_poll(w->surface, &event)) { - if (event.kind == YASL_INPUT_KEY) { + while (yasl_surface_poll_event(w->surface, &event)) { + if (event.type == YASL_EVENT_KEY) { assert(event.key.key == YASL_KEY_A); assert(event.key.action == (key_count ? YASL_KEY_RELEASE : YASL_KEY_PRESS)); key_count++; - } else if (event.kind == YASL_INPUT_TEXT) { - assert(event.text.len == 1 && event.text.text[0] == 'A'); + } else if (event.type == YASL_EVENT_TEXT) { + assert(event.text.len == 1 && event.text.data[0] == 'A'); text_count++; } } @@ -262,10 +262,10 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct XSendEvent(native, window, False, KeyPressMask, &key); XFlush(native); pump(loop, d, NULL); - assert(yasl_surface_input_poll(w->surface, &event)); - assert(event.kind == YASL_INPUT_KEY && event.key.key == YASL_KEY_A); + assert(yasl_surface_poll_event(w->surface, &event)); + assert(event.type == YASL_EVENT_KEY && event.key.key == YASL_KEY_A); assert(event.key.mods & YASL_MOD_CTRL); - assert(!yasl_surface_input_poll(w->surface, &event)); + assert(!yasl_surface_poll_event(w->surface, &event)); int symbols_per_key = 0; KeySym *saved_symbols = XGetKeyboardMapping(native, key.xkey.keycode, 1, &symbols_per_key); @@ -282,12 +282,12 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct XFlush(native); pump(loop, d, NULL); saw_key = saw_text = false; - while (yasl_surface_input_poll(w->surface, &event)) { - if (event.kind == YASL_INPUT_KEY) { + while (yasl_surface_poll_event(w->surface, &event)) { + if (event.type == YASL_EVENT_KEY) { assert(event.key.key == YASL_KEY_A && event.key.codepoint == 'q'); saw_key = true; - } else if (event.kind == YASL_INPUT_TEXT) { - assert(event.text.len == 1 && event.text.text[0] == 'q'); + } else if (event.type == YASL_EVENT_TEXT) { + assert(event.text.len == 1 && event.text.data[0] == 'q'); saw_text = true; } } @@ -308,11 +308,11 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct XSendEvent(native, window, False, NoEventMask, &wheel); XFlush(native); pump(loop, d, NULL); - assert(yasl_surface_input_poll(w->surface, &event)); - assert(event.kind == YASL_INPUT_MOUSE && event.mouse.kind == YASL_PTR_SCROLL); - assert(event.mouse.scroll.x == (button == 6 ? -1 : button == 7 ? 1 : 0)); - assert(event.mouse.scroll.y == (button == 4 ? -1 : button == 5 ? 1 : 0)); - assert(!yasl_surface_input_poll(w->surface, &event)); + assert(yasl_surface_poll_event(w->surface, &event)); + assert(event.type == YASL_EVENT_POINTER_SCROLL); + assert(event.pointer.scroll.x == (button == 6 ? -1 : button == 7 ? 1 : 0)); + assert(event.pointer.scroll.y == (button == 4 ? -1 : button == 5 ? 1 : 0)); + assert(!yasl_surface_poll_event(w->surface, &event)); } assert(yasl_surface_timing(w->surface).source == YASL_TIMING_SUBMISSION); assert(!(yasl_display_caps(d) & YASL_CAP_FRAME_PACING)); @@ -329,18 +329,18 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct for (int i = 0; i < 300; i++) { char text[32]; snprintf(text, sizeof(text), "owned-%d", i); - assert(yasl_surface_input_poll(w->surface, &event)); - assert(event.kind == YASL_INPUT_PASTE && strcmp(event.paste.text, text) == 0); + assert(yasl_surface_poll_event(w->surface, &event)); + assert(event.type == YASL_EVENT_PASTE && strcmp(event.text.data, text) == 0); } - const char *last = event.paste.text; - assert(!yasl_surface_input_poll(w->surface, &event)); + const char *last = event.text.data; + assert(!yasl_surface_poll_event(w->surface, &event)); yasl_display_copy(d, YASL_CLIPBOARD, "changed"); pump(loop, d, NULL); assert(strcmp(last, "owned-299") == 0); yasl_display_copy(d, YASL_CLIPBOARD, ""); yasl_display_paste(d, YASL_CLIPBOARD, w->surface); - assert(yasl_surface_input_poll(w->surface, &event)); - assert(event.kind == YASL_INPUT_PASTE && !event.paste.len && !event.paste.text[0]); + assert(yasl_surface_poll_event(w->surface, &event)); + assert(event.type == YASL_EVENT_PASTE && !event.text.len && !event.text.data[0]); /* Concurrent external conversions must not share a mutable target slot. */ struct yasl_display_spec ds = {.backend = YASL_BACKEND_X11}; @@ -354,15 +354,15 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct yasl_surface_destroy(cancelled.surface); pump(loop, d, owner); int first_pastes = 0, second_pastes = 0; - while (yasl_surface_input_poll(w->surface, &event)) { - if (event.kind == YASL_INPUT_PASTE) { - assert(strcmp(event.paste.text, "external") == 0); + while (yasl_surface_poll_event(w->surface, &event)) { + if (event.type == YASL_EVENT_PASTE) { + assert(strcmp(event.text.data, "external") == 0); first_pastes++; } } - while (yasl_surface_input_poll(other.surface, &event)) { - if (event.kind == YASL_INPUT_PASTE) { - assert(strcmp(event.paste.text, "external") == 0); + while (yasl_surface_poll_event(other.surface, &event)) { + if (event.type == YASL_EVENT_PASTE) { + assert(strcmp(event.text.data, "external") == 0); second_pastes++; } } diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c index ee6fe61..7c1ab06 100644 --- a/tests/common/test_contracts.c +++ b/tests/common/test_contracts.c @@ -37,31 +37,27 @@ static void test_queue(void) { struct input_queue q = {0}; struct yasl_surface surface = {0}; - const enum yasl_input_kind kinds[] = { - YASL_INPUT_TEXT, YASL_INPUT_PASTE, YASL_INPUT_DROP_FILES, + const enum yasl_event_type kinds[] = { + YASL_EVENT_TEXT, YASL_EVENT_PASTE, YASL_EVENT_DROP, }; for (size_t k = 0; k < sizeof(kinds) / sizeof(kinds[0]); k++) { char *source = malloc(4); assert(source); memcpy(source, "a\0b", 4); - struct yasl_input_event in = {.surface = &surface, .kind = kinds[k]}; - if (in.kind == YASL_INPUT_TEXT) { in.text.text = source; in.text.len = 3; } - if (in.kind == YASL_INPUT_PASTE) { in.paste.text = source; in.paste.len = 3; } - if (in.kind == YASL_INPUT_DROP_FILES) { in.drop_files.files = source; in.drop_files.len = 3; } + struct yasl_event in = {.surface = &surface, .type = kinds[k], .text = {.data = source, .len = 3}}; assert(input_queue_push(&q, &in)); memset(source, 'x', 4); free(source); - struct yasl_input_event out; + struct yasl_event out; assert(input_queue_pop(&q, &out)); - const char *payload = out.kind == YASL_INPUT_TEXT ? out.text.text : - out.kind == YASL_INPUT_PASTE ? out.paste.text : out.drop_files.files; - assert(out.surface == &surface && out.kind == kinds[k]); + const char *payload = out.text.data; + assert(out.surface == &surface && out.type == kinds[k]); assert(memcmp(payload, "a\0b", 4) == 0); assert(!input_queue_pop(&q, &out)); assert(memcmp(payload, "a\0b", 4) == 0); /* Growth/wraparound must not invalidate a previously polled payload. */ for (unsigned i = 0; i < 4096; i++) { - in = (struct yasl_input_event){.kind = YASL_INPUT_KEY, .key.key = i}; + in = (struct yasl_event){.type = YASL_EVENT_KEY, .key.key = i}; assert(input_queue_push(&q, &in)); } assert(memcmp(payload, "a\0b", 4) == 0); @@ -79,28 +75,28 @@ static void test_queue(void) } assert(!input_queue_pop(&q, &out)); } - struct yasl_input_event empty = {.surface = &surface, .kind = YASL_INPUT_PASTE}; - struct yasl_input_event out; + struct yasl_event empty = {.surface = &surface, .type = YASL_EVENT_PASTE}; + struct yasl_event out; assert(input_queue_push(&q, &empty)); assert(input_queue_pop(&q, &out)); - assert(out.paste.text && !out.paste.len && out.paste.text[0] == '\0'); - struct yasl_input_event in = {.surface = &surface, .kind = YASL_INPUT_TEXT, + assert(out.text.data && !out.text.len && out.text.data[0] == '\0'); + struct yasl_event in = {.surface = &surface, .type = YASL_EVENT_TEXT, .text = {"owned", 5}}; assert(input_queue_push(&q, &in)); assert(input_queue_pop(&q, &out)); - const char *last = out.text.text; + const char *last = out.text.data; assert(input_queue_push(&q, &in)); /* Exercise the allocation-failure reset path without allocating huge RAM. */ in.text.len = SIZE_MAX; assert(!input_queue_push(&q, &in)); assert(strcmp(last, "owned") == 0); - in = (struct yasl_input_event){.surface = &surface, .kind = YASL_INPUT_KEY}; + in = (struct yasl_event){.surface = &surface, .type = YASL_EVENT_KEY}; assert(input_queue_push(&q, &in)); - assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_RESET); + assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_INPUT_RESET); assert(out.surface == &surface); - assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_KEY); + assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_KEY); assert(!input_queue_pop(&q, &out)); - in = (struct yasl_input_event){.kind = YASL_INPUT_PASTE, .paste = {"pending", 7}}; + in = (struct yasl_event){.type = YASL_EVENT_PASTE, .text = {"pending", 7}}; assert(input_queue_push(&q, &in)); input_queue_clear(&q); input_queue_clear(&q); diff --git a/tests/common/test_input_alloc.c b/tests/common/test_input_alloc.c index e311dc0..b999a62 100644 --- a/tests/common/test_input_alloc.c +++ b/tests/common/test_input_alloc.c @@ -12,17 +12,20 @@ void *yasl_test_malloc(size_t bytes) return calloc(1, bytes); } +/* input.c timestamps events, but this executable links no event loop. */ +uint64_t yasl_loop_now_ns(void) { return 1; } + int main(void) { struct yasl_surface *surface = (struct yasl_surface *)(uintptr_t)1; for (int failure = 0; failure < 2; failure++) { struct input_queue q = {0}; - struct yasl_input_event in = {.surface = surface, .kind = YASL_INPUT_PASTE, - .paste = {"payload", 7}}, out; + struct yasl_event in = {.surface = surface, .type = YASL_EVENT_PASTE, + .text = {"payload", 7}}, out; /* Fail either payload allocation or the initial event-array allocation. */ allocations = failure; assert(!input_queue_push(&q, &in)); - assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_RESET); + assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_INPUT_RESET); assert(out.surface == surface); assert(!input_queue_pop(&q, &out)); input_queue_clear(&q); @@ -30,17 +33,17 @@ int main(void) allocations = -1; assert(input_queue_push(&q, &in)); assert(input_queue_pop(&q, &out)); - const char *last = out.paste.text; + const char *last = out.text.data; for (size_t i = 0; i < q.capacity; i++) assert(input_queue_push(&q, &in)); allocations = failure; assert(!input_queue_push(&q, &in)); assert(strcmp(last, "payload") == 0); assert(!q.count && q.reset_pending); allocations = -1; - in = (struct yasl_input_event){.surface = surface, .kind = YASL_INPUT_KEY, + in = (struct yasl_event){.surface = surface, .type = YASL_EVENT_KEY, .key.action = YASL_KEY_RELEASE}; assert(input_queue_push(&q, &in)); - assert(input_queue_pop(&q, &out) && out.kind == YASL_INPUT_RESET); + assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_INPUT_RESET); assert(input_queue_pop(&q, &out) && out.key.action == YASL_KEY_RELEASE); input_queue_clear(&q); } 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})); diff --git a/tests/test_api.cpp b/tests/test_api.cpp index c45932a..c5921e6 100644 --- a/tests/test_api.cpp +++ b/tests/test_api.cpp @@ -38,12 +38,12 @@ int main() assert(yasl_loop_step(loop, 0) >= 0); yasl_loop_destroy(loop); - yasl_input_event event{}; + yasl_event event{}; event.key.key = YASL_KEY_A; assert(event.key.key == YASL_KEY_A); - event.mouse.scroll = {0.25, -0.5}; - assert(event.mouse.scroll.x == 0.25 && event.mouse.scroll.y == -0.5); - assert(!yasl_surface_input_poll(nullptr, &event)); + event.pointer.scroll = {0.25, -0.5}; + assert(event.pointer.scroll.x == 0.25 && event.pointer.scroll.y == -0.5); + assert(!yasl_surface_poll_event(nullptr, &event)); assert(!yasl_display_drag_start(nullptr, nullptr, nullptr, nullptr, nullptr)); assert(!yasl_surface_drag_carry(nullptr, {0, 0})); diff --git a/tests/wayland/test_app_input.c b/tests/wayland/test_app_input.c index c8c5687..843f38d 100644 --- a/tests/wayland/test_app_input.c +++ b/tests/wayland/test_app_input.c @@ -15,15 +15,15 @@ struct test_state { static void push_key(struct yasl_surface *s) { - struct yasl_input_event ev = { + struct yasl_event ev = { .surface = s, - .kind = YASL_INPUT_KEY, + .type = YASL_EVENT_KEY, .key = { .key = YASL_KEY_A, .action = YASL_KEY_PRESS }, }; assert(input_queue_push(&((struct wayland_surface *)s)->input, &ev)); } -static int on_init(void *ud, struct yasl_display *d) +static enum yasl_app_result on_init(void *ud, struct yasl_display *d) { struct test_state *state = ud; if (state->end) { @@ -39,42 +39,42 @@ static int on_init(void *ud, struct yasl_display *d) assert(s); struct input_queue *queue = &((struct wayland_surface *)s)->input; input_queue_clear(queue); - struct yasl_input_event event = {.surface = s, .kind = YASL_INPUT_MOUSE, - .mouse = {.kind = YASL_PTR_PRESS, .device = YASL_PTR_DEV_ERASER, + struct yasl_event event = {.surface = s, .type = YASL_EVENT_POINTER_DOWN, + .pointer = {.device = YASL_PTR_DEV_ERASER, .button = YASL_BUTTON_PRIMARY, .pos = {12, 34}, .pen = {.pressure = 50000, .tilt_x = -20, .tilt_y = 30}}}; assert(input_queue_push(queue, &event)); - event.mouse.kind = YASL_PTR_MOTION; - event.mouse.pos = (struct yasl_vector2i){15, 39}; + event.type = YASL_EVENT_POINTER_MOTION; + event.pointer.pos = (struct yasl_vector2i){15, 39}; assert(input_queue_push(queue, &event)); - struct yasl_input_event reset = {.surface = s, .kind = YASL_INPUT_RESET}; + struct yasl_event reset = {.surface = s, .type = YASL_EVENT_INPUT_RESET}; assert(input_queue_push(queue, &reset)); - event.mouse.device = YASL_PTR_DEV_PEN; - event.mouse.pos = (struct yasl_vector2i){100, 200}; + event.pointer.device = YASL_PTR_DEV_PEN; + event.pointer.pos = (struct yasl_vector2i){100, 200}; assert(input_queue_push(queue, &event)); push_key(s); push_key(s); return YASL_APP_CONTINUE; } -static int on_event(void *ud, const struct yasl_event *ev) +static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev) { struct test_state *state = ud; - if (ev->type == YASL_EVENT_MOUSE_BUTTON) { - assert(ev->mouse_button.device == YASL_PTR_DEV_ERASER); - assert(ev->mouse_button.pressed && ev->mouse_button.button == 0); - assert(ev->mouse_button.pos.x == 12 && ev->mouse_button.pos.y == 34); - assert(ev->mouse_button.pen.pressure == 50000); - assert(ev->mouse_button.pen.tilt_x == -20 && ev->mouse_button.pen.tilt_y == 30); + if (ev->type == YASL_EVENT_POINTER_DOWN) { + assert(ev->pointer.device == YASL_PTR_DEV_ERASER); + assert(ev->pointer.button == YASL_BUTTON_PRIMARY); + assert(ev->pointer.pos.x == 12 && ev->pointer.pos.y == 34); + assert(ev->pointer.pen.pressure == 50000); + assert(ev->pointer.pen.tilt_x == -20 && ev->pointer.pen.tilt_y == 30); state->buttons++; - } else if (ev->type == YASL_EVENT_MOUSE_MOTION) { + } else if (ev->type == YASL_EVENT_POINTER_MOTION) { if (!state->motions) { - assert(ev->mouse_motion.device == YASL_PTR_DEV_ERASER); - assert(ev->mouse_motion.delta.x == 3 && ev->mouse_motion.delta.y == 5); + assert(ev->pointer.device == YASL_PTR_DEV_ERASER); + assert(ev->pointer.delta.x == 3 && ev->pointer.delta.y == 5); } else { - assert(ev->mouse_motion.device == YASL_PTR_DEV_PEN); - assert(!ev->mouse_motion.delta.x && !ev->mouse_motion.delta.y); + assert(ev->pointer.device == YASL_PTR_DEV_PEN); + assert(!ev->pointer.delta.x && !ev->pointer.delta.y); } - assert(ev->mouse_motion.pen.pressure == 50000); + assert(ev->pointer.pen.pressure == 50000); state->motions++; } else if (ev->type == YASL_EVENT_INPUT_RESET) { state->resets++; diff --git a/tests/wayland/test_cursor.c b/tests/wayland/test_cursor.c index a4a522e..eb729a3 100644 --- a/tests/wayland/test_cursor.c +++ b/tests/wayland/test_cursor.c @@ -76,14 +76,14 @@ int main(void) pointer_frame(&seat, seat.pointer); tablet_tool_motion(&tool, tool.proxy, wl_fixed_from_int(56), wl_fixed_from_int(78)); tool_frame(&tool, tool.proxy, 0); - struct yasl_input_event event; - assert(yasl_surface_input_poll(&surface.base, &event)); - assert(event.kind == YASL_INPUT_MOUSE && event.mouse.device == YASL_PTR_DEV_MOUSE); - assert(event.mouse.pos.x == 12 && event.mouse.pos.y == 34); - assert(yasl_surface_input_poll(&surface.base, &event)); - assert(event.kind == YASL_INPUT_MOUSE && event.mouse.device == YASL_PTR_DEV_PEN); - assert(event.mouse.pos.x == 56 && event.mouse.pos.y == 78); - assert(!yasl_surface_input_poll(&surface.base, &event)); + struct yasl_event event; + assert(yasl_surface_poll_event(&surface.base, &event)); + assert(event.type == YASL_EVENT_POINTER_MOTION && event.pointer.device == YASL_PTR_DEV_MOUSE); + assert(event.pointer.pos.x == 12 && event.pointer.pos.y == 34); + assert(yasl_surface_poll_event(&surface.base, &event)); + assert(event.type == YASL_EVENT_POINTER_MOTION && event.pointer.device == YASL_PTR_DEV_PEN); + assert(event.pointer.pos.x == 56 && event.pointer.pos.y == 78); + assert(!yasl_surface_poll_event(&surface.base, &event)); /* Each new entry needs a request with its own serial. */ pointer_leave(&seat, seat.pointer, 12, surface.surface); diff --git a/tests/wayland/test_input.c b/tests/wayland/test_input.c index feff2f3..f6112b6 100644 --- a/tests/wayland/test_input.c +++ b/tests/wayland/test_input.c @@ -41,10 +41,10 @@ int main(void) for (int i = 0; i < 600; i++) { char text[32]; snprintf(text, sizeof(text), "commit-%d", i); - struct yasl_input_event event; - assert(wayland_surface_input_poll(&w, &event)); - assert(event.kind == YASL_INPUT_TEXT && event.surface == &w.base); - assert(strcmp(event.text.text, text) == 0); + struct yasl_event event; + assert(wayland_surface_poll_event(&w, &event)); + assert(event.type == YASL_EVENT_TEXT && event.surface == &w.base); + assert(strcmp(event.text.data, text) == 0); } input_queue_clear(&w.input); return 0; diff --git a/tests/wayland/test_keyboard.c b/tests/wayland/test_keyboard.c index 6921322..bce0a0c 100644 --- a/tests/wayland/test_keyboard.c +++ b/tests/wayland/test_keyboard.c @@ -1,18 +1,18 @@ #include "../../src/platform/wayland/keyboard.c" #include <assert.h> -static struct yasl_input_event next(struct wayland_surface *w, enum yasl_input_kind kind) +static struct yasl_event next(struct wayland_surface *w, enum yasl_event_type type) { - struct yasl_input_event ev; - assert(yasl_surface_input_poll(&w->base, &ev)); - assert(ev.kind == kind && ev.surface == &w->base); + struct yasl_event ev; + assert(yasl_surface_poll_event(&w->base, &ev)); + assert(ev.type == type && ev.surface == &w->base); return ev; } static void empty(struct wayland_surface *w) { - struct yasl_input_event ev; - assert(!yasl_surface_input_poll(&w->base, &ev)); + struct yasl_event ev; + assert(!yasl_surface_poll_event(&w->base, &ev)); } static void layout(struct seat *s, const char *name, const char *variant) @@ -59,65 +59,65 @@ int main(void) xkb_compose_table_unref(table); layout(&s, "us", NULL); key(&s, KEY_A, true); - struct yasl_input_event ev = next(&w, YASL_INPUT_KEY); + struct yasl_event ev = next(&w, YASL_EVENT_KEY); assert(ev.key.key == YASL_KEY_A && ev.key.native_code == KEY_A); assert(ev.key.codepoint == 'a' && ev.key.shifted == 'A' && !ev.key.mods); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "a") == 0); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "a") == 0); modifiers(&s, XKB_MOD_NAME_SHIFT); key(&s, KEY_A, false); /* Modifier changes cannot change physical identity. */ - ev = next(&w, YASL_INPUT_KEY); + ev = next(&w, YASL_EVENT_KEY); assert(ev.key.key == YASL_KEY_A && ev.key.action == YASL_KEY_RELEASE); assert(ev.key.mods == YASL_MOD_SHIFT); empty(&w); key(&s, KEY_A, true); - next(&w, YASL_INPUT_KEY); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "A") == 0); + next(&w, YASL_EVENT_KEY); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "A") == 0); modifiers(&s, XKB_MOD_NAME_CAPS); key(&s, KEY_A, true); - assert(next(&w, YASL_INPUT_KEY).key.mods == YASL_MOD_CAPS); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "A") == 0); + assert(next(&w, YASL_EVENT_KEY).key.mods == YASL_MOD_CAPS); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "A") == 0); const char *shortcuts[] = {XKB_MOD_NAME_CTRL, XKB_MOD_NAME_ALT, XKB_MOD_NAME_LOGO}; for (size_t i = 0; i < sizeof(shortcuts)/sizeof(shortcuts[0]); i++) { modifiers(&s, shortcuts[i]); key(&s, KEY_A, true); - next(&w, YASL_INPUT_KEY); + next(&w, YASL_EVENT_KEY); empty(&w); /* Shortcut characters never leak into committed text. */ } layout(&s, "fr", NULL); key(&s, KEY_A, true); - ev = next(&w, YASL_INPUT_KEY); + ev = next(&w, YASL_EVENT_KEY); assert(ev.key.key == YASL_KEY_A && ev.key.codepoint == 'q'); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "q") == 0); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "q") == 0); layout(&s, "de", NULL); modifiers(&s, "Mod5"); /* AltGr is text input, not an Alt shortcut. */ key(&s, KEY_E, true); - assert(next(&w, YASL_INPUT_KEY).key.key == YASL_KEY_E); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "€") == 0); + assert(next(&w, YASL_EVENT_KEY).key.key == YASL_KEY_E); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "€") == 0); layout(&s, "us", "intl"); key(&s, KEY_APOSTROPHE, true); - next(&w, YASL_INPUT_KEY); + next(&w, YASL_EVENT_KEY); empty(&w); key(&s, KEY_E, true); - next(&w, YASL_INPUT_KEY); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "é") == 0); + next(&w, YASL_EVENT_KEY); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "é") == 0); assert(keyboard_dispatch_key(&s, &w, KEY_E, YASL_KEY_REPEAT)); - assert(next(&w, YASL_INPUT_KEY).key.action == YASL_KEY_REPEAT); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0); + assert(next(&w, YASL_EVENT_KEY).key.action == YASL_KEY_REPEAT); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0); key(&s, KEY_APOSTROPHE, true); - next(&w, YASL_INPUT_KEY); + next(&w, YASL_EVENT_KEY); keyboard_reset_keys(&s, &w); key(&s, KEY_E, true); - next(&w, YASL_INPUT_KEY); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0); + next(&w, YASL_EVENT_KEY); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0); key(&s, KEY_APOSTROPHE, true); - next(&w, YASL_INPUT_KEY); + next(&w, YASL_EVENT_KEY); s.ime_focus = &w; text_input_listener.commit_string(&s, NULL, "字"); text_input_listener.done(&s, NULL, 0); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "字") == 0); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "字") == 0); key(&s, KEY_E, true); - next(&w, YASL_INPUT_KEY); - assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0); + next(&w, YASL_EVENT_KEY); + assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0); empty(&w); xkb_compose_state_unref(s.compose); xkb_state_unref(s.xkb_state); diff --git a/tests/wayland/test_tablet.c b/tests/wayland/test_tablet.c index 8723df2..c76ddf8 100644 --- a/tests/wayland/test_tablet.c +++ b/tests/wayland/test_tablet.c @@ -1,12 +1,12 @@ #include "../../src/platform/wayland/pointer.c" #include <assert.h> -static struct yasl_mouse_event next(struct wayland_surface *surface) +static struct yasl_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; + struct yasl_event event; + assert(yasl_surface_poll_event(&surface->base, &event)); + assert(event.surface == &surface->base); + return event; } int main(void) @@ -22,38 +22,38 @@ int main(void) 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); + struct yasl_event ev = next(&surface); + assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.device == YASL_PTR_DEV_PEN); + assert(ev.pointer.pos.x == 150 && ev.pointer.pos.y == 180 && ev.pointer.pen.pressure == 32768); + assert(ev.pointer.pen.tilt_x == -35 && ev.pointer.pen.tilt_y == 42); ev = next(&surface); - assert(ev.kind == YASL_PTR_PRESS && ev.button == 0 && ev.pen.pressure == 32768); + assert(ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY && ev.pointer.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); + assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + assert(ev.pointer.pos.x == 150 && ev.pointer.pos.y == 180); + assert(ev.pointer.pen.tilt_x == -90 && ev.pointer.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); + assert(ev.type == YASL_EVENT_POINTER_UP && ev.pointer.button == YASL_BUTTON_PRIMARY && !ev.pointer.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); + assert(next(&surface).pointer.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); - assert(ev.scroll.x == 0 && ev.scroll.y == 1); + assert(ev.type == YASL_EVENT_POINTER_SCROLL && ev.pointer.device == YASL_PTR_DEV_ERASER); + assert(ev.pointer.scroll.x == 0 && ev.pointer.scroll.y == 1); 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(ev.type == YASL_EVENT_POINTER_LEAVE && ev.pointer.device == YASL_PTR_DEV_ERASER && !ev.pointer.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. */ @@ -68,12 +68,12 @@ int main(void) pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -60); pointer_frame(&seat, NULL); ev = next(&surface); - assert(ev.kind == YASL_PTR_SCROLL && ev.device == YASL_PTR_DEV_MOUSE); - assert(ev.scroll.x == -0.5 && ev.scroll.y == 0.25); - struct yasl_input_event unused; - assert(!yasl_surface_input_poll(&surface.base, &unused)); + assert(ev.type == YASL_EVENT_POINTER_SCROLL && ev.pointer.device == YASL_PTR_DEV_MOUSE); + assert(ev.pointer.scroll.x == -0.5 && ev.pointer.scroll.y == 0.25); + struct yasl_event unused; + assert(!yasl_surface_poll_event(&surface.base, &unused)); pointer_frame(&seat, NULL); - assert(!yasl_surface_input_poll(&surface.base, &unused)); + assert(!yasl_surface_poll_event(&surface.base, &unused)); /* Stops preserve offsets from the same frame. Repeated tiny movements * must be visible immediately rather than held until a whole detent. */ @@ -84,16 +84,16 @@ int main(void) pointer_axis_stop(&seat, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL); pointer_frame(&seat, NULL); ev = next(&surface); - assert(ev.scroll.x == -0.25 && ev.scroll.y == 0.125); + assert(ev.pointer.scroll.x == -0.25 && ev.pointer.scroll.y == 0.125); } pointer_axis_discrete(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 2); pointer_frame(&seat, NULL); ev = next(&surface); - assert(ev.scroll.x == 2 && ev.scroll.y == 0); + assert(ev.pointer.scroll.x == 2 && ev.pointer.scroll.y == 0); pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 60); seat_pointer_reset(&seat); pointer_frame(&seat, NULL); - assert(!yasl_surface_input_poll(&surface.base, &unused)); + assert(!yasl_surface_poll_event(&surface.base, &unused)); input_queue_clear(&surface.input); return 0; } 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); } |
