From 76073fe5fad8799e5850805f2f090af2cb62c741 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 23:41:31 +0300 Subject: 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 --- tests/x11/inputtest-protocol.h | 4 +- tests/x11/test_input.c | 148 ++++++++++++++--------------- tests/x11/test_state.c | 18 ++-- tests/x11/test_tablet.c | 210 +++++++++++++++++++++++++++++------------ tests/x11/test_tablet_native.c | 58 ++++++------ 5 files changed, 262 insertions(+), 176 deletions(-) (limited to 'tests/x11') diff --git a/tests/x11/inputtest-protocol.h b/tests/x11/inputtest-protocol.h index 18f62ba..2a94a55 100644 --- a/tests/x11/inputtest-protocol.h +++ b/tests/x11/inputtest-protocol.h @@ -22,8 +22,8 @@ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef YASL_TEST_INPUTTEST_PROTOCOL_H -#define YASL_TEST_INPUTTEST_PROTOCOL_H +#ifndef YASL_PRIVATE_TEST_INPUTTEST_PROTOCOL_H +#define YASL_PRIVATE_TEST_INPUTTEST_PROTOCOL_H #include 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; } diff --git a/tests/x11/test_state.c b/tests/x11/test_state.c index abc0851..4696e60 100644 --- a/tests/x11/test_state.c +++ b/tests/x11/test_state.c @@ -31,7 +31,7 @@ int state_property(Display *display, Window window, Atom property, static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud) { (void)ud; - assert(yasl_surface_state(surface) == state); + assert(yasl_private_surface_state(surface) == state); reported_state = state; notifications++; } @@ -93,39 +93,39 @@ static void test_xsettings(void) int main(void) { test_xsettings(); - struct x11_display display = {.base.ops = &yasl_x11_backend, + struct x11_display display = {.base.ops = &yasl_private_x11_backend, .net_state = 10, .fullscreen = 20, .maximized_h = 21, .maximized_v = 22}; display.native = (Display *)&display; struct x11_surface surface = {.base = {.display = &display.base, - .state = YASL_STATE_ACTIVATED}, .window = 42}; - set_callbacks(&surface.base, &(struct yasl_window_cbs){.state = state_changed}, NULL); + .state = YASL_PRIVATE_STATE_ACTIVATED}, .window = 42}; + set_callbacks(&surface.base, &(struct yasl_private_window_cbs){.state = state_changed}, NULL); properties[0] = display.fullscreen; property_count = 1; update_state(&surface); assert(notifications == 1); - assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED)); + assert(reported_state == (YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_ACTIVATED)); update_state(&surface); assert(notifications == 1); /* Both maximized axes are required; activation survives property changes. */ properties[0] = display.maximized_h; update_state(&surface); - assert(notifications == 2 && reported_state == YASL_STATE_ACTIVATED); + assert(notifications == 2 && reported_state == YASL_PRIVATE_STATE_ACTIVATED); properties[1] = display.maximized_v; property_count = 2; update_state(&surface); assert(notifications == 3); - assert(reported_state == (YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED)); + assert(reported_state == (YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_STATE_ACTIVATED)); properties[2] = display.fullscreen; property_count = 3; update_state(&surface); assert(notifications == 4); - assert(reported_state == (YASL_STATE_FULLSCREEN | YASL_STATE_MAXIMIZED | YASL_STATE_ACTIVATED)); + assert(reported_state == (YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_STATE_ACTIVATED)); property_count = 0; update_state(&surface); - assert(notifications == 5 && reported_state == YASL_STATE_ACTIVATED); + assert(notifications == 5 && reported_state == YASL_PRIVATE_STATE_ACTIVATED); update_state(&surface); assert(notifications == 5); return 0; diff --git a/tests/x11/test_tablet.c b/tests/x11/test_tablet.c index 243ae00..be5da4c 100644 --- a/tests/x11/test_tablet.c +++ b/tests/x11/test_tablet.c @@ -1,10 +1,18 @@ /* Exercise native XI2 samples through the backend and public input queue. */ #include "../../src/platform/x11/window.c" -static struct yasl_event next(struct x11_surface *surface) +static struct yasl_private_event next(struct x11_surface *surface) { - struct yasl_event event; - assert(yasl_surface_poll_event(&surface->base, &event)); + struct yasl_private_event event; + /* This backend unit harness owns a standalone input queue, without a + * registered display event FIFO. Read rich private events directly. */ + static unsigned count; + count++; + if (!input_queue_pop(&surface->input, &event)) { + fprintf(stderr, "missing private event at expectation %u (queued=%zu reset=%d)\n", + count, surface->input.count, surface->input.reset_pending); + abort(); + } assert(event.surface == &surface->base); return event; } @@ -13,51 +21,51 @@ struct drag_test_recorder { int over_count; int leave_count; int drop_count; - struct yasl_vector2i last_pos; + struct yasl_private_vector2i last_pos; }; -static void on_test_drag(struct yasl_surface *s, enum yasl_drag_event ev, - struct yasl_vector2i pos, void *ud) +static void on_test_drag(struct yasl_surface *s, enum yasl_private_drag_event ev, + struct yasl_private_vector2i pos, void *ud) { (void)s; struct drag_test_recorder *rec = ud; rec->last_pos = pos; - if (ev == YASL_DRAG_OVER) rec->over_count++; - else if (ev == YASL_DRAG_LEAVE) rec->leave_count++; - else if (ev == YASL_DRAG_DROP) rec->drop_count++; + if (ev == YASL_PRIVATE_DRAG_OVER) rec->over_count++; + else if (ev == YASL_PRIVATE_DRAG_LEAVE) rec->leave_count++; + else if (ev == YASL_PRIVATE_DRAG_DROP) rec->drop_count++; } struct drop_test_recorder { int over_count; int leave_count; - struct yasl_vector2i last_pos; + struct yasl_private_vector2i last_pos; }; -static void on_test_drop(struct yasl_surface *s, enum yasl_drop_event ev, - struct yasl_vector2i pos, void *ud) +static void on_test_drop(struct yasl_surface *s, enum yasl_private_drop_event ev, + struct yasl_private_vector2i pos, void *ud) { (void)s; struct drop_test_recorder *rec = ud; rec->last_pos = pos; - if (ev == YASL_DROP_OVER) rec->over_count++; - else if (ev == YASL_DROP_LEAVE) rec->leave_count++; + if (ev == YASL_PRIVATE_DROP_OVER) rec->over_count++; + else if (ev == YASL_PRIVATE_DROP_LEAVE) rec->leave_count++; } -static void on_test_drag_end(void *ud, enum yasl_drag_end how) +static void on_test_drag_end(void *ud, enum yasl_private_drag_end how) { - enum yasl_drag_end *res = ud; + enum yasl_private_drag_end *res = ud; *res = how; } static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) { /* 1. Caps */ - assert(caps(&d->base) & YASL_CAP_POPUPS); - assert(caps(&d->base) & YASL_CAP_DRAG); - assert(caps(&d->base) & YASL_CAP_DRAG_CARRY); + assert(caps(&d->base) & YASL_PRIVATE_CAP_POPUPS); + assert(caps(&d->base) & YASL_PRIVATE_CAP_DRAG); + assert(caps(&d->base) & YASL_PRIVATE_CAP_DRAG_CARRY); /* 2. Popups: spec validation, calculation, creation, reposition, destruction */ - struct yasl_popup_spec invalid_specs[] = { + struct yasl_private_popup_spec invalid_specs[] = { {.size = {0, 100}}, {.size = {100, 0}}, {.size = {35000, 100}}, @@ -70,7 +78,7 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) assert(!surface_create_popup(&s->base, &invalid_specs[i])); } - struct yasl_popup_spec valid_spec = { + struct yasl_private_popup_spec valid_spec = { .size = {100, 120}, .anchor = {30, 40, 50, 60}, .beside = false, @@ -78,12 +86,40 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) }; assert(popup_spec_valid(s, &valid_spec)); int x = 0, y = 0; - popup_calculate_position(d, s, &valid_spec, &x, &y); + struct yasl_private_vector2i actual_size; + popup_calculate_position(d, s, &valid_spec, &x, &y, &actual_size); assert(x == 30 - 5); assert(y == 40 + 60 - 10); + /* Explicit XDG-style anchor/gravity stays exact unless a constraint allows a fit. */ + struct yasl_private_popup_spec positioned = { + .positioner_explicit = true, + .anchor_edges = 2, /* bottom */ + .gravity = 2, /* below */ + .size = {100, 120}, .anchor = {100, 100, 40, 20}, + .content_offset = {5, 10}, + }; + popup_calculate_position(d, s, &positioned, &x, &y, &actual_size); + assert(x == 68 && y == 110 && actual_size.x == 100 && actual_size.y == 120); + positioned.anchor_edges = 4; /* right edge */ + positioned.gravity = 4; /* to the right */ + positioned.anchor = (struct yasl_private_rect2i){1900, 100, 20, 20}; + positioned.constraints = 4; /* flip X */ + popup_calculate_position(d, s, &positioned, &x, &y, &actual_size); + assert(x == 1800 && actual_size.x == 100); + positioned.gravity = 0; + positioned.constraints = 1; /* slide X */ + popup_calculate_position(d, s, &positioned, &x, &y, &actual_size); + assert(x + actual_size.x == 1920); + positioned.content_offset = (struct yasl_private_vector2i){0, 0}; + positioned.gravity = 4; + positioned.constraints = 16; /* resize X */ + positioned.anchor = (struct yasl_private_rect2i){1880, 100, 20, 20}; + popup_calculate_position(d, s, &positioned, &x, &y, &actual_size); + assert(x == 1920 - actual_size.x && actual_size.x == 20); + valid_spec.beside = true; - popup_calculate_position(d, s, &valid_spec, &x, &y); + popup_calculate_position(d, s, &valid_spec, &x, &y, &actual_size); assert(x == 30 + 50 - 5); assert(y == 40 - 10); @@ -94,7 +130,7 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) assert(popup->parent == s); assert(popup->size.x == 100 && popup->size.y == 120); - struct yasl_popup_spec repo_spec = { + struct yasl_private_popup_spec repo_spec = { .size = {150, 180}, .anchor = {10, 20, 30, 40}, .beside = false, @@ -113,24 +149,24 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) struct drag_test_recorder rec1 = {0}; struct drag_test_recorder rec2 = {0}; - struct yasl_window_cbs cbs1 = {.drag = on_test_drag}; - struct yasl_window_cbs cbs2 = {.drag = on_test_drag}; + struct yasl_private_window_cbs cbs1 = {.drag = on_test_drag}; + struct yasl_private_window_cbs cbs2 = {.drag = on_test_drag}; set_callbacks(&s->base, &cbs1, &rec1); set_callbacks(&s2.base, &cbs2, &rec2); - enum yasl_drag_end end_reason = (enum yasl_drag_end)-1; - struct yasl_drag_listener l = {.end = on_test_drag_end}; + enum yasl_private_drag_end end_reason = (enum yasl_private_drag_end)-1; + struct yasl_private_drag_listener l = {.end = on_test_drag_end}; assert(drag_start(&d->base, &s->base, NULL, &l, &end_reason)); assert(d->drag.active); - /* Motion on s (window 42) -> YASL_DRAG_OVER on s */ + /* Motion on s (window 42) -> YASL_PRIVATE_DRAG_OVER on s */ XIDeviceEvent mev = {.evtype = XI_Motion, .sourceid = 8, .event = 42, .event_x = 12.0, .event_y = 34.0}; XGenericEventCookie cookie = {.evtype = XI_Motion, .data = &mev}; xi_event(d, &cookie); assert(rec1.over_count == 1); assert(rec1.last_pos.x == 12 && rec1.last_pos.y == 34); - /* Motion on s2 (window 43) -> YASL_DRAG_LEAVE on s, YASL_DRAG_OVER on s2 */ + /* Motion on s2 (window 43) -> YASL_PRIVATE_DRAG_LEAVE on s, YASL_PRIVATE_DRAG_OVER on s2 */ mev.event = 43; mev.event_x = 56.0; mev.event_y = 78.0; @@ -139,12 +175,12 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) assert(rec2.over_count == 1); assert(rec2.last_pos.x == 56 && rec2.last_pos.y == 78); - /* ButtonRelease -> YASL_DRAG_DROP on s2 and drag end */ + /* ButtonRelease -> YASL_PRIVATE_DRAG_DROP on s2 and drag end */ XIDeviceEvent rel = {.evtype = XI_ButtonRelease, .sourceid = 8, .event = 43, .detail = 1}; cookie = (XGenericEventCookie){.evtype = XI_ButtonRelease, .data = &rel}; xi_event(d, &cookie); assert(rec2.drop_count == 1); - assert(end_reason == YASL_DRAG_DROPPED); + assert(end_reason == YASL_PRIVATE_DRAG_DROPPED); assert(!d->drag.active); /* Drag cancel */ @@ -155,7 +191,7 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) assert(rec1.over_count == 2); drag_cancel(&d->base); assert(rec1.leave_count == 2); - assert(end_reason == YASL_DRAG_CANCELLED); + assert(end_reason == YASL_PRIVATE_DRAG_CANCELLED); assert(!d->drag.active); /* Hierarchy change cancels drag and pushes reset */ @@ -164,18 +200,18 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) XIHierarchyEvent hiev = {.evtype = XI_HierarchyChanged, .flags = XISlaveRemoved}; cookie = (XGenericEventCookie){.evtype = XI_HierarchyChanged, .data = &hiev}; xi_event(d, &cookie); - assert(end_reason == YASL_DRAG_CANCELLED); + assert(end_reason == YASL_PRIVATE_DRAG_CANCELLED); assert(!d->drag.active); - struct yasl_event reset_ev; - assert(yasl_surface_poll_event(&s->base, &reset_ev)); - assert(reset_ev.type == YASL_EVENT_INPUT_RESET); + struct yasl_private_event reset_ev; + assert(yasl_private_surface_poll_event(&s->base, &reset_ev)); + assert(reset_ev.type == YASL_PRIVATE_EVENT_INPUT_RESET); /* 4. Drag image parameter */ uint32_t pixels[16] = {0xFF00FF00}; - struct yasl_drag_image img = {.pixels = pixels, .size = {4, 4}, .hotspot = {2, 2}}; + struct yasl_private_drag_image img = {.pixels = pixels, .size = {4, 4}, .hotspot = {2, 2}}; assert(drag_start(&d->base, &s->base, &img, &l, &end_reason)); assert(d->drag.active); - assert(drag_carry(&s->base, (struct yasl_vector2i){10, 10})); + assert(drag_carry(&s->base, (struct yasl_private_vector2i){10, 10})); drag_cancel(&d->base); /* 5. XDND drop-target events and URI parsing */ @@ -246,11 +282,11 @@ 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_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); + /* Push YASL_PRIVATE_EVENT_DROP */ + push(s, (struct yasl_private_event){.type = YASL_PRIVATE_EVENT_DROP}, "file:///sample.png\r\n", 20); + struct yasl_private_event drop_ev; + assert(yasl_private_surface_poll_event(&s->base, &drop_ev)); + assert(drop_ev.type == YASL_PRIVATE_EVENT_DROP); assert(drop_ev.text.len == 20); assert(!strcmp(drop_ev.text.data, "file:///sample.png\r\n")); @@ -262,10 +298,18 @@ static void test_x11_gaps(struct x11_display *d, struct x11_surface *s) int main(void) { + /* External GPU surfaces retain geometry without allocating CPU targets. */ + struct x11_surface external = {0}; + external.base.presenter = YASL_PRIVATE_PRESENTER_NONE; + assert(resize(&external, (struct yasl_private_vector2i){640, 480})); + assert(external.size.x == 640 && external.size.y == 480 && !external.image && !external.pixels); + struct x11_display display = { - .base.ops = &yasl_x11_backend, .abs_pressure = 10, .abs_tilt_x = 11, .abs_tilt_y = 12, + .base.ops = &yasl_private_x11_backend, .abs_pressure = 10, .abs_tilt_x = 11, .abs_tilt_y = 12, }; - struct x11_surface surface = {.base.display = &display.base, .window = 42}; + struct x11_surface surface = {.base = {.display = &display.base, + .creation_flags = YASL_PRIVATE_SURFACE_CPU, + .presenter = YASL_PRIVATE_PRESENTER_CPU}, .window = 42}; display.surfaces = &surface; XIValuatorClassInfo pressure = {.type = XIValuatorClass, .number = 2, .label = 10, .min = 100, .max = 1100, .mode = XIModeAbsolute}; @@ -277,7 +321,7 @@ int main(void) XIDeviceInfo info = {.deviceid = 8, .name = "Tablet pen", .num_classes = 3, .classes = classes}; struct x11_pointer pointer = {0}; pointer_info(&display, &pointer, &info); - assert(pointer.device == YASL_PTR_DEV_PEN); + assert(pointer.device == YASL_PRIVATE_PTR_DEV_PEN); display.pointers = &pointer; /* Cache avoids requiring a real X server. */ unsigned char mask[1] = {0}; @@ -290,9 +334,15 @@ int main(void) .mods.effective = ShiftMask, .valuators = {sizeof(mask), mask, values}}; XGenericEventCookie cookie = {.evtype = XI_ButtonPress, .data = &sample}; xi_event(&display, &cookie); - 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); + struct yasl_private_event ev = next(&surface); + assert(ev.type == YASL_PRIVATE_EVENT_PEN && ev.pen.device_id == 8 && !ev.pen.tool_id); + assert(ev.pen.tool == 1 && ev.pen.action == YASL_PRIVATE_PEN_DOWN && ev.pen.in_contact); + assert((ev.pen.axes_valid & (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)) == + (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)); + assert(ev.pen.axes_changed == (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT)); + ev = next(&surface); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_DOWN && ev.pointer.button == YASL_PRIVATE_BUTTON_PRIMARY && ev.pointer.device == YASL_PRIVATE_PTR_DEV_PEN); + assert(ev.pointer.pos.x == 201 && ev.pointer.pos.y == 175 && ev.pointer.mods == YASL_PRIVATE_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. */ @@ -302,36 +352,48 @@ int main(void) sample.evtype = cookie.evtype = XI_Motion; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535); + assert(ev.type == YASL_PRIVATE_EVENT_PEN && ev.pen.action == YASL_PRIVATE_PEN_MOVE && + ev.pen.axes_valid == (YASL_PRIVATE_PEN_PRESSURE | YASL_PRIVATE_PEN_TILT) && + ev.pen.axes_changed == YASL_PRIVATE_PEN_PRESSURE && ev.pen.pressure == 1.0); + ev = next(&surface); + assert(ev.type == YASL_PRIVATE_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).type == YASL_PRIVATE_EVENT_PEN); assert(next(&surface).pointer.pen.pressure == 65535); values[0] = -50; xi_event(&display, &cookie); + assert(next(&surface).type == YASL_PRIVATE_EVENT_PEN); assert(next(&surface).pointer.pen.pressure == 0); info.name = "Tablet ERASER"; pointer_info(&display, &pointer, &info); - assert(pointer.device == YASL_PTR_DEV_ERASER); + assert(pointer.device == YASL_PRIVATE_PTR_DEV_ERASER); values[0] = 900; sample.evtype = cookie.evtype = XI_ButtonPress; xi_event(&display, &cookie); ev = next(&surface); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER && ev.pointer.pen.pressure > 0); + assert(ev.type == YASL_PRIVATE_EVENT_PEN && ev.pen.tool == 2 && ev.pen.action == YASL_PRIVATE_PEN_DOWN); + ev = next(&surface); + assert(ev.pointer.device == YASL_PRIVATE_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.type == YASL_EVENT_POINTER_UP && ev.pointer.button == YASL_BUTTON_PRIMARY && ev.pointer.pen.pressure == 0); - assert(ev.pointer.device == YASL_PTR_DEV_ERASER); + assert(ev.type == YASL_PRIVATE_EVENT_PEN && ev.pen.action == YASL_PRIVATE_PEN_UP && !ev.pen.in_contact); + ev = next(&surface); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_UP && ev.pointer.button == YASL_PRIVATE_BUTTON_PRIMARY && ev.pointer.pen.pressure == 0); + assert(ev.pointer.device == YASL_PRIVATE_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.type == YASL_EVENT_POINTER_LEAVE && ev.pointer.device == YASL_PTR_DEV_ERASER && !ev.pointer.pen.pressure); + assert(ev.type == YASL_PRIVATE_EVENT_PEN && ev.pen.action == YASL_PRIVATE_PEN_LEAVE); + ev = next(&surface); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_LEAVE && ev.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && !ev.pointer.pen.pressure); /* No tablet axes must produce an ordinary, pressure-free mouse. */ info.num_classes = 0; @@ -340,24 +402,48 @@ int main(void) sample.detail = 3; xi_pointer_event(&surface, &sample); ev = next(&surface); - assert(ev.pointer.device == YASL_PTR_DEV_MOUSE && ev.pointer.button == YASL_BUTTON_SECONDARY && ev.pointer.pen.pressure == 0); + assert(ev.pointer.device == YASL_PRIVATE_PTR_DEV_MOUSE && ev.pointer.button == YASL_PRIVATE_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.type == YASL_EVENT_POINTER_SCROLL); + assert(ev.type == YASL_PRIVATE_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)); + assert(ev.pointer.scroll_valid == 1u && ev.pointer.scroll_source == 1u && ev.pointer.scroll_phase == 2u); sample.evtype = XI_ButtonRelease; xi_pointer_event(&surface, &sample); - struct yasl_event unused; - assert(!yasl_surface_poll_event(&surface.base, &unused)); + struct yasl_private_event unused; + assert(!input_queue_pop(&surface.input, &unused)); } + /* XI2 smooth-scroll valuators preserve fractional line data and source. */ + XIValuatorClassInfo scroll_valuator = {.type = XIValuatorClass, .number = 9, + .value = 0, .mode = XIModeRelative}; + XIScrollClassInfo scroll_class = {.type = XIScrollClass, .number = 9, + .scroll_type = XIScrollTypeVertical, .increment = 2.0}; + XIAnyClassInfo *scroll_classes[] = {(void *)&scroll_valuator, (void *)&scroll_class}; + info.name = "Test touchpad"; + info.num_classes = 2; + info.classes = scroll_classes; + struct x11_pointer touchpad = {0}; + pointer_info(&display, &touchpad, &info); + display.pointers = &touchpad; + unsigned char scroll_mask[2] = {0}; + XISetMask(scroll_mask, 9); + double scroll_value[] = {-1.0}; + sample.evtype = XI_Motion; + sample.valuators = (XIValuatorState){sizeof(scroll_mask), scroll_mask, scroll_value}; + xi_pointer_event(&surface, &sample); + assert(next(&surface).type == YASL_PRIVATE_EVENT_POINTER_MOTION); + ev = next(&surface); + assert(ev.type == YASL_PRIVATE_EVENT_POINTER_SCROLL && ev.pointer.scroll_valid == 1u && + ev.pointer.scroll_source == 2u && ev.pointer.scroll.y == -0.5); + input_queue_clear(&surface.input); assert(pointer_button(2) == 1 && pointer_button(8) == 3); - pointer.pressure = (struct tablet_axis){2, 1, 1, 50}; + pointer.pressure = (struct tablet_axis){2, 1, 1, 50, true}; assert(pressure_value(&pointer.pressure) == 0); - pointer.tilt_x = (struct tablet_axis){4, -90, 90, -200}; + pointer.tilt_x = (struct tablet_axis){4, -90, 90, -200, true}; assert(tilt_value(&pointer.tilt_x) == -90); pointer.tilt_x.value = 200; assert(tilt_value(&pointer.tilt_x) == 90); diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c index 706a5cc..828082c 100644 --- a/tests/x11/test_tablet_native.c +++ b/tests/x11/test_tablet_native.c @@ -2,7 +2,7 @@ #define main tablet_example_main #include "../../examples/tablet.c" #undef main -#include +#include #include #include #include @@ -55,24 +55,24 @@ static int connect_tool(const char *path) return fd; } -static void native_draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud) +static void native_draw(struct yasl_surface *surface, struct yasl_private_frame *frame, void *ud) { (void)surface; draw(ud, surface, frame); } -static void native_configure(struct yasl_surface *surface, struct yasl_geometry geometry, void *ud) +static void native_configure(struct yasl_surface *surface, struct yasl_private_geometry geometry, void *ud) { - input(ud, &(struct yasl_event){.surface = surface, .type = YASL_EVENT_WINDOW_RESIZE, + input(ud, &(struct yasl_private_event){.surface = surface, .type = YASL_PRIVATE_EVENT_WINDOW_RESIZE, .resize = {.geometry = geometry}}); } -static void native_input(struct app *app, const struct yasl_event *event) +static void native_input(struct app *app, const struct yasl_private_event *event) { input(app, event); } -static void pump(int fd, struct yasl_display *display, struct yasl_surface *surface, struct app *app) +static void pump(int fd, struct yasl_private_display *display, struct yasl_surface *surface, struct app *app) { xf86ITEventWaitForSync sync = {{sizeof(sync), XF86IT_EVENT_WAIT_FOR_SYNC}}; send_all(fd, &sync, sizeof(sync)); @@ -81,14 +81,14 @@ static void pump(int fd, struct yasl_display *display, struct yasl_surface *surf assert(response.type == XF86IT_RESPONSE_SYNC_FINISHED && response.length == sizeof(response)); /* The driver acknowledgment guarantees input processing has finished. * 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_event event; - while (yasl_surface_poll_event(surface, &event)) { + XSync(yasl_private_display_get_native_handle(display), False); + assert(yasl_private_display_dispatch(display, 0) == 0); + struct yasl_private_event event; + while (yasl_private_surface_poll_event(surface, &event)) { native_input(app, &event); - yasl_surface_schedule_redraw(surface); + yasl_private_surface_schedule_redraw(surface); } - yasl_display_flush(display); + yasl_private_display_flush(display); assert(!app->failed); } @@ -116,23 +116,23 @@ static void set_eraser_property(Display *display) int main(int argc, char **argv) { assert(argc == 3); /* pen socket, eraser socket */ - struct app app = {.tablet_supported = true, .backend = YASL_BACKEND_X11}; - struct yasl_display_spec ds = {.backend = YASL_BACKEND_X11}; - struct yasl_display *display = yasl_display_open(NULL, &ds); - assert(display && (yasl_display_caps(display) & YASL_CAP_TABLET)); - struct yasl_window_spec ss = {.title = "YASL native pressure test", .size = {500, 400}}; - struct yasl_surface *surface = yasl_surface_create_toplevel(display, &ss); + struct app app = {.tablet_supported = true, .backend = YASL_PRIVATE_BACKEND_X11}; + struct yasl_private_display_spec ds = {.backend = YASL_PRIVATE_BACKEND_X11}; + struct yasl_private_display *display = yasl_private_display_open(NULL, &ds); + assert(display && (yasl_private_display_caps(display) & YASL_PRIVATE_CAP_TABLET)); + struct yasl_private_window_spec ss = {.title = "YASL native pressure test", .size = {500, 400}}; + struct yasl_surface *surface = yasl_private_surface_create_toplevel(display, &ss); assert(surface); - struct yasl_window_cbs cbs = {.draw = native_draw, .configure = native_configure}; - yasl_surface_set_callbacks(surface, &cbs, &app); - yasl_surface_schedule_redraw(surface); - Display *x = yasl_display_get_native_handle(display); - Window window = (Window)(uintptr_t)yasl_surface_get_native_handle(surface); + struct yasl_private_window_cbs cbs = {.draw = native_draw, .configure = native_configure}; + yasl_private_surface_set_callbacks(surface, &cbs, &app); + yasl_private_surface_schedule_redraw(surface); + Display *x = yasl_private_display_get_native_handle(display); + Window window = (Window)(uintptr_t)yasl_private_surface_get_native_handle(surface); XMoveWindow(x, window, 0, 0); XSetInputFocus(x, window, RevertToParent, CurrentTime); XSync(x, False); - assert(yasl_display_dispatch(display, 0) == 0); - yasl_display_flush(display); + assert(yasl_private_display_dispatch(display, 0) == 0); + yasl_private_display_flush(display); set_eraser_property(x); int pen_fd = connect_tool(argv[1]), eraser_fd = connect_tool(argv[2]); xf86ITEventMotion motion = {.header = {sizeof(motion), XF86IT_EVENT_MOTION}, .is_absolute = 1}; @@ -144,7 +144,7 @@ int main(int argc, char **argv) send_all(pen_fd, &proximity, sizeof(proximity)); send_all(pen_fd, &motion, sizeof(motion)); pump(pen_fd, display, surface, &app); - assert(app.visible && !app.down && app.pointer.device == YASL_PTR_DEV_PEN); + assert(app.visible && !app.down && app.pointer.device == YASL_PRIVATE_PTR_DEV_PEN); assert(app.pointer.pos.x == 150 && app.pointer.pos.y == 200); assert(app.canvas[(size_t)200 * app.geometry.size.x + 150] == PAPER); xf86ITEventButton button = {.header = {sizeof(button), XF86IT_EVENT_BUTTON}, @@ -177,7 +177,7 @@ int main(int argc, char **argv) button.valuators.valuators[4] = 1000; send_all(eraser_fd, &button, sizeof(button)); pump(eraser_fd, display, surface, &app); - assert(app.down && app.pointer.device == YASL_PTR_DEV_ERASER && app.pointer.pen.pressure == 65535); + assert(app.down && app.pointer.device == YASL_PRIVATE_PTR_DEV_ERASER && app.pointer.pen.pressure == 65535); assert(app.canvas[(size_t)200 * app.geometry.size.x + 150] == PAPER && app.canvas[(size_t)200 * app.geometry.size.x + 170] == PAPER); button.is_press = 0; @@ -187,8 +187,8 @@ int main(int argc, char **argv) close(pen_fd); close(eraser_fd); free(app.canvas); - yasl_surface_destroy(surface); - yasl_display_close(display); + yasl_private_surface_destroy(surface); + yasl_private_display_close(display); puts("Native Xorg pen pressure, stationary pressure, release, and eraser drawing passed."); return 0; } -- cgit v1.2.3