diff options
Diffstat (limited to 'include/yasl/yasl.h')
| -rw-r--r-- | include/yasl/yasl.h | 110 |
1 files changed, 30 insertions, 80 deletions
diff --git a/include/yasl/yasl.h b/include/yasl/yasl.h index cde7f34..30bf591 100644 --- a/include/yasl/yasl.h +++ b/include/yasl/yasl.h @@ -136,11 +136,6 @@ struct yasl_framebuffer { uint64_t generation; /* Opaque draw identity; preserve when copying target. */ uint32_t *pixels; struct yasl_vector2i size; - int buffer; - bool cleared; - struct yasl_damage_list *damage; - void *native_drawable; - bool transaction; }; struct yasl_frame { @@ -250,6 +245,25 @@ enum yasl_input_kind { YASL_INPUT_RESET, }; +struct yasl_focus_event { + bool focused; +}; + +struct yasl_text_event { + const char *text; + size_t len; +}; + +struct yasl_paste_event { + const char *text; + size_t len; +}; + +struct yasl_drop_files_event { + const char *files; + size_t len; +}; + struct yasl_input_event { struct yasl_surface *surface; enum yasl_input_kind kind; @@ -257,10 +271,10 @@ struct yasl_input_event { union { struct yasl_key_event key; struct yasl_mouse_event mouse; - struct { bool focused; } focus; - struct { const char *text; size_t len; } text; - struct { const char *text; size_t len; } paste; - struct { const char *files; size_t len; } drop_files; + struct yasl_focus_event focus; + struct yasl_text_event text; + struct yasl_paste_event paste; + struct yasl_drop_files_event drop_files; }; }; @@ -270,7 +284,6 @@ struct yasl_input_event { * popups before parents, and displays before their supplied loop. * Specs, strings, callback tables and drag listeners are copied during calls. * Userdata is borrowed until callbacks are removed or the object/drag ends. - * Native handles are borrowed and expire when their owning object is destroyed. * Surface destruction is allowed from its callbacks; display/loop destruction * during dispatch or callbacks is not supported. */ @@ -315,8 +328,9 @@ YASL_API struct yasl_display *yasl_display_open(struct yasl_loop *loop, YASL_API enum yasl_backend yasl_display_backend(const struct yasl_display *d); YASL_API void yasl_display_close(struct yasl_display *d); YASL_API uint32_t yasl_display_caps(const struct yasl_display *d); -YASL_API void yasl_display_dispatch(struct yasl_display *d); -YASL_API int yasl_display_dispatch_timeout(struct yasl_display *d, int timeout_ms); +/* Process events, waiting at most timeout_ms: zero polls, negative waits. + * Pending input or redraw work returns immediately. Returns -1 on failure. */ +YASL_API int yasl_display_dispatch(struct yasl_display *d, int timeout_ms); YASL_API void yasl_display_flush(struct yasl_display *d); YASL_API int yasl_display_modifiers(const struct yasl_display *d); /* Unsupported/invalid selections are no-ops, never clipboard aliases. */ @@ -336,10 +350,6 @@ struct yasl_surface_spec { struct yasl_vector2i size; bool fullscreen; bool tearing; - /* Optional native graphics device (retained on Cocoa). Requires - * YASL_CAP_NATIVE_GRAPHICS; other backends reject it with ENOTSUP. - * NULL selects CPU pixel presentation. */ - void *graphics_device; }; struct yasl_popup_spec { @@ -364,12 +374,10 @@ YASL_API void yasl_surface_set_callbacks(struct yasl_surface *s, YASL_API void yasl_surface_set_title(struct yasl_surface *s, const char *title); YASL_API void yasl_surface_schedule_redraw(struct yasl_surface *s); /* Present exactly the target supplied to the current draw callback, at most - * once. Targets and native drawables expire when that callback returns or - * the surface is destroyed. + * once. Targets expire when that callback returns or the surface is destroyed. * damage is required: n must be -1 or 0..YASL_DAMAGE_MAX. Rectangles must have * nonnegative extents; they are clipped to the target. Invalid input returns - * false without consuming the frame. Native renderers submit/present their - * drawable themselves, then call this function to record the submission. */ + * false without consuming the frame. See yasl/native.h for native rendering. */ YASL_API bool yasl_surface_present(struct yasl_surface *s, const struct yasl_framebuffer *fb, const struct yasl_damage_list *damage); /* Event payload strings are library-owned, NUL-terminated, and valid until @@ -377,8 +385,8 @@ YASL_API bool yasl_surface_present(struct yasl_surface *s, const struct yasl_fra * flush and unsuccessful polls do not invalidate them. Copy to keep longer. */ YASL_API bool yasl_surface_input_poll(struct yasl_surface *s, struct yasl_input_event *ev); -YASL_API struct yasl_vector2i yasl_surface_size(const struct yasl_surface *s); -YASL_API uint32_t yasl_surface_scale_120(const struct yasl_surface *s); +/* Current device-pixel size and scale, matching the configure callback. */ +YASL_API struct yasl_geometry yasl_surface_geometry(const struct yasl_surface *s); YASL_API uint32_t yasl_surface_state(const struct yasl_surface *s); /* Timing uses monotonic nanoseconds. Check source before treating timestamps * as presentation confirmation. refresh/next_present are estimates. Without @@ -403,64 +411,6 @@ YASL_API bool yasl_surface_show_window_menu(struct yasl_surface *s, struct yasl_ YASL_API bool yasl_surface_drag_carry(struct yasl_surface *s, struct yasl_vector2i offset); YASL_API bool yasl_surface_place_under_pointer(struct yasl_surface *s, struct yasl_vector2i at); -/* Native Interoperability Handles */ -YASL_API void *yasl_display_get_native_handle(struct yasl_display *d); -YASL_API void *yasl_surface_get_native_handle(struct yasl_surface *s); - -/* Integrated Event Loop */ -YASL_API struct yasl_loop *yasl_loop_create(void); -YASL_API void yasl_loop_destroy(struct yasl_loop *l); -YASL_API int yasl_loop_run(struct yasl_loop *l); -YASL_API int yasl_loop_step(struct yasl_loop *l, int timeout_ms); -YASL_API void yasl_loop_quit(struct yasl_loop *l); -YASL_API bool yasl_loop_is_running(const struct yasl_loop *l); -YASL_API void yasl_loop_kick(struct yasl_loop *l); -YASL_API uint64_t yasl_loop_now_ns(void); -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 } #endif |
