diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -113,6 +113,8 @@ These tests need a desktop session. ```c #include <yasl/yasl.h> +static bool running = true; + static void on_draw(struct yasl_surface *s, struct yasl_frame *frame, void *ud) { /* Present frame target */ @@ -120,29 +122,44 @@ static void on_draw(struct yasl_surface *s, struct yasl_frame *frame, void *ud) yasl_surface_present(s, &frame->target, &dmg); } +static void on_close(struct yasl_surface *s, void *ud) +{ + (void)s; (void)ud; + running = false; +} + int main(void) { - struct yasl_loop *loop = yasl_loop_create(); struct yasl_display_spec dspec = { .app_id = "org.example.app" }; - struct yasl_display *d = yasl_display_open(loop, &dspec); + struct yasl_display *d = yasl_display_open(NULL, &dspec); struct yasl_surface_spec sspec = { .title = "YASL Application", .size = { .x = 800, .y = 600 }, }; struct yasl_surface *s = yasl_surface_create_toplevel(d, &sspec); - struct yasl_surface_cbs cbs = { .draw = on_draw }; + struct yasl_surface_cbs cbs = { + .draw = on_draw, + .close = on_close, + }; yasl_surface_set_callbacks(s, &cbs, NULL); yasl_surface_schedule_redraw(s); - while (true) { + while (running) { yasl_display_dispatch(d); struct yasl_input_event ev; while (yasl_surface_input_poll(s, &ev)) { - /* Handle input */ + if (ev.kind == YASL_INPUT_KEY && ev.key.action == YASL_KEY_PRESS) { + if (ev.key.key == 0xff1b) /* Escape */ + running = false; + } } yasl_display_flush(d); } + + yasl_surface_destroy(s); + yasl_display_close(d); + return 0; } ``` |
