AtlatestRepositorysigil-ui
1
#ifndef SIGIL_UI_WAYLAND_BRIDGE_H2
#define SIGIL_UI_WAYLAND_BRIDGE_H4
#include <sigil/sigil.h>5
#include <stddef.h>6
#include <stdint.h>7
#include <sys/types.h>9
/* Native embedders use the same connection and dispatcher as the Sigil UI.10
* Calls and callbacks run on the owning thread. No protocol pointer escapes.11
* An acquired surface stays allocated after close, but rejects presentation.12
* Release callbacks run exactly once, after compositor release or teardown;13
* frame callbacks report presented=0 when teardown cancels a pending frame.14
* A successful present owns the callback data until both notifications run;15
* a rejected present never calls either callback. */16
typedef struct Wl SuiWaylandSurface;17
/* Closing the parent from a completion callback marks it closed immediately;18
* teardown/disconnect finish when the outermost GUI dispatch or child19
* teardown unwinds. Callers20
* may drop their final handle references inside that callback. */21
typedef void (*SuiWaylandRelease)(void *data);22
typedef void (*SuiWaylandFrame)(void *data, uint32_t milliseconds, int presented);24
/* Optional v4 surface feedback. Enabling never dispatches or selects a GPU.25
* Snapshots own copied data and outlive updates, surface close and disconnect.26
* All calls, including snapshot ref/unref, belong to the owning thread.27
* Partial updates keep the last completed snapshot. An invalid completed28
* update revokes it; acquire then returns NULL until a valid update arrives.29
* Generation advances for every completed update or capability revocation;30
* a closed, cleaned-up handle reports unavailable with generation zero. */31
typedef struct SuiWaylandDmabufFeedback SuiWaylandDmabufFeedback;32
enum {33
SUI_DMABUF_UNAVAILABLE, SUI_DMABUF_PENDING, SUI_DMABUF_READY, SUI_DMABUF_INVALID34
};35
int sui_wayland_dmabuf_feedback_enable(SuiWaylandSurface *surface);36
int sui_wayland_dmabuf_feedback_status(SuiWaylandSurface *surface, uint64_t *generation);37
SuiWaylandDmabufFeedback *sui_wayland_dmabuf_feedback_acquire(SuiWaylandSurface *surface);38
SuiWaylandDmabufFeedback *sui_wayland_dmabuf_feedback_ref(SuiWaylandDmabufFeedback *feedback);39
void sui_wayland_dmabuf_feedback_unref(SuiWaylandDmabufFeedback *feedback);40
uint64_t sui_wayland_dmabuf_feedback_generation(const SuiWaylandDmabufFeedback *feedback);41
dev_t sui_wayland_dmabuf_feedback_main_device(const SuiWaylandDmabufFeedback *feedback);42
size_t sui_wayland_dmabuf_feedback_tranche_count(const SuiWaylandDmabufFeedback *feedback);43
int sui_wayland_dmabuf_feedback_tranche(const SuiWaylandDmabufFeedback *feedback,44
size_t tranche, dev_t *device, uint32_t *flags, size_t *formats);45
int sui_wayland_dmabuf_feedback_format(const SuiWaylandDmabufFeedback *feedback,46
size_t tranche, size_t index, uint32_t *fourcc, uint64_t *modifier);48
/* Asynchronous import only; this API never attaches a buffer. Input plane49
* descriptors are borrowed and remain the caller's property. Each handle50
* retains the connection, survives child-surface teardown, and must be51
* unref'd by its caller. Connection close cancels every surviving handle.52
* Pending imports may be canceled explicitly; no dispatch or wait occurs.53
* Cancellation retains a bounded private listener until created/failed or54
* connection close, so a late created buffer can be destroyed correctly.55
* Calls belong to the connection's owning thread. At most 64 handles may56
* coexist on one connection. Each plane's span must fit in 32 bits and57
* lie within its DMA-BUF's real size, as the kernel reports it; the first58
* plane's offset + stride * height must fit too. These are the compositor's own import59
* checks, so a refused plane never reaches it as a fatal protocol error.60
* Creation returns NULL with errno on refusal. */61
typedef struct SuiWaylandDmabufImport SuiWaylandDmabufImport;62
typedef struct { int fd; uint32_t offset, stride; } SuiWaylandDmabufPlane;63
typedef struct {64
int width, height;65
uint32_t fourcc, n_planes;66
uint64_t modifier;67
SuiWaylandDmabufPlane planes[4];68
} SuiWaylandDmabufSpec;69
enum {70
SUI_DMABUF_IMPORT_PENDING, SUI_DMABUF_IMPORT_READY,71
SUI_DMABUF_IMPORT_FAILED, SUI_DMABUF_IMPORT_CANCELED,72
SUI_DMABUF_IMPORT_FENCE_PENDING, SUI_DMABUF_IMPORT_FENCE_FAILED,73
SUI_DMABUF_IMPORT_FENCE_TIMED_OUT74
};75
SuiWaylandDmabufImport *sui_wayland_dmabuf_import(SuiWaylandSurface *surface,76
const SuiWaylandDmabufSpec *spec);77
SuiWaylandDmabufImport *sui_wayland_dmabuf_import_ref(SuiWaylandDmabufImport *buffer);78
void sui_wayland_dmabuf_import_unref(SuiWaylandDmabufImport *buffer);79
void sui_wayland_dmabuf_import_cancel(SuiWaylandDmabufImport *buffer);80
int sui_wayland_dmabuf_import_status(const SuiWaylandDmabufImport *buffer);81
/* Gate an idle READY import on producer readiness. fd is borrowed; a private82
* CLOEXEC duplicate is closed on ready/error/timeout/cancel/teardown. The GUI83
* dispatcher advances FENCE_PENDING without blocking input or protocol reads.84
* timeout_ms is 1..5000. POLLIN without error means ready; any terminal error85
* or deadline prevents presentation. An error/canceled wait does not establish86
* that producer rendering finished or permit reuse. Only a producer fence may87
* be supplied; this API neither validates a GPU allocation nor enables an88
* explicit-sync protocol. Returns 1 on acceptance, 0 with errno on refusal. */89
int sui_wayland_dmabuf_import_fence(SuiWaylandDmabufImport *buffer,90
int fd, unsigned timeout_ms);92
/* DMA-BUF release is distinct from frame pacing and SHM teardown. released=193
* means an actual compositor release; released=0 means connection teardown94
* has disconnected and the producer must be retired, never reused. Child95
* close cancels its frame callback but retains submitted imports until their96
* real release or connection teardown. Cancel/unref cannot destroy a busy97
* buffer. Success retains data until both notifications; refusal calls neither.98
* Only READY same-connection imports with exact device-pixel dimensions can99
* be submitted. No rendering-fence wait is provided by this call: the producer100
* must already satisfy the implicit synchronization contract. */101
typedef void (*SuiWaylandDmabufRelease)(void *data, int released);102
int sui_wayland_present_dmabuf(SuiWaylandSurface *surface,103
SuiWaylandDmabufImport *buffer, SuiWaylandDmabufRelease released,104
SuiWaylandFrame frame, void *data);106
SuiWaylandSurface *sui_wayland_acquire(SigilVM *vm, Value native_handle);107
void sui_wayland_unref(SuiWaylandSurface *surface);108
SuiWaylandSurface *sui_wayland_child(SuiWaylandSurface *parent, int x, int y,109
int width, int height, int overlay);110
void sui_wayland_close(SuiWaylandSurface *surface);111
int sui_wayland_size(SuiWaylandSurface *surface, int *width, int *height, int *scale);112
/* Start an xdg-foreign v2 export on a live xdg-toplevel. Only ordinary113
* UI dispatch receives the handle. Returns NULL while pending or unavailable.114
* A returned string is borrowed until the next dispatch or surface close. */115
const char *sui_wayland_export_handle(SuiWaylandSurface *surface);116
/* Cursor requests affect the shared connection, including requests from a117
* child. They copy desired state, never dispatch, and apply only with a live118
* pointer-enter serial. Calls must use the connection's owning thread.119
* A name alone prefers its mapped compositor shape, then the default loader.120
* An explicit theme or positive size prefers the configured loader, then a121
* mapped shape. NULL theme with size 0 clears that explicit preference.122
* For an explicit size without a theme, NULL selects XCURSOR_THEME/default;123
* size 0 selects valid XCURSOR_SIZE/24. Size is 1..128 logical pixels.124
* The loader uses frame one; builtin and theme origins are indistinguishable.125
* Images are premultiplied native ARGB8888, at most 512x512/1 MiB, copied now;126
* image scale is 1..8 and divides both dimensions; hotspots are device pixels127
* strictly inside the image.128
* False reports invalid/closed/wrong-thread or currently unavailable output.129
* True outside pointer focus means accepted for the next pointer entry. */130
int sui_wayland_cursor_configure(SuiWaylandSurface *surface, const char *theme, int size);131
int sui_wayland_cursor_name(SuiWaylandSurface *surface, const char *name);132
int sui_wayland_cursor_image(SuiWaylandSurface *surface, const uint8_t *bytes,133
size_t length, int width, int height, size_t stride, int hotspot_x, int hotspot_y, int scale);134
enum { SUI_CURSOR_UNAVAILABLE, SUI_CURSOR_THEME, SUI_CURSOR_SHAPE, SUI_CURSOR_IMAGE, SUI_CURSOR_HIDDEN };135
int sui_wayland_cursor_backend(SuiWaylandSurface *surface);136
/* Requests never dispatch or claim compositor acceptance. State is 0/1 only137
* after xdg_surface.configure; -1 means no live xdg-toplevel. */138
int sui_wayland_set_fullscreen(SuiWaylandSurface *surface, int fullscreen);139
int sui_wayland_fullscreen_state(SuiWaylandSurface *surface);140
/* Child geometry is in logical pixels; changing it retires old buffers on141
* the next present. Modifier masks are the compositor's XKB masks/group. */142
int sui_wayland_geometry(SuiWaylandSurface *surface, int x, int y, int width, int height);143
void sui_wayland_modifiers(SuiWaylandSurface *surface, uint32_t masks[4]);144
const char *sui_wayland_keymap(SuiWaylandSurface *surface, size_t *size);145
/* Monotonic selection generation and whether readable text is offered. */146
uint64_t sui_wayland_clipboard_generation(SuiWaylandSurface *surface, int *has_text);147
/* Text only; at most 4 MiB. Setting requires a compositor input serial.148
* Read returns malloc-owned bytes, or NULL on missing selection/error/timeout. */149
int sui_wayland_clipboard_set(SuiWaylandSurface *surface, const uint8_t *bytes, size_t size);150
uint8_t *sui_wayland_clipboard_read(SuiWaylandSurface *surface, size_t *size);151
int sui_wayland_present_shm(SuiWaylandSurface *surface, const uint8_t *pixels,152
int width, int height, size_t stride,153
SuiWaylandRelease released, SuiWaylandFrame frame,154
void *data);156
#endif