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, thenxvfb-run -a /tmp/vx11-integration. - Examples use the same
-pathargument when built from this checkout. - Optional extensions: build
tests/extensions.vwith the same-path, then run on Xvfb with-screen 0 640x480x24 -screen 1 800x600x24 +xinerama. Also run with-xinerama -extension RANDR -extension MIT-SCREEN-SAVERand the test's--unavailableargument. See README for full commands. - RandR:
v -path '..|@vlib|@vmodules' test randr; buildrandr/tests/integration.vwith the same-path, run it on Xvfb with-screen 0 1024x768x24, then with-extension RANDRand--unavailable. The fixture modifies and restores the screen. - XRender:
v -path '..|@vlib|@vmodules' test render; buildrender/tests/integration.vwith the same-path, run it on Xvfb with-screen 0 640x480x24, then with-extension RENDERand--unavailable. Composite:v -path '..|@vlib|@vmodules' test composite, pluscomposite/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 runv 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 completeXrandr.h/randr.hraw 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 importsvx11.renderforXTransform. The CConnectiontypedef isConnectionStatus. Helpers pre-check server state where an X error is fatal.render/: handwritten XRender 0.11 submodule with completeXrender.h/render.hraw coverage (raw.c.v) and native helpers (render.v): format snapshots, ownedPictureHandle/GlyphSetHandle, gradients, glyphs, cursors. It owns the singleXRenderColor/XGlyphInfodeclarations thatxftaliases. Probes inrender_test.vandtests/abi.hcheck every constant and C long/short width. libXrender'sXRenderReferenceGlyphSetsends a bad length (upstream defect).composite/: completeXcomposite.h/composite.hraw coverage plusPreview;composite_test.vchecks constants against the headers.- A map with a C struct value type can fail to link in this V build
(
new_map_alignedunresolved); store a V struct instead (seeGlyphMetrics).
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/andxft/: C-backed types and native ownership helpers. Keep#pkgconfig fontconfig/#pkgconfig xftconfined to these optional imports.- Generated (generator not in this repository):
fontconfig/andxft/raw.c.vandbridge.h, andfontconfig/constants.v. They cover all non-variadicfontconfig.hfunctions (the twova_listbuilders are skipped), everyFC_*/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.his 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.uis the anonymous union, namedvx11_FcValueUnionintypes.h.- Unit tests:
v -path '..|@vlib|@vmodules' test fontconfig. - Integration: build
tests/text.vwith 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.