diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 00:29:34 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 00:29:34 +0300 |
| commit | f7fa0930cb46046f995fa1ab927aef62466e995e (patch) | |
| tree | f5ac4e1579811b5d69498a19d0bdfbf128a1d62b /include | |
| parent | 624d1371304a5ae4b3429ad5e4267aac7cd03dfd (diff) | |
feat: add SDL3-style surface, display, and loop timer API for X11, Wayland, and Cocoa
Diffstat (limited to 'include')
| -rw-r--r-- | include/yasl/yasl.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/yasl/yasl.h b/include/yasl/yasl.h index 2852112..cde7f34 100644 --- a/include/yasl/yasl.h +++ b/include/yasl/yasl.h @@ -420,6 +420,46 @@ YASL_API int yasl_loop_add_fd(struct yasl_loop *l, int fd, short events, int (*fn)(int fd, short revents, void *ud), void *ud); YASL_API int yasl_loop_del_fd(struct yasl_loop *l, int id); YASL_API int yasl_loop_set_fd_events(struct yasl_loop *l, int id, short events); +YASL_API int yasl_loop_next_timeout_ms(const struct yasl_loop *l); + +/* Timers (SDL3-compatible callback model) + * Timer callbacks return the next interval in nanoseconds (or milliseconds for _ms), + * or 0 to disarm and remove the timer. Returning the same interval repeats the timer; + * returning a different non-zero interval reschedules it with the new interval. + * + * All timers fire on the display's opening thread during event dispatch/step. + * Surface timers are bound to a specific surface and are automatically canceled + * if that surface is destroyed. */ +typedef uint32_t yasl_timer_id; + +typedef uint64_t (*yasl_timer_cb)(void *ud, yasl_timer_id id, uint64_t interval_ns); +typedef uint32_t (*yasl_timer_ms_cb)(void *ud, yasl_timer_id id, uint32_t interval_ms); + +#define YASL_MS_TO_NS(ms) ((uint64_t)(ms) * 1000000ull) +#define YASL_NS_TO_MS(ns) ((uint64_t)(ns) / 1000000ull) + +/* Surface-bound Timers */ +YASL_API yasl_timer_id yasl_surface_add_timer(struct yasl_surface *s, uint64_t interval_ns, + yasl_timer_cb cb, void *ud); +YASL_API yasl_timer_id yasl_surface_add_timer_ms(struct yasl_surface *s, uint32_t interval_ms, + yasl_timer_ms_cb cb, void *ud); +YASL_API bool yasl_surface_del_timer(struct yasl_surface *s, yasl_timer_id id); + +/* Display-bound Timers */ +YASL_API yasl_timer_id yasl_display_add_timer(struct yasl_display *d, uint64_t interval_ns, + yasl_timer_cb cb, void *ud); +YASL_API yasl_timer_id yasl_display_add_timer_ms(struct yasl_display *d, uint32_t interval_ms, + yasl_timer_ms_cb cb, void *ud); +YASL_API bool yasl_display_del_timer(struct yasl_display *d, yasl_timer_id id); +YASL_API struct yasl_loop *yasl_display_loop(struct yasl_display *d); +YASL_API struct yasl_loop *yasl_surface_loop(struct yasl_surface *s); + +/* Loop Timers */ +YASL_API yasl_timer_id yasl_loop_add_timer(struct yasl_loop *l, uint64_t interval_ns, + yasl_timer_cb cb, void *ud); +YASL_API yasl_timer_id yasl_loop_add_timer_ms(struct yasl_loop *l, uint32_t interval_ms, + yasl_timer_ms_cb cb, void *ud); +YASL_API bool yasl_loop_del_timer(struct yasl_loop *l, yasl_timer_id id); #ifdef __cplusplus } |
