Skip to main content

Module cursor

Module cursor 

Source
Expand description

Wayland cursor shape to PNG resolution and the cursor delivery worker. Wayland cursor shape resolution: converts a CursorImageStatus into a PNG image buffer for the cursor sink. Uses xcursor to load the system cursor theme and render the appropriate frame at the current scale.

Structs§

CappedSprite 🔒
A cursor sprite encoded at its delivered size: the straight-alpha PNG, the factor the source was scaled by, and the payload’s dimensions. Hotspots are per-job rather than a property of the pixels, so they are scaled against scale instead of being stored here.
Cursor
The loaded XCursor theme, held for the whole capture so cursor lookups stay cheap.

Enums§

CursorJob
One unit of cursor-callback work handed from the calloop thread to the wl-cursor worker. The calloop resolves everything renderer/surface-affine (SHM copies, dmabuf readbacks, hotspots); the worker does the PNG encode, the cache, and the call into the sink so none of that latency lands on the input/render thread. One channel keeps cursor updates ordered with sink (re)registration.

Constants§

MAX_SPRITE_SIDE 🔒
Longest side of a cursor surface still read: an application’s own pointer can be well past what is delivered (the cap downscales it), but a surface this large is not a cursor at all and its copy is skipped.
SPRITE_CACHE_MAX 🔒
Sprites retained before arbitrary eviction; an evicted sprite re-encodes on next appearance.

Functions§

cap_and_encode 🔒
Apply the size cap to a premultiplied sprite and encode it as a straight-alpha PNG.
capped_job 🔒
Cache wrapper for sprite jobs, keyed by (sprite hash, cap) so a repeat of a sprite already delivered under the same cap is a plain clone of its PNG; a miss decodes the sprite, caps it, and encodes it once. Keying on the cap keeps a live SetSizeCap from serving stale sizes.
decode_gles_cursor 🔒
Read a dmabuf sprite’s RGBA readback (stride recovered from the mapping length) into a premultiplied RGBA image.
decode_shm_cursor 🔒
Read a wl_shm BGRA/XRGB sprite sub-image into a premultiplied RGBA image, the form cap_and_encode must resize before it unpremultiplies. Stride/offset are clamped non-negative with checked arithmetic so a garbage descriptor skips pixels instead of panicking; a sprite past MAX_SPRITE_SIDE is ignored.
frame 🔒
Pick which animation frame to show for the elapsed time, so animated cursors (a spinner, a progress ring) actually advance instead of freezing on frame zero; it maps the time onto the frames by cycling their cumulative delays.
load_icon 🔒
Parse the named icon from the theme’s cursor file into its frames.
nearest_images 🔒
All frames of the theme variant whose pixel size is closest to size. XCursor files bundle the same cursor at several sizes, and choosing the nearest one avoids scaling a mismatched bitmap into a blurry or aliased cursor.
scaled_hotspot 🔒
Scale a source hotspot onto a delivered sprite. Consumers treat the hotspot as an offset INTO the bitmap, so the rounded coordinate is clamped to the payload rather than allowed to land one pixel past its right or bottom edge.
spawn_cursor_worker
Spawn the cursor delivery worker; returns its job channel. The worker owns its own theme handle, the PNG cache, and the sink until one replaces or withdraws it (like the compositor thread itself); SHUTDOWN gates every call into it.