# AGENTS.md — vx11 ## Project Unix libX11 bindings for V. There is a generated raw API and a handwritten native convenience layer. Module `vx11`, MIT, no V package dependencies. Installed X11 headers are the source of truth. ## Commands Compiler: `/home/diviocity/.local/bin/v` (V 0.5.2; compiler checkout is `/home/diviocity/git/v/v`). - Check library: `v -check -shared .` (this is not a main module). - Compile every binding: `v -shared -o /tmp/libvx11.so .`. - Unit tests: `v test bindings_test.v`. - Integration: `v -path '..|@vlib|@vmodules' -o /tmp/vx11-integration tests/integration.v`, then `xvfb-run -a /tmp/vx11-integration`. - Examples use the same `-path` argument when built from this checkout. - Optional extensions: build `tests/extensions.v` with the same `-path`, then run on Xvfb with `-screen 0 640x480x24 -screen 1 800x600x24 +xinerama`. Also run with `-xinerama -extension RANDR -extension MIT-SCREEN-SAVER` and the test's `--unavailable` argument. See README for full commands. - RandR: `v -path '..|@vlib|@vmodules' test randr`; build `randr/tests/integration.v` with the same `-path`, run it on Xvfb with `-screen 0 1024x768x24`, then with `-extension RANDR` and `--unavailable`. The fixture modifies and restores the screen. - XRender: `v -path '..|@vlib|@vmodules' test render`; build `render/tests/integration.v` with the same `-path`, run it on Xvfb with `-screen 0 640x480x24`, then with `-extension RENDER` and `--unavailable`. Composite: `v -path '..|@vlib|@vmodules' test composite`, plus `composite/tests/integration.v` (see composite/README.md). - Every wrapper compiles only with `-no-skip-unused`, e.g. `v -cc gcc -no-skip-unused -path '..|@vlib|@vmodules' -shared -o /tmp/m.so render`. ## Structure - `types.c.v`, `functions.c.v`, `constants.v`, `methods.v`, `vx11_bridge.h`: generated from the installed Xlib headers. The generator is not in this repository; edit these by hand in the generated style and run `v fmt -w`. - `vx11.v`: C includes and linker configuration; `abi.v`: native C long aliases. - `image.c.v`: XImage operation macros and XUniqueContext. - `connection.v`, `window.v`, `graphics.v`, `events.v`, `property.v`: native helpers. - `examples/`: runnable window and bound-method event-handler examples. - `bindings_test.v`, `tests/integration.v`: offline and Xvfb coverage. - `xinerama/`, `shape/`, `screensaver/`: handwritten optional submodules, each with complete public raw header coverage plus native borrowed-connection helpers. Extension linkage belongs only in that submodule, never in the core. - `tests/abi.h`: actual C long pointer/size probes; `tests/extensions.v`: extension behavior, availability, ownership, and lifetime tests. - `randr/`: handwritten XRandR 1.6 submodule with complete `Xrandr.h`/`randr.h` raw coverage (`raw.c.v`), native snapshots (`randr.v`, `property.v`), field-width probes (`randr_test.v`, `tests/abi.h`), and an Xvfb fixture (`tests/integration.v`). It imports `vx11.render` for `XTransform`. The C `Connection` typedef is `ConnectionStatus`. Helpers pre-check server state where an X error is fatal. - `render/`: handwritten XRender 0.11 submodule with complete `Xrender.h`/`render.h` raw coverage (`raw.c.v`) and native helpers (`render.v`): format snapshots, owned `PictureHandle`/`GlyphSetHandle`, gradients, glyphs, cursors. It owns the single `XRenderColor`/`XGlyphInfo` declarations that `xft` aliases. Probes in `render_test.v` and `tests/abi.h` check every constant and C long/short width. libXrender's `XRenderReferenceGlyphSet` sends a bad length (upstream defect). - `composite/`: complete `Xcomposite.h`/`composite.h` raw coverage plus `Preview`; `composite_test.v` checks constants against the headers. - A map with a C struct value type can fail to link in this V build (`new_map_aligned` unresolved); store a V struct instead (see `GlyphMetrics`). ## ABI and ownership rules C int is `i32`; C long/unsigned long are `CLong`/`CULong`. XIDs are native C unsigned longs, not always u32. Property format 32 uses C long slots in Xlib. CLong/CULong use explicit i64/u64 or i32/u32 according to Unix target bitness. Do not alias them to V int/uint: C interop can adapt int pointers to 32-bit C int. Use C-backed typedef structs/unions; do not recreate layouts as ordinary V structs. Preserve case-distinct keysyms. Callbacks must use exact C-width argument types. Native handles share ownership state by reference and must be released in order: GC, window, display. Close/destroy is idempotent. Returned V strings/arrays copy and free the C allocation. Raw calls retain Xlib ownership and asynchronous error semantics. New helpers should validate local inputs and document lifetime rules. Do not edit `.crush/` session data. Do not delegate to other agents by default. ## Optional text libraries - `fontconfig/` and `xft/`: C-backed types and native ownership helpers. Keep `#pkgconfig fontconfig`/`#pkgconfig xft` confined to these optional imports. - Generated (generator not in this repository): `fontconfig/` and `xft/` `raw.c.v` and `bridge.h`, and `fontconfig/constants.v`. They cover all non-variadic `fontconfig.h` functions (the two `va_list` builders are skipped), every `FC_*`/`Fc*` macro and enum value, and all non-variadic Xft functions. Edit them by hand in the generated style. Types (`types.c.v`, `types.h`) and helpers are handwritten; `fcfreetype.h` is not bound. - Fontconfig enum output pointers (FcResult*, FcValueBinding*) cross typed C adapters; do not substitute an int pointer directly in a C prototype. FcDestroyFunc/FcFilterFontSetFunc callbacks cross void* adapters. - `FcValue.u` is the anonymous union, named `vx11_FcValueUnion` in `types.h`. - Unit tests: `v -path '..|@vlib|@vmodules' test fontconfig`. - Integration: build `tests/text.v` with that path, then run it under Xvfb. - `examples/xft_text.v`: antialiased rendering and positioned glyph showcase. - Close Xft draw contexts and fonts before the drawable and display. Native open_pattern copies requests; raw XftFontOpenPattern consumes on success. Fontconfig global FcFini must not run while any Xft user remains active.