From 537b2d768b31deb0f95c5122e0d562e4406ae9a0 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 15:41:39 +0300 Subject: Unify core and runner events into struct yasl_event The core input queue and the yasl_run() runner each had their own event type, and the runner translated one into the other. Both now share struct yasl_event in : yasl_surface_poll_event() returns the same events the app event callback receives, so the runner forwards them unchanged. Pointer input becomes POINTER_DOWN/UP/MOTION/SCROLL/LEAVE with a named yasl_pointer_button and a motion delta computed in the input queue. TEXT, PASTE and DROP share one text payload, scale changes fold into WINDOW_RESIZE, and every event carries a monotonic time_ns. yasl_surface_set_mouse_mode() is replaced by yasl_surface_set_pointer_mode(); no backend implements relative mode yet. The export check now only counts YASL_API declarations, so function pointer fields returning enum yasl_app_result are not mistaken for exports. Co-Authored-By: Claude Opus 5.5 --- examples/tablet.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'examples/tablet.c') diff --git a/examples/tablet.c b/examples/tablet.c index f392cdc..01dcdfc 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -140,44 +140,40 @@ static void stroke(struct app *app) app->previous = true; } -static int input(void *ud, const struct yasl_event *event) +static enum yasl_app_result input(void *ud, const struct yasl_event *event) { struct app *app = ud; - if (event->type == YASL_EVENT_WINDOW_CLOSE_REQUEST) + if (event->type == YASL_EVENT_WINDOW_CLOSE) return YASL_APP_QUIT; if (event->type == YASL_EVENT_WINDOW_RESIZE) { - if (!resize_canvas(app, (struct yasl_geometry){event->resize.size, event->resize.scale_120})) { + if (!resize_canvas(app, event->resize.geometry)) { app->failed = true; return YASL_APP_QUIT; } - } else if (event->type == YASL_EVENT_INPUT_RESET || event->type == YASL_EVENT_MOUSE_LEAVE || - (event->type == YASL_EVENT_WINDOW_FOCUS && !event->focus.focused)) { + } else if (event->type == YASL_EVENT_INPUT_RESET || event->type == YASL_EVENT_POINTER_LEAVE || + (event->type == YASL_EVENT_FOCUS && !event->focus.focused)) { cancel_stroke(app); } else if (event->type == YASL_EVENT_KEY && event->key.action == YASL_KEY_PRESS) { if (event->key.key == YASL_KEY_ESCAPE) return YASL_APP_QUIT; if (event->key.key == YASL_KEY_C || event->key.key == YASL_KEY_SPACE) clear_canvas(app); - } else if (event->type == YASL_EVENT_MOUSE_BUTTON) { - if (app->pointer.device != event->mouse_button.device) cancel_stroke(app); - app->pointer.pos = event->mouse_button.pos; - app->pointer.device = event->mouse_button.device; - app->pointer.pen = event->mouse_button.pen; + } else if (event->type == YASL_EVENT_POINTER_DOWN || event->type == YASL_EVENT_POINTER_UP || + event->type == YASL_EVENT_POINTER_MOTION) { + if (app->pointer.device != event->pointer.device) cancel_stroke(app); + app->pointer.pos = event->pointer.pos; + app->pointer.device = event->pointer.device; + app->pointer.pen = event->pointer.pen; app->visible = true; - if (event->mouse_button.pressed && event->mouse_button.button == 0) { + if (event->type == YASL_EVENT_POINTER_DOWN && event->pointer.button == YASL_BUTTON_PRIMARY) { app->down = true; app->previous = false; stroke(app); - } else if (!event->mouse_button.pressed && event->mouse_button.button == 0) { + } else if (event->type == YASL_EVENT_POINTER_UP && event->pointer.button == YASL_BUTTON_PRIMARY) { app->down = app->previous = false; app->pointer.pen.pressure = 0; + } else if (event->type == YASL_EVENT_POINTER_MOTION) { + if (app->down) stroke(app); } - } else if (event->type == YASL_EVENT_MOUSE_MOTION) { - if (app->pointer.device != event->mouse_motion.device) cancel_stroke(app); - app->pointer.pos = event->mouse_motion.pos; - app->pointer.device = event->mouse_motion.device; - app->pointer.pen = event->mouse_motion.pen; - app->visible = true; - if (app->down) stroke(app); } else { return YASL_APP_CONTINUE; } @@ -293,7 +289,7 @@ static void draw(void *ud, struct yasl_surface *surface, struct yasl_frame_conte } } -static int init(void *ud, struct yasl_display *display) +static enum yasl_app_result init(void *ud, struct yasl_display *display) { struct app *app = ud; app->backend = yasl_display_backend(display); @@ -307,7 +303,7 @@ static int init(void *ud, struct yasl_display *display) app->failed = true; return YASL_APP_QUIT; } - yasl_surface_set_mouse_mode(app->surface, YASL_MOUSE_HIDDEN); + yasl_surface_set_cursor(app->surface, YASL_CURSOR_HIDDEN); yasl_surface_request_frame(app->surface); printf("YASL tablet on %s: pressure changes brush width; eraser removes ink.\n" "Mouse: fixed-width drawing. C/Space: clear. Escape: quit.\n", -- cgit v1.2.3