Version0.2.11Verifiednot yet verifiedLicenseBSD-3-Clause

sigil-ui

Retained-mode UI framework with a software renderer

Report a bug or suggest a feature
Clone

git clone https://git.usesigil.org/sigil/sigil-ui.git

Readme

sigil-ui

Wayland windows support named and image cursors through their owned connection. Named requests prefer compositor shapes; explicit theme/size configuration prefers optional library images. The loader combines theme, default and builtin fallback without identifying their origin. Applications select desktop theme preferences. Existing applications retain compositor-default behavior until making a cursor call.

A retained-mode UI library for Sigil, with a software renderer and offscreen, Linux framebuffer, DRM, Wayland and macOS AppKit surfaces. It draws rectangles, bitmap text and alpha masks into XRGB8888 pixel buffers, and can save renders as PNG files.

A view is a function from application state to an element tree. On each update, sigil-ui reconciles that description with the tree it retained from the previous frame, keeps unchanged display items and repaints damaged rectangles. Keys keep children's identity across reordering; components skip a subtree when their function and input are unchanged. Positions are explicit logical pixels, with integer scaling and named theme colors, fonts and images.

Install

Requires Sigil 0.24.8. Add the registry dependency to your package's dependencies list, then run sigil deps install:

(from-pkg name: "sigil/sigil-ui" version: "^0.2")

This release is 0.2.7; see NEWS for changes.

Minimal example

This draws a progress bar offscreen and saves it to progress.png:

(import (sigil math)
        (sigil ui raster)
        (sigil ui theme)
        (sigil ui tree)
        (sigil ui png))

(define theme
  (make-theme
    (list (cons 'background #x101820)
          (cons 'accent #xEDBB45))
    '()
    '()))

(define ui
  (make-ui theme (make-canvas 320 80) 1 'background))

(define (view progress)
  (group 0 0
    (list (rect 20 30 (quotient (* 280 progress) 100) 20 'accent))))

(ui-update! ui (view 50))
(write-png! "progress.png" (ui-canvas ui))
Read the rest

ui-update! returns damaged rectangles in logical pixels. To present them on a surface, multiply each coordinate by ui-scale and pass each rectangle with the canvas to surface-present!.

Renderer and surfaces

The display list supports solid and blended rectangles, bitmap text, colored text runs, grayscale outline text and alpha masks. Pixel loops, PNG encoding and device access are C; the retained tree, themes and display list are Sigil. Bitmap rendering needs no external graphics library. Outline text uses the shared (sigil font) interface and explicitly supplied font files. Native platform backends provide grayscale glyphs and metrics.

(sigil ui surface) provides offscreen buffers, 32-bit XRGB8888 fbdev devices and Linux DRM dumb buffers. DRM master can be dropped and reacquired for display handoff; surface-close! with keep-frame?: #t preserves active scanout on Linux 6.8 or later. Hardware surfaces require access to the device.

(sigil ui wayland) provides windows and fullscreen surfaces, keyboard and pointer events, resizing, integer buffer scaling and damage-aware presentation. It loads libwayland-client and libxkbcommon at runtime. Use a dynamically linked program for Wayland: a fully static musl executable cannot load those libraries. The application owns the event loop; see the demo.

(sigil ui window) provides the common window and input interface on Linux and macOS, including title, clipboard, and acknowledged fullscreen services. See macOS support for the drawing adapter, sigil-window's prebuilt Mac qualification packet, scheduler integration and remaining gates.

Popup chooser

(sigil ui chooser) provides an immutable chooser model, a local keyboard adapter and a retained view. Applications supply stable item IDs, labels and values; the control handles focus, filtering, marks and selection display.

(import (sigil ui chooser))
(define choices
  (make-chooser
    (list (chooser-item 'first "First item" 1)
          (chooser-item 'second "Second item" 2))
    multiple?: #t
    selected: '(first)))
(define accepted (chooser-action choices 'confirm))
;; status: is accepted, canceled or pending; items: is the accepted list.
;; state: is the next immutable chooser, including after keyboard input.

Single selection is the default and confirms the focused item. Multiple selection returns marked records in canonical model order, including marks hidden by filtering. Cancellation and accepted empty selection have distinct statuses. chooser-set-items preserves marks/focus by ID, removes vanished IDs and resolves acceptance against the current records. IDs must be unique and stable; equal labels and duplicate values are allowed. Applications must recheck selected resources before acting on them.

(chooser-item id label value selectable?: #f) supplies a context row: it remains visible to filtering and layout but cannot be focused, marked or accepted. chooser-item-selectable? reports the flag; it defaults to #t for existing callers. Initial marks on context rows are refused. Changing a marked item to context through chooser-set-items clears its mark, so later ID reuse cannot inherit it. Movement skips context rows, including on wrap; an all-context list accepts an empty selection. The single-selection match count excludes context rows. chooser-view uses context-color: for their text and leaves their mark column blank in multiple-selection mode.

chooser-key accepts a shared UI key event while the chooser owns focus. Control-Space toggles, Up/Down or Control-p/n moves focus, Alt-a marks matching rows, Alt-u clears every mark, Return confirms, and Escape cancels. Printable text, including spaces, filters; Backspace removes the final query character. These keys require exact modifiers. Only press events act; releases and repeats are ignored. An action-for-key: callback overrides the local action map without an application mode dependency. The default filter matches case-insensitive label substrings; matches?: can supply application-specific matching.

chooser-view takes the chooser, theme and logical width, with optional max-rows:, font: and color values. It keeps focus visible, clips labels using theme measurements, keys rows by stable ID, and shows total/hidden selection counts. Render it with the ordinary retained tree. The application owns the popup surface, query prompt, focus transfer and action policy. Font coverage follows the selected shared text path; the chooser does not replace missing characters in the stored labels.

Development and status

Version 0.2 is an early API and may change. Layout, input handling and animation timing belong to the application. Fonts may be supplied bitmap fonts or explicit Regular/Bold outline faces. The text API does not include a shaping engine. Native fractional scaling, GPU rendering, drag and drop, IME and accessibility support remain outside this release.

sigil deps install
sigil build
sigil test
cd bench
sigil deps install
sigil build --config release
./build/release/bin/sigil-ui-bench

The benchmark normally uses the published library. For local changes, use Sigil dependency redirects for sigil/sigil-ui to your checkout. The benchmark and demo generate their own untracked locks on installation, so they don't pin an older archive of this repository inside the package itself.

The demo also uses the registry package. From demo/, run sigil deps install, sigil build, then ./build/dev/bin/sigil-ui-demo. It includes Spleen bitmap fonts under their own license.

The default suite needs no display or installed fonts. Outline-text tests use the checked-in OFL fixtures and SHA-256 manifest in test/fixtures; SIGIL_UI_TEST_REGULAR and SIGIL_UI_TEST_BOLD are optional path overrides. On Linux, sigil scripts/test-discovery-error.sgl also checks file fallback when loading Fontconfig fails. Additional checks are sigil scripts/check-surface-close.sgl (GCC and libdrm through Guix), sigil scripts/test-wayland-configure.sgl (a C compiler, wayland-scanner and Wayland server development files), and test/wayland/run (headless sway, swaymsg, grim and a C compiler). The live tests start their own compositor.

Native embedders can opt into linux-dmabuf v4 surface feedback through native/wayland-bridge.h. Ordinary SHM surfaces never bind the optional global. Enabling is asynchronous: dispatch the existing connection, check pending/ready/invalid/unavailable status, then acquire a snapshot. Its copied data preserves tranche preference, raw target devices, flags and exact format/modifier pairs. Device IDs are metadata, not device-selection policy.

Snapshots are immutable and independently reference counted on the owner thread. They remain readable through table replacement, later updates, capability removal and surface teardown. Partial updates retain the last completed snapshot; an invalid completed update revokes new acquisition until a valid batch arrives. Check status/generation before choosing current formats. Closing a surface makes its status unavailable and generation zero; already acquired snapshots retain their original generation and contents. No descriptors or mappings escape into snapshots. Parsing is bounded to a 1-MiB table, 64 tranches and 4,096 resolved format entries per update; malformed or larger updates become invalid without failing the SHM connection. This API does not import GPU buffers or choose synchronization/fallback policy.

The owned socketpair fixture requires no compositor or GPU. With matching Sigil runtime headers and archive already available, run its plain and ASan/UBSan controls using a C compiler with those sanitizers:

CC=cc sigil scripts/check-dmabuf-feedback.sgl /path/to/runtime/include build/dev/native/libsigil.a /tmp/feedback-checks

The controls cover opt-in binding, absent/legacy globals, atomic updates, replacement/reused tables, invalid lengths/indices/devices/duplicates, bounds, recovery, global removal, retained readers and descriptor cleanup. Existing Wayland live tests continue to exercise SHM rendering, input and clipboard. wayland-set-title! updates a live toplevel's metadata without presenting or committing its surface. It returns false for an identical title and rejects embedded NUL, text longer than 4095 UTF-8 bytes, subsurfaces and closed handles. The owned-compositor test/wayland/title.sgl checks the compositor's title and client trace, including duplicate suppression and unchanged surface commits. open-wayland-surface also accepts server-decorations?: #t for a toplevel. It requests server mode before the initial commit and waits for its configure before allowing a buffer. wayland-decoration-mode reports the compositor's chosen server-side/client-side mode, or false when not negotiated. Ordinary opens do not bind xdg-decoration. The owned test/wayland/decoration.sgl covers server mode, unchanged defaults, protocol absence and preference validation.

(wayland-activate! surface (getenv "XDG_ACTIVATION_TOKEN")) submits a compositor-issued token for a live toplevel. It returns #t when the request is submitted. The compositor decides whether to focus the window. An omitted, #f, empty, or invalid token returns #f, as does an unavailable activation protocol. Tokens must be valid UTF-8, at most 1024 bytes, and contain no NUL.

wayland-set-fullscreen! sends an asynchronous xdg-toplevel request. Its true result means sent; wayland-surface-fullscreen? and (fullscreen on?) events change only after the compositor's configure. Child/layer roles refuse the request, and closed surfaces remain errors. The native bridge exposes the same request and confirmed state for embedders. The owned fullscreen control checks both transitions and the state before dispatching the compositor's answer.

sui_wayland_dmabuf_import adds asynchronous import ownership, without attaching buffers. The caller supplies negotiated format/modifier/plane layout, retains its original descriptors and observes pending/ready/failed/ canceled status through an opaque reference-counted handle. Metadata checks do not establish that a GPU or compositor supports a layout. The connection allows at most 64 live handles. Each plane's span must fit in 32 bits and lie within its DMA-BUF's real size, which the kernel reports through lseek(SEEK_END); the first plane's offset + stride * height must fit too. These are the compositor's own import checks, so a refused layout fails locally instead of ending the connection with a protocol error. Canceling or dropping a pending handle keeps a bounded private listener until its terminal reply or connection close, then destroys any late-created buffer. Parent close cancels surviving handles; child close leaves connection-owned imports intact. No dispatch or wait happens inside create/cancel/unref. Presentation and fences are separate.

Run scripts/check-dmabuf-import.sgl with the same header/archive/evidence arguments as the feedback harness. Its plain and sanitizer controls use owned wire peers and memfd descriptors, check transport/cancellation/cleanup, and require zero surface attachments. They do not qualify hardware import.

sui_wayland_present_dmabuf submits a ready same-connection import to a child whose current device-pixel dimensions match it exactly. Frame pacing and buffer reuse are independent: child close cancels a pending frame, while a submitted import remains alive until real compositor release. Canceling or dropping a busy handle cannot destroy its buffer early. Its release callback reports 1 for actual release, or 0 only after connection teardown disconnects; the latter requires retiring the producer, not reusing its allocation. The producer must already meet implicit synchronization requirements; this call does not wait for rendering fences. scripts/check-dmabuf-present.sgl runs owned-wire plain/sanitizer ordering, refusal and teardown controls with the same arguments as the other native harnesses. Hardware pixels and fences need their own qualification before an embedder enables GPU presentation.

An embedder can gate an idle ready import with sui_wayland_dmabuf_import_fence: it borrows a producer fence FD, keeps a private CLOEXEC duplicate and advances readiness in the existing GUI dispatcher. The monotonic timeout is bounded to five seconds. Pending, failed or timed-out waits reject presentation; every terminal path closes the duplicate. Errors and cancellation do not authorize producer reuse. This readiness wait uses implicit synchronization and enables no explicit sync protocol. scripts/check-dmabuf-fence.sgl uses owned pipes to check readiness, delayed progress alongside Wayland dispatch, errors/deadlines, the full 64-handle poll set and cancellation/teardown FD ownership. Those controls do not qualify real GPU sync files.

A completion callback may close the parent and drop its final handle references. Close becomes visible immediately, but connection teardown and disconnect wait until the outermost GUI dispatch or child teardown unwinds, including nested dispatch. Presentation controls exercise this from real frame and release listeners with sanitizers, so libwayland never resumes on a freed display.

See the design document for reconciliation rules, the module map and benchmark measurements. Licensed under BSD-3-Clause.

Releases

v0.2.11 — latest by version, released 5 Dec 2026

All releases — 13 tags in this repository.

Source

Browse the latest source

One page per file, and every line has a permalink.

Recent commitsAtom

The last 20 commits keep a page here. Everything older lives in the clone.