CupertinoKit: getting started
CupertinoKit is the UI toolkit for Cupertino applications. An application depends on one crate, cupertino-kit
(MPL-2.0), whose modules list the toolkit items an application names and which has a prelude. Every command below runs from a
checkout and was run on the commit this page was written against.
What an application needs
-
A Wayland display.
cupertino_kit::app::run::<A>()connects to the session’s display. Without one it returnscannot connect to the Wayland displayand the example exits with a failure:env -u WAYLAND_DISPLAY cargo run -p cupertino-kit --example counter -
No Cupertino desktop. The kit reads theme data from
$CUPERTINO_SPEC_DIR(a default directory otherwise). When the data is missing or unusable, the application starts on the built-in neutral theme and prints one line on stderr saying why. Any Wayland compositor works. To see it, point the variable at an empty directory:CUPERTINO_SPEC_DIR="$(mktemp -d)" cargo run -p cupertino-kit --example counterThe window opens and stderr shows
cupertino-kit: no Cupertino theme (…); using the neutral theme. -
Fonts and icons come from an asset pack when one is installed (
CUPERTINO_ASSET_DIR, else the user or system pack). The kit falls back to its built-in Inter font. Headless captures of the controls sheet need a pack (kit_capturesays so). -
The renderer follows the application’s class,
Application::RENDERER. An application that declares none (RendererClass::ByUse) starts on the CPU: the kit rasterizes each window there (cupertino-ui-render), repainting only what changed and keeping scrolled content as an image it moves, and hands it to the compositor in shared memory (wl_shm). Once one of its windows covers more than a quarter of its output, or presents more than 30 frames a second for two seconds, the process moves to the GPU renderer (cupertino-ui-render’sgpumodule) on the device the compositor names and hands its windows over as dmabufs, drawing on the CPU while the device warms up.RendererClass::Gpustarts there (a large or busy window),RendererClass::Cpunever goes (a small window drawn now and then);CUPERTINO_RENDERER=cpu|gpuoverrides the class, and the CPU stays the fallback. A long list or grid keeps scrolling cheap by building only the rows near its viewport, each asElement::kept(key, mark, build): a row whose mark is the same as last time keeps its nodes and their layout and is not built again, and while nothing in it changed its paint is laid into the frame as it was, without walking its nodes. -
No Cupertino compositor for transitions. A window with a shell role may hand its open and close to the compositor (
Command::Window(key, WindowRequest::Present(changes)), whenCapabilities::present_animationsays it can), which then fades, moves or scales all the window draws on its clock without the application drawing a frame; the request may be given in the update that opens the window and goes with its first frame. On any other compositor the capability is off and the application animates the window itself, as before. Popups need nothing of the application: where the compositor presents popups (Capabilities::present_popups) the runtime hands it a popover’s growth out of its anchor and shrinking back and a closing menu’s fade, on the same curves, and draws no frame for them. A part of a window can move on the compositor’s clock too: a widget whoseWidget::surface_layerreturns aSurfaceLayerMark(a key and a look: glass style, glass group, corner radius, masks, and whereCapabilities::surface_layer_edgessays so aLayerEdgethe compositor draws along the glass’s outline) draws its subtree into a surface of its own at its layout size, whenCapabilities::surface_layerssays the compositor can; the application then sets or animates that layer’s place, size, opacity, scale, corner radius and content blur withCommand::Window(key, WindowRequest::Layer { key, changes }), which draws no frame; a motion no single curve draws (a product of two springs, a clamped ramp) goes as values at even steps of its duration (LayerChange::through). The window’s root hearsEvent::LayersSettledonce its layers’ last running animation ends. A widget whoseWidget::overlay_layerreturns a mark draws its overlay (a caret) into a layer of its own over the layer it lies in and at that layer’s rect, inside a marked subtree too, so the overlay can fade on the compositor’s clock while it moves with what it lies on (BareField::caret_layer). The compositor holds every value it shows in a range far past any output (places and sizes within a million points, scales up to 64), and one glass group takes at most 16 layers of a window: a 17th is a protocol error (group_full). Elsewhere the subtree paints in place and the application draws its motion itself. -
A Rust toolchain. Nothing else is installed or enabled by these steps.
Build and run the examples
The four examples live in crates/cupertino-kit/examples. Each opens a window on the session’s display and runs until
you close it.
| Example | What it shows | Command |
|---|---|---|
| Counter | A number and two buttons that change it | cargo run -p cupertino-kit --example counter |
| Forms | A sign-in form: a name, a password and a choice | cargo run -p cupertino-kit --example forms |
| Virtual List | 50,000 two-line rows in a scrolling list with multiple selection, a status line, and a button that reverses the order and keeps the selection | cargo run -p cupertino-kit --example virtual-list |
| Editor | Text editing, selection and undo | cargo run -p cupertino-kit --example editor |
Build all four without running them:
cargo build -p cupertino-kit --examples
Run them in a nested Cupertino session, on another compositor, or on the host’s Wayland session; see Building and running for the nested server. On a Wayland session, Counter and Forms run until you close them.
From C
The C SDK is the cupertino-kit package: the library libcupertinokit.so.1, the header
/usr/include/cupertinokit-1/cupertinokit.h and cupertinokit.pc. A C program needs nothing else, and takes every
path from pkg-config. The ABI’s rules (versions, handles, threads, errors) are at the top of the header and in
crates/cupertino-ui-abi/README.md. Today the library runs the headless backend only. With the package installed,
and gcc, make and pkgconf:
cupertino sdk info # what is installed, file by file
cupertino sdk check # build and run a probe with /usr/bin/cc
cupertino sdk new --lang c demo # main.c, a Makefile, demo.desktop and a README
make -C demo && ./demo/demo # prints count: 1, count: 2, count: 3
Versions: the header defines CUPERTINOKIT_ABI_MAJOR and CUPERTINOKIT_ABI_MINOR for the compiler, and
pkg-config --atleast-version=1.0.0 cupertinokit checks the installed SDK in a build script. At run time
ck_abi_version reports the library’s version; pass the minor version the program needs as abi_minor to
ck_runtime_new, which refuses an older library with CK_ERROR_VERSION, and ask ck_has_capability before calling a
function added after 1.0. A new major version gets a new soname and include directory. Threads: a runtime belongs to the
thread that created it; other threads only post to it through a waker (ck_runtime_waker, ck_waker_post), and the
runtime’s thread reads the posts with ck_poll_events.
cupertino sdk new --lang rust NAME starts a Rust project on the cupertino-kit crate of the same release instead
(--source CHECKOUT takes it from a Cupertino checkout, offline or before the release is tagged). The samples in crates/cupertino-ui-abi/examples/c build with make the same way.
Accessibility
app::run publishes every window’s accessibility tree over AT-SPI (cupertino-ui-wayland’s atspi module, on AccessKit’s Unix
adapter). Nothing is exported until an assistive technology turns accessibility on (org.a11y.Status IsEnabled).
Works:
- Roles, names, descriptions, states, bounds, relations, children and values (text, number with range and step, toggle).
- Actions from the assistive technology: click, focus, increment, decrement, expand, collapse, show menu, scroll into view, set value. An action reaches the application only if its target advertised it.
- Password and protected values carry no value and cannot be set from outside.
- A text field’s caret and selection, in characters, and a selection set from the assistive technology. A protected field publishes neither.
- A window root without a name of its own is named by the window’s title. A list item, tree item, cell or tab without a name is labelled by the text inside it. Menu items, tabs and page dots say their place and how many there are.
- Tests can check a whole window with
cupertino-ui-test’saccessibility_audit(unnamed controls, missing values and states, focus that does not agree with the tree, masked text, items without place or count) and drive it as a screen reader would with itsAssistiveTechnologystand-in, which also records what live regions announce. - While the session is locked, and until an application learns it is not, each of its windows reads as an empty frame without a name and takes no action from the assistive technology; nothing is announced. The unlock publishes the windows whole again. The lock screen is what an assistive technology reads behind the lock.
Not done:
- Bounds are window-relative, because a Wayland client does not know its window position.
- A closed window’s AT-SPI object stays until the application exits.
- An application on another toolkit keeps publishing its tree while the session is locked: only Kit applications hide theirs.
No screen reader was run against the examples for this page, so how a screen reader reads them is not documented here.
Right to left
What exists:
-
Layout mirrors children inside their parent in right-to-left mode. A horizontal scroll view starts at its right edge. Insets are physical and do not mirror.
-
Text follows UAX 9: the base direction comes from the paragraph style or the first strong character, runs are shaped in their direction, lines are reordered for display, and carets, hit testing and selection rectangles work across direction changes, for Latin, Hebrew, Arabic, Devanagari, emoji and digits inside right-to-left text.
-
In the toolkit’s text editing (
cupertino-ui-text), the arrow keys move on screen through right-to-left text. -
The toolkit’s controls sheet draws mirrored:
cargo run -p cupertino-kit --example kit_capture -- kit/controls --direction rtlThis writes light and dark PNGs under the build directory’s
captures/.kit/iconstakes the same flag; chevrons follow the reading direction. -
The controls gallery shows every control family together. Hold one down, disable them all, change their size or draw them over a busy backdrop:
cargo run -p cupertino-kit --example kit_capture -- kit/gallery --state held-switch --control-size large --backdrop busy --scale 2 cargo run -p cupertino-kit --example kit_capture -- kit/gallery --sheetThe sheet puts the resting, held and disabled states side by side.
Limits:
app::runalways lays out left to right; it has no option to change that yet. The kit does not choose the direction from the locale or the session.