From 76073fe5fad8799e5850805f2f090af2cb62c741 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 23:41:31 +0300 Subject: Simplify the public event and CPU API Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 --- examples/hello.c | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) (limited to 'examples/hello.c') diff --git a/examples/hello.c b/examples/hello.c index 31ab18b..9e324a6 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -1,38 +1,26 @@ -/* A complete CPU-rendered window. Build instructions: docs/getting-started.md. */ -#include -#include +/* A CPU-rendered window. Build instructions: docs/getting-started.md. */ +#include +#include -static bool failed; -static void draw(void *ud, struct yasl_surface *surface, struct yasl_frame *frame) +int main(void) { - (void)ud; - int w = frame->target.size.x, h = frame->target.size.y; - for (int y = 0; y < h; y++) { - uint32_t *row = frame->target.pixels + (size_t)y * (frame->target.stride_bytes / 4); - for (int x = 0; x < w; x++) { - /* Red grows rightward, green downward, blue fades; opaque premultiplied ARGB. */ - uint32_t r = (uint32_t)(x * 255 / (w > 1 ? w - 1 : 1)); - uint32_t g = (uint32_t)(y * 255 / (h > 1 ? h - 1 : 1)); - row[x] = 0xff000000 | r << 16 | g << 8 | (255 - r); + yasl_surface *surface = yasl_surface_create("Hello YASL", 640, 480, YASL_SURFACE_CPU); + yasl_event event; + while (surface && yasl_wait_event(&event, -1) >= 0 && + event.type != YASL_EVENT_CLOSE && event.type != YASL_EVENT_QUIT) { + if (event.type != YASL_EVENT_REFRESH) continue; + int w, h; + uint32_t *pixels = yasl_cpu_pixels(surface, &w, &h); + for (int y = 0; pixels && y < h; y++) { + for (int x = 0; x < w; x++) { + /* Red grows rightward, green downward, blue fades; opaque premultiplied ARGB. */ + uint32_t r = (uint32_t)(x * 255 / (w > 1 ? w - 1 : 1)); + uint32_t g = (uint32_t)(y * 255 / (h > 1 ? h - 1 : 1)); + pixels[(size_t)y * w + x] = 0xff000000 | r << 16 | g << 8 | (255 - r); + } } + yasl_cpu_present(surface); } - - if (!yasl_frame_present(frame, NULL, 0)) { - fprintf(stderr, "Could not present the draw target\n"); - failed = true; - } - if (failed) yasl_app_exit(yasl_surface_display(surface), YASL_APP_ERROR); -} - -int main(void) -{ - struct yasl_window_spec window = {.title = "Hello YASL", .size_logical = {640, 480}}; - struct yasl_app_desc desc = { - .app_id = "org.example.hello", - .window = &window, - .frame = draw, - }; - int result = yasl_run(&desc); - if (result) fprintf(stderr, "Could not run the application\n"); - return result || failed ? 1 : 0; + yasl_shutdown(); + return surface ? 0 : 1; } -- cgit v1.2.3