summaryrefslogtreecommitdiff
path: root/src/common/app.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 15:05:06 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 15:05:06 +0300
commit98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (patch)
tree90b03d0930986620d95eb0f45c07b96e1331783c /src/common/app.c
parent339e1ad7adb8340732ee856d0f6f0d2c7f1455d1 (diff)
Simplify surface state, examples, and library installation
Diffstat (limited to 'src/common/app.c')
-rw-r--r--src/common/app.c36
1 files changed, 27 insertions, 9 deletions
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;
}