generation
This commit is contained in:
parent
4c7c96a8a9
commit
c4dc26d3f3
104
include/uhdk.h
104
include/uhdk.h
|
|
@ -67,6 +67,9 @@
|
||||||
* not allocate/free memory themselves, intercept malloc, or transfer ownership.
|
* not allocate/free memory themselves, intercept malloc, or transfer ownership.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Typed event payload convenience; see uhdk_event. */
|
||||||
|
#define UHDK_EVENT_PAYLOAD(event_ptr, expected_type, payload_type) (((event_ptr)->type == (expected_type) && (event_ptr)->data_size >= sizeof(payload_type)) ? (const payload_type *)(event_ptr)->data : (const payload_type *)0)
|
||||||
|
|
||||||
#define UHDK_ABI_VERSION 1u
|
#define UHDK_ABI_VERSION 1u
|
||||||
|
|
||||||
#ifdef UHDK_PROFILE_BACKEND
|
#ifdef UHDK_PROFILE_BACKEND
|
||||||
|
|
@ -134,8 +137,13 @@ typedef struct uhdk_window uhdk_window;
|
||||||
typedef struct uhdk_file uhdk_file;
|
typedef struct uhdk_file uhdk_file;
|
||||||
typedef struct uhdk_watch uhdk_watch;
|
typedef struct uhdk_watch uhdk_watch;
|
||||||
typedef struct uhdk_menu uhdk_menu;
|
typedef struct uhdk_menu uhdk_menu;
|
||||||
typedef uint64_t
|
/* Caller-chosen, nonzero. Unique in the session until REQUEST_DONE is delivered.
|
||||||
uhdk_request_tag; /* Caller-chosen, nonzero; unique until completion is delivered. */
|
* Duplicates return BUSY, including while a completion is queued. A failed submit
|
||||||
|
* reserves nothing. Cancel is best effort and does not free the tag. Reuse only
|
||||||
|
* after handling the completion, or after consuming or ignoring it if the owner
|
||||||
|
* is gone. See [Asynchronous services](#asynchronous-services).
|
||||||
|
*/
|
||||||
|
typedef uint64_t uhdk_request_tag;
|
||||||
|
|
||||||
typedef struct uhdk_text {
|
typedef struct uhdk_text {
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
|
|
@ -210,26 +218,6 @@ enum {
|
||||||
UHDK_CAP_OPENGL = 18
|
UHDK_CAP_OPENGL = 18
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Every accepted async request uses a caller-chosen nonzero tag and produces one terminal
|
|
||||||
* REQUEST_DONE during normal draining. Failure to accept produces no event.
|
|
||||||
* Tags are unique per session until REQUEST_DONE is delivered by next_frame.
|
|
||||||
* Duplicate tags return BUSY, including while completion is queued. Zero is invalid.
|
|
||||||
* Tags may be reused while handling their completion. Failure to accept reserves
|
|
||||||
* no tag and produces no completion. Private native IDs are never reused.
|
|
||||||
* Cancellation is best effort; an operation already committed may succeed.
|
|
||||||
* Closing a session early abandons undelivered results and drains internal work.
|
|
||||||
*
|
|
||||||
* Component lifetime pattern: the application assigns dedicated tags to reusable
|
|
||||||
* components (for example, a clipboard tag passed to a UI backend at init).
|
|
||||||
* All components share the session's tag namespace; use separate tags for requests
|
|
||||||
* that may overlap. Keep each tag assigned to its component while it is alive.
|
|
||||||
* If a component is destroyed with a request pending, its owner must consume or
|
|
||||||
* ignore the eventual REQUEST_DONE before assigning that tag to a replacement.
|
|
||||||
* Cancelling the request does not release the tag or remove its completion.
|
|
||||||
* This prevents a replacement component from consuming its predecessor's result.
|
|
||||||
* Result payloads are borrowed until the next valid next_frame call or close;
|
|
||||||
* copy data or retain retainable references before keeping them beyond that point.
|
|
||||||
*/
|
|
||||||
typedef struct uhdk_event uhdk_event;
|
typedef struct uhdk_event uhdk_event;
|
||||||
typedef struct uhdk_event_list {
|
typedef struct uhdk_event_list {
|
||||||
const uhdk_event *ptr;
|
const uhdk_event *ptr;
|
||||||
|
|
@ -943,6 +931,11 @@ typedef struct uhdk_key_event {
|
||||||
uhdk_bool repeat;
|
uhdk_bool repeat;
|
||||||
} uhdk_key_event;
|
} uhdk_key_event;
|
||||||
|
|
||||||
|
/* Pointer position and delta use logical window units. POINTER_MOVE events may
|
||||||
|
* continue outside the window while pointer capture is active. pressed and
|
||||||
|
* button are meaningful for POINTER_BUTTON; movement and enter/leave events
|
||||||
|
* retain the current position and modifiers. The event envelope's cycle_id
|
||||||
|
* associates a long-lived drag/capture interaction with its CYCLE_END marker. */
|
||||||
typedef struct uhdk_pointer_event {
|
typedef struct uhdk_pointer_event {
|
||||||
uhdk_point position;
|
uhdk_point position;
|
||||||
uhdk_point delta; /* delta uses logical units. */
|
uhdk_point delta; /* delta uses logical units. */
|
||||||
|
|
@ -952,6 +945,9 @@ typedef struct uhdk_pointer_event {
|
||||||
uint32_t click_count;
|
uint32_t click_count;
|
||||||
} uhdk_pointer_event;
|
} uhdk_pointer_event;
|
||||||
|
|
||||||
|
/* Scroll deltas use the declared unit and phase. A phase-aware gesture shares
|
||||||
|
* cycle_id across BEGIN, UPDATE and END/CANCEL events; discrete wheel ticks use
|
||||||
|
* cycle_id=0. Positive delta means right/down in logical coordinates. */
|
||||||
typedef struct uhdk_scroll_event {
|
typedef struct uhdk_scroll_event {
|
||||||
uhdk_point position;
|
uhdk_point position;
|
||||||
uhdk_point delta; /* Positive scroll = toward right/bottom. */
|
uhdk_point delta; /* Positive scroll = toward right/bottom. */
|
||||||
|
|
@ -1029,36 +1025,48 @@ enum {
|
||||||
UHDK_CYCLE_SHUTDOWN /* Session is draining normally. */
|
UHDK_CYCLE_SHUTDOWN /* Session is draining normally. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* The terminal reason for the interaction identified by event.cycle_id. The
|
||||||
|
* marker retires application state; it does not decide whether application data
|
||||||
|
* should be committed or rolled back. */
|
||||||
typedef struct uhdk_cycle_end_event {
|
typedef struct uhdk_cycle_end_event {
|
||||||
uhdk_cycle_end_reason reason;
|
uhdk_cycle_end_reason reason;
|
||||||
} uhdk_cycle_end_event;
|
} uhdk_cycle_end_event;
|
||||||
|
|
||||||
/* cycle_id groups a pointer drag/capture, phased scroll gesture, or visible IME
|
/* One event from a next_frame batch.
|
||||||
* preedit composition. Independent kinds/windows never share IDs; IDs are not
|
*
|
||||||
* request tags or input_id values and are never reused within a session.
|
* Cast `data` by `type`; see [Event payloads](#event-payloads). Events omitted
|
||||||
* A pointer cycle starts on first button-down or capture activation. It ends
|
* there have NULL `data` and zero `data_size`. Payloads are borrowed until the
|
||||||
* after the last release without capture, or capture is released/lost. Hover,
|
* next next_frame or close.
|
||||||
* discrete wheel ticks and ordinary typing have cycle_id=0.
|
*
|
||||||
* Each ended cycle produces CYCLE_END with its ID, window and cycle_end_event. This
|
* `window` is NULL for app-wide events. `time_ns` is monotonic time since
|
||||||
* covers normal completion, cancellation, focus loss, hiding and normal shutdown.
|
* session creation, not wall time.
|
||||||
* Markers follow native ending events; session deactivation and shutdown emit
|
*
|
||||||
* them before APP_ACTIVATION(false) and STOPPED. The reason reports the first
|
* `cycle_id` groups a pointer drag/capture, phased scroll, or visible IME
|
||||||
* observed terminating cause; later native cleanup does not replace it. They signal retirement, not
|
* preedit. Zero means no cycle. It is not a request tag or `input_id`, and it
|
||||||
* whether an application operation should be committed or rolled back.
|
* is never reused in a session. See [Input lifetimes](#input-lifetimes).
|
||||||
* Destroying a window or closing a session invalidates its cycles immediately;
|
*
|
||||||
* queued events may be discarded. Fatal errors can interrupt delivery.
|
* Async completions arrive as REQUEST_DONE; see
|
||||||
*/
|
* [`uhdk_request_tag`](api:uhdk_request_tag).
|
||||||
|
*
|
||||||
/* Event data mapping:
|
* In C and C++, UHDK_EVENT_PAYLOAD returns a typed pointer only when both type
|
||||||
* APP_ACTIVATION: uhdk_activation_event; OPEN_FILES: uhdk_file_list;
|
* and data_size match. Pass a stable event pointer expression because the macro
|
||||||
* WINDOW_METRICS: uhdk_window_metrics; PREFERENCES_CHANGED: uhdk_preferences;
|
* may evaluate it more than once:
|
||||||
* KEY: uhdk_key_event; POINTER_ENTER/LEAVE/MOVE/BUTTON: uhdk_pointer_event;
|
*
|
||||||
* POINTER_MODE_CHANGED: uhdk_pointer_mode_event; SCROLL: uhdk_scroll_event;
|
* ```c
|
||||||
* TEXT_COMMIT/PREEDIT: uhdk_text_event; EDIT_COMMAND: uhdk_edit_event;
|
* const uhdk_key_event *key =
|
||||||
* DROP_FILES: uhdk_drop_files_event; MENU_COMMAND: uhdk_menu_event;
|
* UHDK_EVENT_PAYLOAD(event, UHDK_EVENT_KEY, uhdk_key_event);
|
||||||
* WATCH: uhdk_watch_event;
|
* if (key != NULL) { ... }
|
||||||
* REQUEST_DONE: uhdk_request_result; CYCLE_END: uhdk_cycle_end_event.
|
* ```
|
||||||
* All other events have NULL/0 data.
|
*
|
||||||
|
* Environments that do not expose C macros perform the equivalent operation by
|
||||||
|
* checking type, checking data_size, and only then casting data:
|
||||||
|
*
|
||||||
|
* ```c
|
||||||
|
* if (event->type == UHDK_EVENT_KEY &&
|
||||||
|
* event->data_size >= sizeof(uhdk_key_event)) {
|
||||||
|
* const uhdk_key_event *key = (const uhdk_key_event *)event->data;
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
struct uhdk_event {
|
struct uhdk_event {
|
||||||
uint32_t struct_size;
|
uint32_t struct_size;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue