veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

ui/wayland

lib/ui/wayland.vk

lib/ui/wayland.vk Pure-Veko Wayland wire-protocol codec (wl_display, wl_registry, wl_compositor, wl_shm, wl_shm_pool, wl_surface, xdg_wm_base, xdg_surface, xdg_toplevel). Zero host capabilities required: encodes 32-bit aligned Wayland requests and parses server events for Veko's zero-libc Linux AF_UNIX + memfd_create + SCM_RIGHTS backend.

signature
wl-display-id = fn [] i64
signature
shm-format-argb8888 = fn [] i64
signature
shm-format-xrgb8888 = fn [] i64
WlMsgHdr struct
signature
WlMsgHdr = struct { object_id i64, opcode i64, size i64 }

Decoded 8-byte Wayland wire message header.

WlGlobal struct
signature
WlGlobal = struct { name i64, interface str, version i64 }

Decoded wl_registry.global advertisement event (opcode 0).

signature
socket-path = fn [xdg_runtime_dir str, wayland_display str] str

Resolves the canonical AF_UNIX Wayland socket path from XDG_RUNTIME_DIR and WAYLAND_DISPLAY.

Executable Example
veko
use [wl = ui/wayland]
p1 = wl/socket-path '/run/user/1000' ''
p2 = wl/socket-path '/run/user/1000' 'wayland-1'
p3 = wl/socket-path '/run/user/1000' '/tmp/custom-wl-0'
if p1 != '/run/user/1000/wayland-0' or p2 != '/run/user/1000/wayland-1' or p3 != '/tmp/custom-wl-0' [
    err 'bad wayland socket path'
] else [ .ok ]
signature
encode-hdr = fn [object_id i64, opcode i64, size i64] bytes

Encodes an 8-byte Wayland wire header (object_id, (size << 16) | opcode).

signature
decode-hdr = fn [pkt bytes, off i64] WlMsgHdr

Decodes an 8-byte Wayland wire header at off inside pkt.

signature
push-str-arg = fn [mut buf bytes, s str] i64

Appends a Wayland NUL-terminated 32-bit padded string argument to buf and returns bytes written.

signature
encode-sync = fn [callback_id i64] bytes

Encodes wl_display@1.sync(callback_id) (opcode 0, 12 bytes).

signature
encode-get-registry = fn [registry_id i64] bytes

Encodes wl_display@1.get_registry(registry_id) (opcode 1, 12 bytes).

signature
encode-registry-bind = fn [registry_id i64, global_name i64, iface str, version i64, new_id i64] bytes

Encodes wl_registry.bind(name, interface, version, new_id) (opcode 0, untyped new_id wire layout).

Executable Example
veko
use [wl = ui/wayland]
pkt = wl/encode-registry-bind 2 7 'wl_compositor' 4 4
hdr = wl/decode-hdr pkt 0
if hdr.object_id != 2 or hdr.opcode != 0 or hdr.size != (len pkt) or ((len pkt) % 4) != 0 [
    err 'bad wl_registry.bind packet'
] else [ .ok ]
signature
parse-registry-global = fn [pkt bytes, body_off i64] WlGlobal

Parses a wl_registry.global event body starting at off (after the 8-byte header).

Executable Example
veko
use [wl = ui/wayland]
mut ev = bytes/with-cap 32
_ = bytes/push-all mut ev (wl/encode-hdr 2 0 28)
_ = bytes/push-u32-le mut ev 11
_ = wl/push-str-arg mut ev 'wl_shm'
_ = bytes/push-u32-le mut ev 1
g = wl/parse-registry-global ev 8
if g.name != 11 or g.interface != 'wl_shm' or g.version != 1 [ err 'bad global parse' ] else [ .ok ]
signature
encode-create-surface = fn [compositor_id i64, surface_id i64] bytes

Encodes wl_compositor.create_surface(surface_id) (opcode 0, 12 bytes).

signature
encode-shm-create-pool = fn [shm_id i64, pool_id i64, byte_size i64] bytes

Encodes wl_shm.create_pool(pool_id, byte_size) (opcode 0, 16 bytes; fd passed via SCM_RIGHTS).

signature
encode-pool-create-buffer = fn [pool_id i64, buf_id i64, offset i64, w i64, h i64, stride i64, fmt i64] bytes

Encodes wl_shm_pool.create_buffer(buf_id, offset, w, h, stride, format) (opcode 0, 32 bytes).

signature
encode-get-xdg-surface = fn [wm_base_id i64, xdg_surf_id i64, wl_surf_id i64] bytes

Encodes xdg_wm_base.get_xdg_surface(xdg_surf_id, wl_surf_id) (opcode 2, 16 bytes).

signature
encode-xdg-pong = fn [wm_base_id i64, serial i64] bytes

Encodes xdg_wm_base.pong(serial) (opcode 3, 12 bytes).

signature
encode-get-toplevel = fn [xdg_surf_id i64, toplevel_id i64] bytes

Encodes xdg_surface.get_toplevel(toplevel_id) (opcode 1, 12 bytes).

signature
encode-ack-configure = fn [xdg_surf_id i64, serial i64] bytes

Encodes xdg_surface.ack_configure(serial) (opcode 4, 12 bytes).

signature
encode-set-title = fn [toplevel_id i64, title str] bytes

Encodes xdg_toplevel.set_title(title) (opcode 2).

signature
encode-surface-present = fn [surface_id i64, buf_id i64, w i64, h i64] bytes

Encodes pipelined wl_surface.attach(buf_id, 0, 0) + wl_surface.damage(0, 0, w, h) + wl_surface.commit() (52 bytes).

Executable Example
veko
use [wl = ui/wayland]
pkt = wl/encode-surface-present 9 8 800 600
if (len pkt) != 52 [ err 'expected 52-byte pipelined Wayland present packet' ] else [ .ok ]