Expand description
Host-side event system for Oxide guest modules.
Guests register listeners with api_on_event(type, callback_id) and receive
events through the optional exported on_event(callback_id: u32) function.
While the callback runs, the guest may read the current event type and
payload via api_event_type_* and api_event_data_*.
Two sources push events onto the per-guest queue:
- Custom events emitted by the guest itself via
api_emit_event(type, data). - Built-in events produced by the host each tick:
resize— payload is(width: u32, height: u32)little-endian.focus/blur— empty payload; fires when the canvas gains/loses focus.visibility_change— payload is"visible"or"hidden"UTF-8.online/offline— empty payload; backed by a 30 s reachability check.touch_start/touch_move/touch_end— payload is(x: f32, y: f32)little-endian. Synthesised from primary mouse button + mouse position;touch_cancelis reserved for real touch input on platforms that surface it.gamepad_connected— payload is the device name (UTF-8).gamepad_button— payload is(gamepad_id: u32, button_code: u32, pressed: u32)little-endian (pressed= 1 for press, 0 for release).gamepad_axis— payload is(gamepad_id: u32, axis_code: u32, value: f32)little-endian (valuein [-1.0, 1.0]).drop_files— payload is a JSON array of dropped file paths (UTF-8).
Built-in producers run inside drain_pending_events, which the runtime
calls once per frame before invoking the guest on_event exports.
Structs§
- Event
State - Per-guest event system state: listener table, pending queue, current event, and built-in event detector state (last canvas size, focus, mouse, online).
- Pending
Event - One queued event: type name and arbitrary opaque payload bytes.
Functions§
- drain_
pending_ events - Drain built-in event sources + the pending custom-event queue and return
(callback_id, type, data)tuples to dispatch viaon_event. - enqueue_
drop_ files - Push a freshly-dropped file batch onto the queue as a
drop_filesevent. - register_
event_ functions - Register
api_on_event,api_off_event,api_emit_event, and the in-callback type/data read functions on the linker. - set_
current_ event - Populate
currentso the guest can read the event type/data inside itson_eventcallback. Called by the runtime immediately before eachon_event(callback_id)invocation.