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

ui/x11

lib/ui/x11.vk

lib/ui/x11.vk Pure-Veko X11 core wire-protocol codec (X11R6 little-endian over AF_UNIX /tmp/.X11-unix/X<n>). Zero capabilities required; encodes connection setup, .Xauthority MIT-MAGIC-COOKIE-1 parsing, pipelined CreateWindow/CreateGC/ChangeProperty/MapWindow requests, scanline-band chunked PutImage frames (<= 128 KB per packet so 4K/Retina surfaces never hit X11's 262 KB BadLength cap), and 32-byte X11 input/structure event packets.

X11Setup struct
signature
X11Setup = struct { id_base i64, id_mask i64, root_window i64, white_pixel i64, root_visual i64, root_depth i64 }

Parsed X11 server setup parameters for the default root screen.

X11Band struct
signature
X11Band = struct { y i64, height i64, req_words i64, byte_count i64 }

One scanline band descriptor (y offset + height rows) for chunked PutImage transmission.

X11Event struct
signature
X11Event = struct { kind i64, x i64, y i64, key i64, btn i64 }

Decoded 32-byte X11 wire event mapped to canonical Veko ui event fields (kind, x, y, key, btn).

signature
display-socket-path = fn [display str] str

Resolves the canonical AF_UNIX socket path (e.g. '/tmp/.X11-unix/X0') from a DISPLAY string (':0', 'unix:1.0').

Executable Example
veko
use [x11 = ui/x11]
p0 = x11/display-socket-path ':0'
p2 = x11/display-socket-path 'unix:2.0'
if p0 != '/tmp/.X11-unix/X0' or p2 != '/tmp/.X11-unix/X2' [ err 'bad x11 path' ] else [ .ok ]
signature
encode-setup = fn [cookie bytes] bytes

Encodes the little-endian X11 connection setup packet (12 bytes unauthenticated, or 48 bytes with a 16-byte MIT-MAGIC-COOKIE-1).

signature
parse-setup-reply = fn [pkt bytes] X11Setup

Parses a complete X11 Setup reply buffer (8-byte header + body) into X11Setup.

signature
encode-window-init = fn [setup X11Setup, wid i64, gcid i64, title str, w i64, h i64] bytes

Encodes pipelined CreateWindow + CreateGC + ChangeProperty(WM_NAME) + MapWindow core requests.

signature
plan-put-image-bands = fn [w i64, h i64] block[X11Band]

Plans scanline bands (<= 128 KB pixel payload per packet) so PutImage never exceeds X11's 16-bit 4-byte-word request cap (262,140 bytes).

Executable Example
veko
use [x11 = ui/x11]
bands = x11/plan-put-image-bands 960 600
if (len bands) != 18 or bands[0].height != 34 or bands[0].req_words >= 65535 [ err 'bad bands' ] else [ .ok ]
signature
encode-put-image-band = fn [wid i64, gcid i64, depth i64, rgba bytes, w i64, band X11Band] bytes

Encodes one 24-byte PutImage (ZPixmap) band packet + BGRA-swizzled scanlines from rgba.

signature
decode-event-32 = fn [ev bytes] X11Event

Decodes a 32-byte X11 wire event packet into a canonical X11Event (kind = 0 when ignored).