diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:41:39 +0300 |
| commit | 38533c81e7b7ebfc5f281c2523188aeaa38d09c3 (patch) | |
| tree | 4ba509a81be479748b313e0935a01ae80cea3ae2 | |
| parent | 482f799d356a8fbb8f585c4de7cc0992b8dc6fd3 (diff) | |
Drop the app state struct from the hello example
hello only tracked a failure flag, so keep it as a file-scope static like
simple_window and leave yasl_app_desc.userdata unset.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | examples/hello.c | 17 | ||||
| -rw-r--r-- | tests/common/test_hello_example.c | 7 |
2 files changed, 10 insertions, 14 deletions
diff --git a/examples/hello.c b/examples/hello.c index ded4235..1761e04 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -3,17 +3,16 @@ #include <stdio.h> -struct app { - bool failed; -}; +static bool failed; static enum yasl_app_result init(void *ud, struct yasl_display *display) { + (void)ud; struct yasl_window_spec spec = {.title = "Hello YASL", .size = {640, 480}}; struct yasl_surface *surface = yasl_surface_create_toplevel(display, &spec); if (!surface) { perror("yasl_surface_create_toplevel"); - ((struct app *)ud)->failed = true; + failed = true; return YASL_APP_QUIT; } yasl_surface_request_frame(surface); @@ -28,29 +27,27 @@ static enum yasl_app_result event(void *ud, const struct yasl_event *event) static void draw(void *ud, struct yasl_surface *surface, struct yasl_frame_context *frame) { - struct app *app = ud; + (void)ud; size_t count = (size_t)frame->size.x * frame->size.y; for (size_t i = 0; i < count; i++) frame->cpu.pixels[i] = 0xff306090; /* Opaque premultiplied ARGB. */ if (!yasl_frame_present_cpu(frame, NULL, 0)) { fprintf(stderr, "Could not present the draw target\n"); - app->failed = true; + failed = true; } - if (app->failed) yasl_surface_destroy(surface); + if (failed) yasl_surface_destroy(surface); } int main(void) { - struct app app = {0}; struct yasl_app_desc desc = { .app_id = "org.example.hello", - .userdata = &app, .init = init, .event = event, .frame = draw, }; int result = yasl_run(&desc); if (result) fprintf(stderr, "Could not run the application\n"); - return result || app.failed ? 1 : 0; + return result || failed ? 1 : 0; } diff --git a/tests/common/test_hello_example.c b/tests/common/test_hello_example.c index 6e0318f..7faa147 100644 --- a/tests/common/test_hello_example.c +++ b/tests/common/test_hello_example.c @@ -6,15 +6,14 @@ static void draw_once(void *ud, struct yasl_surface *surface, struct yasl_frame_context *frame) { draw(ud, surface, frame); - if (!((struct app *)ud)->failed) yasl_surface_destroy(surface); + if (!failed) yasl_surface_destroy(surface); } int main(void) { - struct app app = {0}; struct yasl_app_desc desc = { - .app_id = "org.yasl.test.hello", .userdata = &app, + .app_id = "org.yasl.test.hello", .init = init, .event = event, .frame = draw_once, }; - return yasl_run(&desc) || app.failed ? 1 : 0; + return yasl_run(&desc) || failed ? 1 : 0; } |
