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 +++++++++++++++++++++++++++--------- src/common/app_internal.h | 3 +-- src/common/backend.c | 4 +--- src/common/backend.h | 3 +-- src/common/keyboard.h | 2 +- 5 files changed, 31 insertions(+), 17 deletions(-) (limited to 'src/common') 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; } diff --git a/src/common/app_internal.h b/src/common/app_internal.h index 64fa34c..143df41 100644 --- a/src/common/app_internal.h +++ b/src/common/app_internal.h @@ -1,8 +1,7 @@ #ifndef YASL_APP_INTERNAL_H #define YASL_APP_INTERNAL_H -#include "yasl/app.h" -#include "common/backend.h" +struct yasl_surface; void app_runner_register_surface(void *runner, struct yasl_surface *s); void app_runner_unregister_surface(void *runner, struct yasl_surface *s); diff --git a/src/common/backend.c b/src/common/backend.c index be06136..3f2143d 100644 --- a/src/common/backend.c +++ b/src/common/backend.c @@ -328,9 +328,7 @@ struct yasl_geometry yasl_surface_geometry(const struct yasl_surface *s) uint32_t yasl_surface_state(const struct yasl_surface *s) { - if (!s || !s->display->ops->surface_state) - return 0; - return s->display->ops->surface_state(s); + return s ? s->state : 0; } struct yasl_timing yasl_surface_timing(const struct yasl_surface *s) diff --git a/src/common/backend.h b/src/common/backend.h index 37fa167..17d781e 100644 --- a/src/common/backend.h +++ b/src/common/backend.h @@ -22,7 +22,7 @@ struct yasl_surface { void *native_handle; struct yasl_vector2i size; uint32_t scale_120; - uint32_t state; + uint32_t state; /* Authoritative YASL_STATE_* bitmask, maintained by the backend. */ uint32_t bg_color; struct yasl_window_cbs callbacks; void *ud; @@ -72,7 +72,6 @@ struct yasl_backend_ops { bool (*surface_present)(struct yasl_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); bool (*surface_input_poll)(struct yasl_surface *s, struct yasl_input_event *ev); struct yasl_geometry (*surface_geometry)(const struct yasl_surface *s); - uint32_t (*surface_state)(const struct yasl_surface *s); struct yasl_timing (*surface_timing)(const struct yasl_surface *s); uint64_t (*surface_frame_time_ns)(struct yasl_surface *s, uint64_t now); void (*surface_set_cursor)(struct yasl_surface *s, enum yasl_cursor cursor); diff --git a/src/common/keyboard.h b/src/common/keyboard.h index 77c6380..d8b8bbc 100644 --- a/src/common/keyboard.h +++ b/src/common/keyboard.h @@ -1,7 +1,7 @@ #ifndef YASL_COMMON_KEYBOARD_H #define YASL_COMMON_KEYBOARD_H -#include "yasl/yasl.h" +#include /* Layout labels omit controls, invalid Unicode, and Cocoa function-key PUA. */ static inline uint32_t yasl_key_label(uint32_t cp) -- cgit v1.2.3