diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 23:41:31 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 23:41:31 +0300 |
| commit | 76073fe5fad8799e5850805f2f090af2cb62c741 (patch) | |
| tree | 9658019babe4760a3634bdab4da0731a10e42e68 /tests/x11/test_input.c | |
| parent | dd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff) | |
Simplify the public event and CPU API
Applications now need far less ceremony: hello.c is a 20-line loop that
handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels.
- Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size,
scale and state; unchanged values send nothing.
- Guarantee REFRESH once a window has a size and after every resize,
never at size zero.
- Merge DROP_HOVER into DROP with over/leave/data actions and give drag
and drop actions enums.
- Keep event strings valid until the next wait and drop
yasl_event_release; empty or failed waits report NONE.
- Replace copy-in presentation with a lent pixel buffer:
yasl_cpu_pixels and yasl_cpu_present.
- Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and
comments that restated names.
- Wayland: resize floating windows in request_size instead of reporting
it unsupported, and stop marking new GPU surfaces as Vulkan so
yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE.
Also includes the in-progress public API refactor that was uncommitted
in the tree (removal of the app/loop layer, new surface, GL and Vulkan
entry points).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/x11/test_input.c')
| -rw-r--r-- | tests/x11/test_input.c | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/tests/x11/test_input.c b/tests/x11/test_input.c index c2eca37..ccad859 100644 --- a/tests/x11/test_input.c +++ b/tests/x11/test_input.c @@ -8,10 +8,10 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * { Window requestor = XCreateSimpleWindow(d->native, DefaultRootWindow(d->native), 0, 0, 1, 1, 0, 0, 0); - Atom property = XInternAtom(d->native, "YASL_TEST_STRING", False); + Atom property = XInternAtom(d->native, "YASL_PRIVATE_TEST_STRING", False); XSelectionRequestEvent request = {.display = d->native, .requestor = requestor, .selection = d->clipboard, .target = XA_STRING, .property = property}; - yasl_display_copy(&d->base, YASL_CLIPBOARD, "café £"); + yasl_private_display_copy(&d->base, YASL_PRIVATE_CLIPBOARD, "café £"); selection_request(d, &request); Atom actual; int format; @@ -22,7 +22,7 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * assert(actual == XA_STRING && format == 8 && count == 6); assert(memcmp(data, "caf\xe9 \xa3", count) == 0); XFree(data); - yasl_display_copy(&d->base, YASL_CLIPBOARD, "字"); + yasl_private_display_copy(&d->base, YASL_PRIVATE_CLIPBOARD, "字"); selection_request(d, &request); assert(XGetWindowProperty(d->native, requestor, property, 0, 100, True, AnyPropertyType, &actual, &format, &count, &left, &data) == Success); @@ -44,12 +44,12 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * size_t len; int format; const char *expected; - enum yasl_transfer_status status; + enum yasl_private_transfer_status status; } cases[] = { - {XA_STRING, "caf\xe9 \xa3", 6, 8, "café £", YASL_TRANSFER_OK}, - {d->utf8, "", 0, 8, "", YASL_TRANSFER_OK}, - {d->utf8, "\xff", 1, 8, NULL, YASL_TRANSFER_FAILED}, - {d->incr, NULL, 1, 32, NULL, YASL_TRANSFER_FAILED}, + {XA_STRING, "caf\xe9 \xa3", 6, 8, "café £", YASL_PRIVATE_TRANSFER_OK}, + {d->utf8, "", 0, 8, "", YASL_PRIVATE_TRANSFER_OK}, + {d->utf8, "\xff", 1, 8, NULL, YASL_PRIVATE_TRANSFER_FAILED}, + {d->incr, NULL, 1, 32, NULL, YASL_PRIVATE_TRANSFER_FAILED}, }; for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { struct paste_request *pending = calloc(1, sizeof(*pending)); @@ -59,7 +59,7 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * 0, 0, 1, 1, 0, 0, 0); pending->target = s; pending->id = (uint64_t)i + 1; - pending->timeout = yasl_loop_add_timer(d->loop, PASTE_TIMEOUT_NS, + pending->timeout = yasl_private_loop_add_timer(d->loop, PASTE_TIMEOUT_NS, paste_timeout, pending); assert(pending->timeout); pending->next = d->pastes; @@ -71,21 +71,21 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * cases[i].format, PropModeReplace, bytes, (int)cases[i].len); XSelectionEvent reply = {.requestor = pending->window, .property = property}; selection_notify(d, &reply); - struct yasl_event event; - assert(yasl_surface_poll_event(&s->base, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == i + 1); + struct yasl_private_event event; + assert(yasl_private_surface_poll_event(&s->base, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == i + 1); assert(event.paste.status == cases[i].status); - if (cases[i].status == YASL_TRANSFER_OK) { + if (cases[i].status == YASL_PRIVATE_TRANSFER_OK) { assert(event.text.len == strlen(cases[i].expected)); assert(strcmp(event.text.data, cases[i].expected) == 0); } if (cases[i].type == d->incr) { assert(d->pastes == pending && !pending->target); - assert(yasl_loop_del_timer(d->loop, pending->timeout)); + assert(yasl_private_loop_del_timer(d->loop, pending->timeout)); pending->timeout = 0; paste_timeout(pending, 0, PASTE_TIMEOUT_NS); } - assert(!yasl_surface_poll_event(&s->base, &event)); + assert(!yasl_private_surface_poll_event(&s->base, &event)); } struct paste_request *rejected = calloc(1, sizeof(*rejected)); @@ -99,10 +99,10 @@ static void check_selection_encoding(struct x11_display *d, struct x11_surface * d->pastes = rejected; XSelectionEvent no_property = {.requestor = rejected->window, .property = None}; selection_notify(d, &no_property); - struct yasl_event event; - assert(yasl_surface_poll_event(&s->base, &event)); - assert(event.type == YASL_EVENT_PASTE && event.paste.request_id == 99); - assert(event.paste.status == YASL_TRANSFER_FAILED); + struct yasl_private_event event; + assert(yasl_private_surface_poll_event(&s->base, &event)); + assert(event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == 99); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_FAILED); } /* Own the XSETTINGS selection with one Net/DoubleClickTime value. */ @@ -111,7 +111,7 @@ static void check_double_click(struct x11_display *d) /* No settings owner and no portal: the default applies. */ unsetenv("DBUS_SESSION_BUS_ADDRESS"); unsetenv("XDG_RUNTIME_DIR"); - assert(yasl_display_double_click_ms(&d->base) == YASL_DOUBLE_CLICK_MS_DEFAULT); + assert(yasl_private_display_double_click_ms(&d->base) == YASL_PRIVATE_DOUBLE_CLICK_MS_DEFAULT); char name[32]; snprintf(name, sizeof(name), "_XSETTINGS_S%d", d->screen); @@ -129,64 +129,64 @@ static void check_double_click(struct x11_display *d) XChangeProperty(d->native, owner, property, property, 8, PropModeReplace, blob, sizeof(blob)); XSync(d->native, False); - assert(yasl_display_double_click_ms(&d->base) == 250); + assert(yasl_private_display_double_click_ms(&d->base) == 250); XDestroyWindow(d->native, owner); XSync(d->native, False); - assert(yasl_display_double_click_ms(&d->base) == YASL_DOUBLE_CLICK_MS_DEFAULT); + assert(yasl_private_display_double_click_ms(&d->base) == YASL_PRIVATE_DOUBLE_CLICK_MS_DEFAULT); } -static struct yasl_event wait_paste(struct yasl_display *display, uint64_t id) +static struct yasl_private_event wait_paste(struct yasl_private_display *display, uint64_t id) { - struct yasl_event event; - for (int i = 0; i < 256 && yasl_display_poll_event(display, &event); i++) - if (event.type == YASL_EVENT_PASTE && event.paste.request_id == id) + struct yasl_private_event event; + for (int i = 0; i < 256 && yasl_private_display_poll_event(display, &event); i++) + if (event.type == YASL_PRIVATE_EVENT_PASTE && event.paste.request_id == id) return event; assert(!"expected paste completion was not queued"); - return (struct yasl_event){0}; + return (struct yasl_private_event){0}; } static void check_request_completion(struct x11_display *d, struct x11_surface *s) { assert(surface_input_queue(&s->base) == &s->input); - assert(copy_text(&d->base, YASL_CLIPBOARD, "")); + assert(copy_text(&d->base, YASL_PRIVATE_CLIPBOARD, "")); XSync(d->native, False); assert(XGetSelectionOwner(d->native, d->clipboard) == d->selection_window); - assert(request_paste(&d->base, YASL_CLIPBOARD, &s->base, 101)); - struct yasl_event event = wait_paste(&d->base, 101); - assert(event.paste.status == YASL_TRANSFER_OK && event.paste.len == 0); + assert(request_paste(&d->base, YASL_PRIVATE_CLIPBOARD, &s->base, 101)); + struct yasl_private_event event = wait_paste(&d->base, 101); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_OK && event.paste.len == 0); assert(event.paste.data && !event.paste.data[0]); XSetSelectionOwner(d->native, d->clipboard, None, CurrentTime); XSync(d->native, False); - assert(request_paste(&d->base, YASL_CLIPBOARD, &s->base, 102)); + assert(request_paste(&d->base, YASL_PRIVATE_CLIPBOARD, &s->base, 102)); XSync(d->native, False); dispatch(&d->base); event = wait_paste(&d->base, 102); - assert(event.paste.status == YASL_TRANSFER_UNAVAILABLE); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_UNAVAILABLE); Window silent_owner = XCreateSimpleWindow(d->native, DefaultRootWindow(d->native), 0, 0, 1, 1, 0, 0, 0); XSetSelectionOwner(d->native, d->clipboard, silent_owner, CurrentTime); XSync(d->native, False); - assert(request_paste(&d->base, YASL_CLIPBOARD, &s->base, 103)); + assert(request_paste(&d->base, YASL_PRIVATE_CLIPBOARD, &s->base, 103)); struct paste_request *timed = d->pastes; assert(timed && timed->id == 103 && timed->timeout); - assert(yasl_loop_del_timer(d->loop, timed->timeout)); + assert(yasl_private_loop_del_timer(d->loop, timed->timeout)); timed->timeout = 0; paste_timeout(timed, 0, PASTE_TIMEOUT_NS); event = wait_paste(&d->base, 103); - assert(event.paste.status == YASL_TRANSFER_FAILED); + assert(event.paste.status == YASL_PRIVATE_TRANSFER_FAILED); - struct yasl_window_spec spec = {.title = "Cancelled paste", .size = {80, 60}}; - struct yasl_surface *cancel_target = yasl_surface_create_toplevel(&d->base, &spec); + struct yasl_private_window_spec spec = {.title = "Cancelled paste", .size = {80, 60}}; + struct yasl_surface *cancel_target = yasl_private_surface_create_toplevel(&d->base, &spec); assert(cancel_target); - assert(request_paste(&d->base, YASL_CLIPBOARD, cancel_target, 104)); + assert(request_paste(&d->base, YASL_PRIVATE_CLIPBOARD, cancel_target, 104)); assert(d->pastes && d->pastes->target == (struct x11_surface *)cancel_target); - yasl_timer_id timeout = d->pastes->timeout; - yasl_surface_destroy(cancel_target); + yasl_private_timer_id timeout = d->pastes->timeout; + yasl_private_surface_destroy(cancel_target); assert(d->pastes && !d->pastes->target && d->pastes->id == 0); - assert(yasl_loop_del_timer(d->loop, timeout)); + assert(yasl_private_loop_del_timer(d->loop, timeout)); d->pastes->timeout = 0; XSelectionEvent late_reply = { .requestor = d->pastes->window, @@ -200,23 +200,23 @@ static void check_request_completion(struct x11_display *d, struct x11_surface * XSync(d->native, False); } -static struct yasl_event next_composition(struct yasl_display *display) +static struct yasl_private_event next_composition(struct yasl_private_display *display) { - struct yasl_event event; - for (int i = 0; i < 256 && yasl_display_poll_event(display, &event); i++) - if (event.type == YASL_EVENT_COMPOSITION) + struct yasl_private_event event; + for (int i = 0; i < 256 && yasl_private_display_poll_event(display, &event); i++) + if (event.type == YASL_PRIVATE_EVENT_COMPOSITION) return event; assert(!"expected composition snapshot was not queued"); - return (struct yasl_event){0}; + return (struct yasl_private_event){0}; } -static void drain_display_events(struct yasl_display *display) +static void drain_display_events(struct yasl_private_display *display) { - struct yasl_event event; - while (yasl_display_poll_event(display, &event)) {} + struct yasl_private_event event; + while (yasl_private_display_poll_event(display, &event)) {} } -static void check_xim_callbacks(struct yasl_display *display, struct x11_surface *s) +static void check_xim_callbacks(struct yasl_private_display *display, struct x11_surface *s) { const char *old_locale = setlocale(LC_CTYPE, NULL); char *saved_locale = old_locale ? strdup(old_locale) : NULL; @@ -235,7 +235,7 @@ static void check_xim_callbacks(struct yasl_display *display, struct x11_surface }; xim_preedit_draw(NULL, (XPointer)s, (XPointer)&draw); assert(s->ime_preedit && strcmp(s->ime_preedit, "A😀B") == 0); - struct yasl_event event = next_composition(display); + struct yasl_private_event event = next_composition(display); assert(event.composition.active && event.composition.len == 6); assert(event.composition.begin == 5 && event.composition.end == 5); @@ -271,8 +271,8 @@ static void check_xim_callbacks(struct yasl_display *display, struct x11_surface draw.chg_length = 0; xim_preedit_draw(NULL, (XPointer)s, (XPointer)&draw); assert(strcmp(s->ime_preedit, "AéZB") == 0); - struct yasl_event unused; - assert(!yasl_display_poll_event(display, &unused)); + struct yasl_private_event unused; + assert(!yasl_private_display_poll_event(display, &unused)); wchar_t empty[] = {0}; XIMText deletion = {.length = 0, .encoding_is_wchar = True, @@ -305,12 +305,12 @@ static void check_xim_callbacks(struct yasl_display *display, struct x11_surface int main(void) { - struct yasl_display_spec ds = {.backend = YASL_BACKEND_X11}; - struct yasl_display *base = yasl_display_open(NULL, &ds); + struct yasl_private_display_spec ds = {.backend = YASL_PRIVATE_BACKEND_X11}; + struct yasl_private_display *base = yasl_private_display_open(NULL, &ds); assert(base); struct x11_display *d = (struct x11_display *)base; - struct yasl_window_spec spec = {.title = "Keyboard fallback", .size = {100, 100}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(base, &spec); + struct yasl_private_window_spec spec = {.title = "Keyboard fallback", .size = {100, 100}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(base, &spec); assert(surface); struct x11_surface *s = (struct x11_surface *)surface; XIC saved_ic = s->ic; @@ -335,22 +335,22 @@ int main(void) input_queue_clear(&s->input); /* Native creation and keymap updates may already have queued focus or * reset input on the shared display stream. Isolate this synthetic key. */ - struct yasl_event event; - while (yasl_surface_poll_event(surface, &event)) {} + struct yasl_private_event event; + while (yasl_private_surface_poll_event(surface, &event)) {} XKeyEvent native = {.type = KeyPress, .display = d->native, .window = s->window, .keycode = code}; key_event(s, &native, false); - assert(yasl_surface_poll_event(surface, &event)); - assert(event.type == YASL_EVENT_KEY && event.key.key == YASL_KEY_A); + assert(yasl_private_surface_poll_event(surface, &event)); + assert(event.type == YASL_PRIVATE_EVENT_KEY && event.key.key == YASL_KEY_A); assert(event.key.codepoint == cases[i].label); - assert(yasl_surface_poll_event(surface, &event)); - assert(event.type == YASL_EVENT_TEXT && event.text.len == strlen(cases[i].text)); + assert(yasl_private_surface_poll_event(surface, &event)); + assert(event.type == YASL_PRIVATE_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)); + assert(!yasl_private_surface_poll_event(surface, &event)); native.type = KeyRelease; key_event(s, &native, false); - assert(yasl_surface_poll_event(surface, &event) && event.type == YASL_EVENT_KEY); - assert(!yasl_surface_poll_event(surface, &event)); + assert(yasl_private_surface_poll_event(surface, &event) && event.type == YASL_PRIVATE_EVENT_KEY); + assert(!yasl_private_surface_poll_event(surface, &event)); } XChangeKeyboardMapping(d->native, code, width, saved, 1); XSync(d->native, False); @@ -363,14 +363,14 @@ int main(void) check_xim_callbacks(base, s); /* Test CSD interactive actions, window menu, and IME caret */ - assert(yasl_display_caps(base) & YASL_CAP_CSD); - yasl_surface_set_ime_caret(surface, (struct yasl_rect2i){10, 20, 2, 16}); - assert(yasl_surface_ime_preedit(surface) == NULL); + assert(yasl_private_display_caps(base) & YASL_PRIVATE_CAP_CSD); + yasl_private_surface_set_ime_caret(surface, (struct yasl_private_rect2i){10, 20, 2, 16}); + assert(yasl_private_surface_ime_preedit(surface) == NULL); int begin = -1, end = -1; - assert(!yasl_surface_ime_preedit_cursor(surface, &begin, &end)); - assert(yasl_surface_show_window_menu(surface, (struct yasl_vector2i){50, 50})); + assert(!yasl_private_surface_ime_preedit_cursor(surface, &begin, &end)); + assert(yasl_private_surface_show_window_menu(surface, (struct yasl_private_vector2i){50, 50})); - yasl_surface_destroy(surface); - yasl_display_close(base); + yasl_private_surface_destroy(surface); + yasl_private_display_close(base); return 0; } |
