RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
In-tree wlroots bindings
@import("wlroots") resolves to wlr.zig, backed by the installed wlroots
0.20 headers. There is no zig-wlroots package dependency. Some API shapes
were adapted from that project; keep LICENSE.zig-wlroots and attribution.
@import("pixman") resolves to pixman.zig, a hand-written facade over the
small part of pixman's region API this compositor actually calls (Region32
init/initRect/deinit/unionRect/notEmpty/containsPoint). There is no zig-pixman package dependency either; the struct layout is adapted from that project (keepLICENSE.zig-pixman) and must keep matching the realpixman_region32_t, sinceRegion32is embedded by value innode.zig'sBufferand crosses into wlroots calls viaabi.bind. Extend it rather than reintroducing the package if more of the API is needed.
@import("xkbcommon") resolves to xkbcommon.zig, a hand-written facade
over the part of xkbcommon this compositor calls: building a keymap from
RMLVO names, tracking modifier/layout state, and keysym lookups. There is no
zig-xkbcommon package dependency either (keep LICENSE.zig-xkbcommon).
Unlike Region32, Context/Keymap/State are opaque handles — pointers
only, never embedded by value — so they need no layout check to cross the
wlroots boundary. Keysym is a plain non-exhaustive u32 enum: add a named
constant (value from xkbcommon-keysyms.h) rather than growing a full keysym
table. Extend this file rather than reintroducing the package if more of the
API is needed.
Boundary and layouts
c.hlists every wlroots header; the build translates it once intowlr_c, whichc.zigre-exports. Add headers there; separate translations create incompatible C type identities._FORTIFY_SOURCEis undefined for translate-c compatibility in ReleaseSafe. The two uninstalled protocol C headers are generated bywayland-scannerinbuild.zig.- Prefer raw C types where callers need no Zig methods or typed events.
Otherwise declare a small
extern struct, retyping Wayland fields aswl.Signal(T),wl.Listener(T),wl.Resourceorwl.list.Head(T, field). Every represented field must be checked against its real header type. abi.assertFieldschecks offsets, sizes, nested structs and event blocks. It permits an omitted tail only for objects allocated by wlroots and used through pointers. Useabi.assertLayoutfor objects embedded, allocated, or passed by value by Zig. Retain any required private storage using the C field's actual type (@FieldType(c.wlr_foo, "WLR_PRIVATE")), never a guessed padding count. Arrays also need their complete element stride.- For anonymous C unions use an explicit field mapping and check each
alternative.
signal.zigalso supplies the simpler checks used by the earlier adapters. C function/type name collisions needc.struct_wlr_foo. - Signal payloads are a semantic contract; check their emitters and listeners. Equal signal layouts cannot verify the payload type. Preserve nullability from the header/lifecycle, especially optional output and buffer pointers.
abi.bind(fn (...) callconv(.c) Return, c.wlr_foo)verifies the header signature and returns a real wrapper function, preserving method-call syntax. Raw function pointers do not work as Zig methods. Pointer retyping is allowed at this boundary; the owning type's layout checks validate its pointee. Callback signatures and by-value arguments are checked too.- Enum/flag values must come from C constants or be explicitly checked.
Use lazy
@import("wlr.zig").Typereferences for mutually recursive types. Callers use the facade's types directly; do not reintroduce casts between two competing wlroots bindings or hand-declare wlroots extern functions.
Validation
zig build test-wlroots references every exported binding and exercises C
initialization/teardown of embedded Pointer/Keyboard objects with surrounding
canaries. It is included in zig build test. Keep new test cases in sibling
*_tests.zig files and import them from wlr.zig.
Build Debug and ReleaseSafe, then run the affected integration suites as
specified in the root TESTING.md. Use isolated headless sessions and compare
failures against a clean baseline. Protocol layout checks cannot replace
runtime input, capture, lock, output and surface lifecycle coverage.