AtlatestRenderedmarkdown

sigil-ui / tree / docswayland-cursors.md

Read the source

Readme

Wayland cursors

The Wayland window owns cursor protocol objects and the latest pointer-enter serial. Requests never dispatch or create another display connection. Desired state survives pointer leave/re-entry; updates outside pointer focus are stored for the next entry. A subsurface request affects the entire shared connection. Embedding applications must route requests from their active view and reset the cursor when the pointer moves over chrome.

Cursor configuration is opt-in. Until the first configure, name or image request, pointer entry keeps the existing compositor-default shape behavior; it does not load a theme or choose a client-side cursor size.

(wayland-cursor-configure! surface theme: "Adwaita" size: 24)
(wayland-set-cursor! surface "pointer")
(wayland-set-cursor! surface "text")
(wayland-set-cursor! surface "none")

Theme names contain at most 255 UTF-8 bytes and no NUL. Explicit logical size is 1..128. An explicit size without a theme uses XCURSOR_THEME or default. Omitting the size or using 0 reads a valid XCURSOR_SIZE in 1..128, otherwise 24. Desktop preference selection belongs to the application. Naming a theme or a positive size marks the configuration explicit. Calling configure with both arguments omitted clears that preference again. Its library fallback then uses the default theme and the environment-selected size; mapped names continue to prefer the compositor. libwayland-cursor honors XCURSOR_PATH and its standard combined theme, inheritance, default-theme and builtin fallback. Its public API cannot identify which source supplied an image; backend theme includes builtin images. It is loaded optionally by soname; SIGIL_UI_LIBWAYLAND_CURSOR selects an explicit library path, like the existing Wayland/XKB library overrides. A window still opens when this library is absent.

Named requests use CSS cursor names and conventional aliases such as left_ptr, hand2 and xterm. Selection follows this order:

  1. After explicit theme or size configuration, try the configured library loader, then the name's mapped compositor shape if the protocol is bound.
  2. With a name alone, prefer its mapped compositor shape. The compositor supplies the user's desktop theme. If the protocol is absent or the name has no shape mapping, try the library's default theme and standard fallbacks.
  3. If neither path supplies the cursor, return false. Unmapped names reach the loader unchanged and are never replaced with the compositor's default shape.

No separate decoder or builtin data is used. A missing optional library still permits mapped compositor shapes. Image requests keep their copied-image path, and none explicitly hides the cursor. On a miss, wayland-cursor-backend reports unavailable. Missing optional support emits no startup warning. A deferred request outside pointer focus returns true and reports unavailable until entry. Theme animation currently uses its first image.

Theme images reload when the output scale changes. Their physical size is requested at logical size times output scale. If an image's dimensions do not divide that scale, it is presented at buffer scale 1 to avoid a Wayland protocol error; such a theme may appear larger. Theme decoding/allocation belongs to libwayland-cursor and is separate from the copied-image bounds below.

wayland-set-cursor-image! accepts premultiplied native ARGB8888 bytes, width and height, with optional stride, hotspot-x, hotspot-y and scale. Stride defaults to width times 4. Dimensions are 1..512, stride is at most 2048 bytes, and scale is 1..8 and must divide both dimensions. The hotspot is in device pixels and must be strictly inside the image. The supplied bytevector must contain all stride times height bytes. At most 1 MiB is copied; later caller mutation is safe. Two reusable SHM buffers are retained. Busy buffers are never overwritten or re-attached, including unchanged configuration, scale updates and re-entry; if both are busy, only the latest pending pixel copy is kept and submitted after a release. Replacing desired state discards its old pending copy. Closing releases all cursor images, theme, surface and optional library ownership.

wayland-cursor-backend observes unavailable, theme, shape, image or hidden without dispatching. The corresponding native operations are declared in native/wayland-bridge.h and reject calls from the wrong connection thread.

scripts/test-wayland-cursor-native.sgl drives the native serial/ownership and validation controls. The live Wayland suite uses owned Xcursor files from scripts/make-cursor-fixture.sgl, captures the actual compositor cursor with grim, and checks theme/custom-image/hidden/re-entry behavior at scales 1/2. It also exercises compositor-shape fallback with the optional library absent, three custom-image updates without dispatch, and custom-image re-entry. The native gate reproduces a queued old release between unchanged configuration and replacement, and verifies that an application making no cursor call keeps the old default with the optional library available. It also controls shape-bound/unbound, explicit theme/size, unmapped-name and loader-miss branches. The live suite checks explicit images with shape support bound, inherited default-theme images without shape support, and an unmapped owned cursor with exact captured pixels. The existing test/wayland/run prepares these fixtures; custom runners supply SIGIL_UI_TEST_CURSOR_ROOT. Tests do not read or change an installed theme.