From 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 15:05:06 +0300 Subject: Simplify surface state, examples, and library installation --- src/common/app.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/common/app.c') diff --git a/src/common/app.c b/src/common/app.c index da9747d..e1148f9 100644 --- a/src/common/app.c +++ b/src/common/app.c @@ -35,6 +35,7 @@ struct app_runner { struct yasl_display *display; const struct yasl_app_desc *desc; bool running; + bool failed; bool had_surfaces; int surface_count; struct app_surface *surfaces; @@ -380,6 +381,7 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) if (ie.mouse.kind == YASL_PTR_PRESS || ie.mouse.kind == YASL_PTR_RELEASE) { ev.type = YASL_EVENT_MOUSE_BUTTON; ev.mouse_button.pos = ie.mouse.pos; + ev.mouse_button.device = ie.mouse.device; ev.mouse_button.button = ie.mouse.button; ev.mouse_button.pressed = (ie.mouse.kind == YASL_PTR_PRESS); ev.mouse_button.mods = ie.mouse.mods; @@ -391,6 +393,7 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) } else if (ie.mouse.kind == YASL_PTR_MOTION) { ev.type = YASL_EVENT_MOUSE_MOTION; ev.mouse_motion.pos = ie.mouse.pos; + ev.mouse_motion.device = ie.mouse.device; if (as->has_last_mouse_pos) { ev.mouse_motion.delta.x = ie.mouse.pos.x - as->last_mouse_pos.x; ev.mouse_motion.delta.y = ie.mouse.pos.y - as->last_mouse_pos.y; @@ -439,6 +442,9 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) break; case YASL_INPUT_RESET: as->has_last_mouse_pos = false; + ev.type = YASL_EVENT_INPUT_RESET; + if (ar->desc->event(ar->desc->userdata, &ev) == YASL_APP_QUIT) + ar->running = false; break; default: break; @@ -447,27 +453,38 @@ static void app_runner_dispatch_input_events(struct app_runner *ar) } } +static void app_runner_quit(void *ud) +{ + ((struct app_runner *)ud)->running = false; +} + +static void app_runner_lost(void *ud) +{ + struct app_runner *runner = ud; + runner->failed = true; + runner->running = false; +} + int yasl_run(const struct yasl_app_desc *desc) { if (!desc || !desc->init) return -1; + struct app_runner runner = {.desc = desc, .running = true}; + const struct yasl_display_cbs callbacks = { + .quit = app_runner_quit, .lost = app_runner_lost, + }; struct yasl_display_spec dspec = { .app_id = desc->app_id, .backend = desc->backend, + .cbs = &callbacks, + .ud = &runner, }; struct yasl_display *d = yasl_display_open(NULL, &dspec); if (!d) return -1; - struct app_runner runner = { - .display = d, - .desc = desc, - .running = true, - .had_surfaces = false, - .surface_count = 0, - .surfaces = NULL, - }; + runner.display = d; int sync_error = yasl_mutex_init(&runner.user_event_mutex); if (sync_error) { yasl_display_close(d); @@ -503,6 +520,7 @@ int yasl_run(const struct yasl_app_desc *desc) int res = yasl_display_dispatch(d, timeout_ms); if (res < 0) { + runner.failed = true; break; } @@ -546,5 +564,5 @@ int yasl_run(const struct yasl_app_desc *desc) yasl_mutex_destroy(&runner.user_event_mutex); yasl_display_close(d); - return 0; + return runner.failed ? -1 : 0; } -- cgit v1.2.3