From 87279f6903343e621c0446b20d1e7d6a495f1125 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Wed, 14 Oct 2026 13:56:48 +0300 Subject: Simplify the public API into one dense header yasl.h now holds everything except Vulkan: 45 functions instead of 62, and three installed headers instead of ten. - One constructor: yasl_surface_create takes CPU, GL or NATIVE, with zero-initialized GL options meaning 3.2 core, RGBA8, D24S8. - Events carry action, mods, x, y and text at the top level; pen positions are now logical like pointer positions. - yasl_cpu_pixels/yasl_cpu_present draw into one persistent canvas, cutting three full-frame copies per frame. - yasl_surface_get_info, yasl_surface_request, YASL_CURSOR_LOCKED, yasl_surface_set_text_input, yasl_surface_begin_move_resize and yasl_surface_get_native replace groups of narrower calls. - Interactive calls drop the decorative trigger event argument. - yasl_wait_event returns 0 only on timeout or yasl_wake, the refresh callback runs only in native modal loops, focus loss sends INPUT_RESET, and a lost event no longer fails every later wait. - Unsupported operations and bad arguments report ENOTSUP and EINVAL instead of EIO; the keycodes header no longer needs C23. - The shared library gets a versioned SONAME and version macros. Co-Authored-By: Claude Opus 5.5 --- tests/x11/test_tablet_native.c | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'tests/x11') diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c index 66cdd93..bbe39f2 100644 --- a/tests/x11/test_tablet_native.c +++ b/tests/x11/test_tablet_native.c @@ -2,7 +2,6 @@ #define main tablet_example_main #include "../../examples/tablet.c" #undef main -#include #include #include #include @@ -59,7 +58,8 @@ static int connect_tool(const char *path) } struct canvas_state { - struct yasl_pen_payload pen; + struct yasl_pen_event pen; + double x, y; uint32_t *pixels; int width, height, painted_width, painted_height; bool down; @@ -69,24 +69,24 @@ static void render_event(yasl_surface *surface, struct canvas_state *state, cons { if (event->type == YASL_EVENT_PEN) { state->pen = event->pen; + state->x = event->x; + state->y = event->y; state->down = event->pen.in_contact; } - struct yasl_cpu_buffer buffer; free(state->pixels); - state->pixels = canvas(surface, &state->width, &state->height, - &state->painted_width, &state->painted_height, false, &buffer); - assert(state->pixels); + uint32_t *pixels = canvas(surface, &state->width, &state->height, + &state->painted_width, &state->painted_height, false); + assert(pixels); if (event->type == YASL_EVENT_PEN && state->down && - (event->pen.action == YASL_PEN_DOWN || event->pen.action == YASL_PEN_MOVE)) { - double scale = yasl_surface_get_scale(surface); - stamp(state->pixels, state->width, state->height, - event->pen.x * scale, event->pen.y * scale, + (event->action == YASL_PEN_DOWN || event->action == YASL_PEN_MOVE)) { + double scale = yasl_surface_get_info(surface).scale; + stamp(pixels, state->width, state->height, event->x * scale, event->y * scale, (1.5 + 12 * event->pen.pressure) * scale, event->pen.tool == YASL_PEN_ERASER); } uint32_t *snapshot = malloc((size_t)state->width * state->height * sizeof(*snapshot)); assert(snapshot); - memcpy(snapshot, buffer.pixels, (size_t)state->width * state->height * sizeof(*snapshot)); - assert(yasl_cpu_present(surface, &buffer) == 0); + memcpy(snapshot, pixels, (size_t)state->width * state->height * sizeof(*snapshot)); + assert(yasl_cpu_present(surface) == 0); state->pixels = snapshot; } @@ -107,12 +107,12 @@ static void pump(int fd, yasl_surface *surface, struct canvas_state *state) receive_all(fd, &response, sizeof(response)); assert(response.type == XF86IT_RESPONSE_SYNC_FINISHED && response.length == sizeof(response)); /* The driver acknowledgment guarantees XI2 processing has finished. */ - struct yasl_x11_handles native; - assert(yasl_x11_get_native(surface, &native) == 0); - XSync(native.display, False); + struct yasl_native native; + assert(yasl_surface_get_native(surface, &native) == 0); + XSync(native.x11_display, False); drain(surface, state); /* Public polling submits the CPU frame before the native readback. */ - XSync(native.display, False); + XSync(native.x11_display, False); } static void set_eraser_property(Display *display) @@ -140,13 +140,13 @@ int main(int argc, char **argv) { assert(argc == 3); /* pen socket, eraser socket */ struct canvas_state app = {0}; - assert((yasl_init(&(struct yasl_options){.backend=YASL_BACKEND_X11}) == 0)); - yasl_surface *surface = yasl_surface_create(&(struct yasl_surface_options){.title="YASL native pressure test", .width=500, .height=400, .type=YASL_SURFACE_CPU, .flags=0}); - assert(surface && (yasl_surface_get_features(surface) & YASL_CAP_TABLET)); - struct yasl_x11_handles native; - assert(yasl_x11_get_native(surface, &native) == 0); - Display *x = native.display; - Window window = (Window)native.window; + assert(yasl_init(YASL_BACKEND_X11, NULL) == 0); + yasl_surface *surface = yasl_surface_create(&(struct yasl_surface_options){.title="YASL native pressure test", .width=500, .height=400}); + assert(surface && (yasl_get_features() & YASL_FEATURE_TABLET)); + struct yasl_native native; + assert(yasl_surface_get_native(surface, &native) == 0); + Display *x = native.x11_display; + Window window = (Window)native.x11_window; XMoveWindow(x, window, 0, 0); XSetInputFocus(x, window, RevertToParent, CurrentTime); XSync(x, False); @@ -163,7 +163,7 @@ int main(int argc, char **argv) send_all(pen_fd, &motion, sizeof(motion)); pump(pen_fd, surface, &app); assert(!app.down && app.pen.tool == YASL_PEN_PEN); - assert(app.pen.x == 150 && app.pen.y == 200); + assert(app.x == 150 && app.y == 200); assert(app.pixels[(size_t)200 * app.width + 150] == PAPER); xf86ITEventButton button = {.header = {sizeof(button), XF86IT_EVENT_BUTTON}, .is_absolute = 1, .button = 1, .is_press = 1, .valuators = motion.valuators}; -- cgit v1.2.3