summaryrefslogtreecommitdiff
path: root/include/yasl/app.h
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 /include/yasl/app.h
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 'include/yasl/app.h')
-rw-r--r--include/yasl/app.h125
1 files changed, 5 insertions, 120 deletions
diff --git a/include/yasl/app.h b/include/yasl/app.h
index 112140d..f067d5b 100644
--- a/include/yasl/app.h
+++ b/include/yasl/app.h
@@ -41,114 +41,6 @@ typedef enum yasl_pacing_mode {
YASL_PACING_CONTINUOUS,
} yasl_pacing_mode;
-/** Mouse capture and virtualization modes. */
-typedef enum yasl_mouse_mode {
- YASL_MOUSE_NORMAL = 0, /**< Standard visible pointer. */
- YASL_MOUSE_HIDDEN, /**< Hidden cursor, normal bounded window coordinates. */
- YASL_MOUSE_RELATIVE, /**< Relative pointer lock: cursor hidden, unbounded deltas. */
-} yasl_mouse_mode;
-
-/** Unified event types delivered to the application event callback. */
-typedef enum yasl_event_type {
- YASL_EVENT_NONE = 0,
-
- /* Input events */
- YASL_EVENT_KEY,
- YASL_EVENT_TEXT,
- YASL_EVENT_MOUSE_BUTTON,
- YASL_EVENT_MOUSE_MOTION,
- YASL_EVENT_MOUSE_SCROLL,
- YASL_EVENT_MOUSE_LEAVE,
-
- /* Window lifecycle events */
- YASL_EVENT_WINDOW_RESIZE,
- YASL_EVENT_WINDOW_SCALE_CHANGED,
- YASL_EVENT_WINDOW_CLOSE_REQUEST,
- YASL_EVENT_WINDOW_FOCUS,
-
- /* System & external events */
- YASL_EVENT_PASTE,
- YASL_EVENT_DROP_FILES,
- YASL_EVENT_USER,
- YASL_EVENT_INPUT_RESET, /**< Input interrupted; clear held keys/buttons and composition. */
-} yasl_event_type;
-
-/** Unified event payload delivered to yasl_app_desc.event(). */
-struct yasl_event {
- struct yasl_surface *surface; /**< Associated surface, or NULL for display-wide events. */
- yasl_event_type type;
-
- union {
- struct {
- enum yasl_key key;
- enum yasl_key_action action;
- uint32_t mods;
- uint32_t codepoint;
- uint32_t shifted;
- uint32_t native_code;
- bool repeat; /**< true if this press is generated by OS autorepeat. */
- } key;
-
- struct {
- const char *text; /**< UTF-8 text string; borrowed for callback duration. */
- size_t len; /**< Length in bytes excluding terminating NUL. */
- } text;
-
- struct {
- struct yasl_vector2i pos; /**< Device-pixel position relative to surface. */
- enum yasl_pointer_device device; /**< Mouse, touch, pen, or eraser. */
- int16_t button; /**< 0 primary, 1 middle, 2 secondary. */
- bool pressed; /**< true for press, false for release. */
- uint32_t mods;
- struct yasl_pointer_pen pen;
- } mouse_button;
-
- struct {
- struct yasl_vector2i pos; /**< Device-pixel position relative to surface. */
- struct yasl_vector2i delta; /**< Relative motion delta (dx, dy). */
- enum yasl_pointer_device device; /**< Mouse, touch, pen, or eraser. */
- uint32_t mods;
- struct yasl_pointer_pen pen;
- } mouse_motion;
-
- struct {
- struct yasl_vector2i pos;
- struct yasl_vector2d scroll; /**< Fractional line units; positive right/down. */
- uint32_t mods;
- } mouse_scroll;
-
- struct {
- struct yasl_vector2i size; /**< Configured content extent in device pixels. */
- uint32_t scale_120;
- } resize;
-
- struct {
- uint32_t scale_120;
- struct yasl_vector2i size;
- } scale;
-
- struct {
- bool focused;
- } focus;
-
- struct {
- const char *text; /**< UTF-8 text from clipboard. */
- size_t len;
- } paste;
-
- struct {
- const char *files; /**< NUL-terminated text/uri-list. */
- size_t len;
- } drop_files;
-
- struct {
- uint32_t type; /**< Application-defined message type. */
- void *payload; /**< User-defined payload pointer. */
- size_t size; /**< Optional payload size. */
- } user;
- };
-};
-
/** Frame context provided to yasl_app_desc.frame() during presentation. */
struct yasl_frame_context {
struct yasl_surface *surface;
@@ -199,24 +91,17 @@ YASL_API void yasl_surface_set_pacing(struct yasl_surface *s, yasl_pacing_mode m
YASL_API void yasl_surface_request_frame(struct yasl_surface *s);
/**
- * Configure mouse pointer capture / virtualization mode.
- * @param s Surface.
- * @param mode Normal, hidden, or relative pointer lock.
- */
-YASL_API void yasl_surface_set_mouse_mode(struct yasl_surface *s, yasl_mouse_mode mode);
-
-/**
* Safely post a custom user event to the main event loop from ANY thread.
* Wakes the display loop and delivers YASL_EVENT_USER to the event callback.
* @param d Display.
* @param s Optional target surface, or NULL.
- * @param user_type Application-defined message type.
+ * @param code Application-defined message code (yasl_user_event.code).
* @param payload Arbitrary pointer passed through to the event.
* @param size Optional payload size.
* @return true if queued successfully, false if queue is full or memory failed.
*/
YASL_API bool yasl_post_event(struct yasl_display *d, struct yasl_surface *s,
- uint32_t user_type, void *payload, size_t size);
+ uint32_t code, void *payload, size_t size);
/**
* Watch an open file descriptor or socket for poll-style readiness in the main loop.
@@ -269,15 +154,15 @@ struct yasl_app_desc {
* Use this to create windows and initialize application resources.
* Return YASL_APP_CONTINUE or YASL_APP_QUIT.
*/
- int (*init)(void *ud, struct yasl_display *d);
+ enum yasl_app_result (*init)(void *ud, struct yasl_display *d);
/**
- * Unified event handler called for input, resize, close, scale, and custom events.
+ * Unified event handler for input, window and user events, in arrival order.
* Event payloads and borrowed strings are valid for the duration of the callback.
* INPUT_RESET has no payload and requires clearing held application input.
* Return YASL_APP_CONTINUE or YASL_APP_QUIT.
*/
- int (*event)(void *ud, const struct yasl_event *ev);
+ enum yasl_app_result (*event)(void *ud, const struct yasl_event *ev);
/**
* Invoked when a surface needs to present a frame.