summaryrefslogtreecommitdiff
path: root/examples/simple_window.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 15:41:39 +0300
commit537b2d768b31deb0f95c5122e0d562e4406ae9a0 (patch)
treecc3e85cb2990672c11b4e35c6dbcfaac733d09f5 /examples/simple_window.c
parent98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (diff)
Unify core and runner events into struct yasl_event
The core input queue and the yasl_run() runner each had their own event type, and the runner translated one into the other. Both now share struct yasl_event in <yasl/yasl.h>: yasl_surface_poll_event() returns the same events the app event callback receives, so the runner forwards them unchanged. Pointer input becomes POINTER_DOWN/UP/MOTION/SCROLL/LEAVE with a named yasl_pointer_button and a motion delta computed in the input queue. TEXT, PASTE and DROP share one text payload, scale changes fold into WINDOW_RESIZE, and every event carries a monotonic time_ns. yasl_surface_set_mouse_mode() is replaced by yasl_surface_set_pointer_mode(); no backend implements relative mode yet. The export check now only counts YASL_API declarations, so function pointer fields returning enum yasl_app_result are not mistaken for exports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples/simple_window.c')
-rw-r--r--examples/simple_window.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/examples/simple_window.c b/examples/simple_window.c
index e9e6545..fca2f75 100644
--- a/examples/simple_window.c
+++ b/examples/simple_window.c
@@ -87,7 +87,7 @@ static void on_draw(void *ud, struct yasl_surface *s, struct yasl_frame_context
if (failed || smoke_test) yasl_surface_destroy(s);
}
-static int on_init(void *ud, struct yasl_display *display)
+static enum yasl_app_result on_init(void *ud, struct yasl_display *display)
{
(void)ud;
struct yasl_window_spec window_spec = {
@@ -123,19 +123,19 @@ static void pointer_sample(struct yasl_vector2i pos, enum yasl_pointer_device de
pen_tilt_y = pen.tilt_y;
}
-static int on_event(void *ud, const struct yasl_event *ev)
+static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev)
{
(void)ud;
switch (ev->type) {
- case YASL_EVENT_WINDOW_CLOSE_REQUEST:
+ case YASL_EVENT_WINDOW_CLOSE:
return YASL_APP_QUIT;
case YASL_EVENT_WINDOW_RESIZE: {
uint32_t flags = yasl_surface_state(ev->surface);
const char *mode = flags & YASL_STATE_FULLSCREEN ? "fullscreen" :
flags & YASL_STATE_MAXIMIZED ? "maximized" :
flags & YASL_STATE_TILED ? "tiled" : "windowed";
- printf("[YASL] Resized to %dx%d (scale: %.2fx, %s)\n", ev->resize.size.x,
- ev->resize.size.y, (double)ev->resize.scale_120 / YASL_SCALE_UNIT, mode);
+ printf("[YASL] Resized to %dx%d (scale: %.2fx, %s)\n", ev->resize.geometry.size.x,
+ ev->resize.geometry.size.y, (double)ev->resize.geometry.scale_120 / YASL_SCALE_UNIT, mode);
break;
}
case YASL_EVENT_KEY:
@@ -144,22 +144,23 @@ static int on_event(void *ud, const struct yasl_event *ev)
if (ev->key.key == YASL_KEY_SPACE || ev->key.key == YASL_KEY_ENTER)
color_theme++;
break;
- case YASL_EVENT_MOUSE_BUTTON:
- pointer_sample(ev->mouse_button.pos, ev->mouse_button.device, ev->mouse_button.pen);
- if (ev->mouse_button.button == 0) {
- mouse_down = ev->mouse_button.pressed;
- if (!mouse_down) pen_pressure = 0;
+ case YASL_EVENT_POINTER_DOWN:
+ case YASL_EVENT_POINTER_UP:
+ case YASL_EVENT_POINTER_MOTION:
+ pointer_sample(ev->pointer.pos, ev->pointer.device, ev->pointer.pen);
+ if (ev->type == YASL_EVENT_POINTER_DOWN && ev->pointer.button == YASL_BUTTON_PRIMARY) {
+ mouse_down = true;
+ } else if (ev->type == YASL_EVENT_POINTER_UP && ev->pointer.button == YASL_BUTTON_PRIMARY) {
+ mouse_down = false;
+ pen_pressure = 0;
}
break;
- case YASL_EVENT_MOUSE_MOTION:
- pointer_sample(ev->mouse_motion.pos, ev->mouse_motion.device, ev->mouse_motion.pen);
- break;
- case YASL_EVENT_WINDOW_FOCUS:
+ case YASL_EVENT_FOCUS:
if (ev->focus.focused) return YASL_APP_CONTINUE;
/* Fall through to cancel held input on focus loss. */
[[fallthrough]];
case YASL_EVENT_INPUT_RESET:
- case YASL_EVENT_MOUSE_LEAVE:
+ case YASL_EVENT_POINTER_LEAVE:
mouse_x = mouse_y = -1;
mouse_down = false;
pen_pressure = 0;