nested-wayland-session #
A minimal single-app nested Wayland compositor for GUI testing. It hosts exactly one Wayland client fullscreen on the real GPU (dmabuf) path, photographs the framebuffer as a PNG, injects synthetic pointer and keyboard input, and takes all of this over a small Unix-socket control API.
It is built on Smithay and installs through cargo,
so an automated test can give a
GUI app a private,
deterministic screen on any machine,
with no distro package manager
and no system-wide changes.
The full rationale,
the on-hardware measurements,
and the source review of every
alternative considered are recorded in
doc/decision/nested-wayland-session.md
(issue #272).
A plain-language overview is in
doc/planning/nested-wayland-session.md.
What it does #
- Gives exactly one app a private nested screen and keeps it fullscreen.
- Runs the real GPU render path:
it imports the client's
zwp_linux_dmabuf_v1buffers (v4 modifier feedback, v3 fallback) into a GLES renderer, the same path a real user gets, so the app is checked the way it actually draws. - Shuts down cleanly when the hosted app exits, propagating the app's exit code.
- Saves a screenshot of the current frame as a PNG when asked.
- Records a frame sequence at a steady 60fps that holds even when the hosted app is laggy or resource-hungry (with optional systemd CPU isolation of the app).
- Clicks at a point, presses keys, and types text into the app.
- Provides an isolated clipboard through wlr-data-control and ext-data-control,
sharing the nested seat's regular clipboard with
wl_data_deviceclients. - Changes the nested screen size.
- Serves a private dark or light appearance preference and switches it while the app runs, without touching the host desktop theme.
- Keeps the hosted app drawing when its own window is hidden or the host session is locked, so screenshots show the app's current frame.
- Answers every control command with a plain machine-readable
ok/errline.
Requirements #
At build time (supplied by the Fedora build container,
see Building):
wayland-devel,
libxkbcommon-devel,
libdrm-devel,
plus a Rust toolchain.
At run time (present on virtually every Linux desktop):
libwayland-client,
libwayland-egl,
libxkbcommon,
libEGL,
libGLESv2,
libdrm,
dbus-daemon when --color-scheme is used,
and a running parent
Wayland session (this version is a nested winit client of an existing compositor).
Install #
Through mise with the cargo backend:
mise use "cargo:monochromatic-nested-wayland-session"
A source build compiles the crate.
To fetch a prebuilt binary instead of building from
source,
use cargo-binstall:
cargo binstall monochromatic-nested-wayland-session
Usage #
--help or -h prints generated help and exits successfully without opening Wayland.
--version reports the binary version without starting the compositor.
Clap handles parent options only until the child command begins:
app --help and -- app --help both forward --help to the child.
Unknown options before the child remain usage errors.
Clap uses exit 2 for usage errors instead of the former generic exit 1;
help/version use exit 0.
Joined values such as --size=800x600 are also accepted.
monochromatic-nested-wayland-session [--socket PATH] [--size WIDTHxHEIGHT]
[--color-scheme dark|light] [--isolate]
[--app-cpu-quota PCT] [--app-cpu-weight N] [--] COMMAND [ARG...]
--socket PATHenables the control API on a Unix socket atPATH. Omitted, the tool just hosts the app with no control channel.--size WIDTHxHEIGHTsets the initial nested-screen size in pixels (default1280x720).--color-scheme dark|lightgives the hosted client a private XDG Settings portal with deterministic appearance. It does not change the host desktop theme. Thecolor-schemecontrol command switches it while the client runs.--isolatelaunches the hosted app inside a resource-controlled systemd scope so a greedy app cannot starve the capture pipeline (see 60fps recording). It degrades to a direct launch, with a warning, when systemd is unavailable.--app-cpu-quota PCToverrides the app's CPU cap under--isolate, in percent of one core (800means eight cores' worth). Default: leave roughly a quarter of the machine free for the compositor.--app-cpu-weight Noverrides the app's systemdCPUWeight(1 to 10000) under--isolate. Default: a low weight, so the app yields to the compositor under contention.COMMAND [ARG...]is the single client to host. Everything after--(or the first non-flag token) is the command, run withWAYLAND_DISPLAYpointed at the nested socket.
Host an app and drive it from a script:
# Terminal 1: start the compositor with a control socket.
monochromatic-nested-wayland-session --socket /tmp/nws.sock --size 800x600 -- my-app
# Terminal 2: drive it (any tool that speaks a Unix socket works; nc shown here).
printf 'screenshot /tmp/before.png\n' | nc -U /tmp/nws.sock # => ok
printf 'type hello\nkey enter\n' | nc -U /tmp/nws.sock # => ok\nok
printf 'resize 500 400\n' | nc -U /tmp/nws.sock # => ok
printf 'screenshot /tmp/after.png\n' | nc -U /tmp/nws.sock # => ok
printf 'quit\n' | nc -U /tmp/nws.sock # => ok
Isolated clipboard #
Hosted clients receive the nested WAYLAND_DISPLAY without inherited WAYLAND_SOCKET,
DISPLAY,
or XAUTHORITY.
This prevents clipboard libraries from falling back to the host X11 clipboard.
No host clipboard synchronization is provided.
Clients connected to the nested socket can exchange text and other MIME payloads.
Primary selection is not advertised,
and clipboard data is not persisted after its owner exits.
Use mise run //package/cli/nested-wayland-session:inspect:clipboard to verify the built release binary.
The task requires wl-copy and wl-paste,
launches a separate nested session,
checks text and binary round-trips,
clears each selection,
and checks clean producer shutdown.
It asserts child display isolation before touching any clipboard.
Isolate dark and light appearance #
Use explicit color schemes for GUI snapshots:
monochromatic-nested-wayland-session --color-scheme dark -- my-app
monochromatic-nested-wayland-session --color-scheme light -- my-app
The fixture starts a private session bus and minimal org.freedesktop.portal.Settings service,
then sets DBUS_SESSION_BUS_ADDRESS only for the hosted client.
The parent compositor and desktop environment remain untouched.
The private bus intentionally does not expose unrelated host session services,
such as notifications or file-chooser portals.
Use this option for deterministic appearance tests whose client does not need those services.
Without --color-scheme,
the hosted client inherits its usual session bus.
Normal shutdown removes the private socket directory.
A forced SIGKILL bypasses process cleanup and can leave its PID-named temporary directory behind.
Switch appearance while the client runs #
Start with a control socket and either explicit value,
then send color-scheme on the socket:
monochromatic-nested-wayland-session --socket /tmp/nws.sock --color-scheme dark -- my-app
printf 'color-scheme light\n' | nc -U /tmp/nws.sock # => ok changed
printf 'color-scheme light\n' | nc -U /tmp/nws.sock # => ok unchanged
A change replaces the value the private portal serves through ReadOne,
Read,
and ReadAll,
then emits org.freedesktop.portal.Settings.SettingChanged on the private bus
with the arguments org.freedesktop.appearance,
color-scheme,
and the new value as a variant holding an unsigned integer
(1 for dark,
2 for light).
Requesting the value already served answers ok unchanged and emits nothing,
because the portal defines that signal as emitted when a setting changes.
The command only ever uses the private bus started by --color-scheme.
A session started without that option has no private bus,
so the command answers err and names the option to add;
it never falls back to the session bus the compositor itself inherited.
Use mise run //package/cli/nested-wayland-session:inspect:color-scheme to verify the built release binary.
The task requires gdbus,
dbus-daemon,
dbus-monitor,
dbus-send,
and slint-viewer.
It hosts a Slint scene that reports every Palette.color-scheme value the toolkit applies,
watches the private bus,
switches in both directions,
and checks screenshots and recorded frames.
The compositor's own session-bus environment points at a disposable decoy bus for the run,
and the task requires that the decoy saw no connection and no portal signal.
It prints the directory holding its evidence.
Never change the host desktop theme to produce fixture screenshots.
Use this option for isolated dark and light scenes.
See doc/troubleshooting/slint-nested-color-scheme-portal.md
for Slint's D-Bus lookup and the isolation design.
Control protocol #
Requests are newline-delimited text,
one command per line.
Each request yields exactly
one response line:
ok,
ok <data>,
or err <message>.
pinganswersok(liveness check).screenshot PATHcomposites the hosted app's latest committed frame and writes it toPATHas a PNG. The app needs time to draw after input; see Frame pacing for what keeps that frame current.click X Y [left|right|middle]moves the pointer to the logical point and clicks (button defaults toleft).wheel X Y HORIZONTAL VERTICALmoves the pointer to the logical point and delivers real wheel notches there. Positive counts scroll right and down.key NAME [press|release|tap]presses a named key (enter,escape,tab,space,backspace,up,down,left,right,home,end,pageup,pagedown,ctrl,shift,alt,meta, and single characters). Action defaults totap. For a shortcut, press its modifier, tap the target key, then release the modifier through this same isolated seat. Release held keys in the caller's cleanup path.type TEXTtypes the rest of the line as individual key taps (US layout; characters off that layout are skipped).resize WIDTH HEIGHTrequests a new nested-screen size.drop-file PATH [X Y]originates a compositor-side drag carryingPATHas atext/uri-listand drops it onto the hosted app (defaulting to the window centre), exercising the app's own inbound file-drop path. The compositor is the drag source, so no second app (file manager) is needed. The drop completes asynchronously: the command returnsokonce the drag is under way, the button releases after a short dwell (so the app canacceptand choose an action, the round-trips a real drag needs), and the app then reads thefile://PATHpayload. Use ascreenshotafterwards to observe the result.record DIR [FPS] [FORMAT]starts recording a frame sequence intoDIRatFPSframes per second (default60) inFORMAT(pngdefault, orbmp). See 60fps recording.record stopstops recording and answers with the measured statistics, for exampleok captured=180 dropped=0 failures=0 seconds=3.004 fps=59.9.color-scheme dark|lightswitches the private appearance preference started by--color-scheme. It answersok changedafter notifying subscribed clients,ok unchangedwhen that value was already served, anderr <message>when the session has no private appearance portal. See Switch appearance while the client runs.quitstops the compositor.
Payloads are passed through verbatim:
type text and the screenshot path keep their
spaces and are never interpreted by a shell,
so no quoting rules apply beyond the single
newline that terminates each command.
How it works #
The tool is itself a winit client of the parent Wayland session,
so it inherits the
parent's GPU device and renders with a GLES2/EGL renderer,
following Smithay's anvil
winit path.
Because the fixture owns the compositor,
three testing needs become built-in,
in-process features rather than external tools:
- Screenshots are a framebuffer readback (
ExportMem::copy_framebufferplusmap_texture) encoded with theimagecrate. - Input is synthesised directly through the compositor's own seat,
so events reach only
the hosted client,
never the host session,
and there is no
/dev/uinputinvolvement. - The control API is a Unix socket whose blocking-IO thread forwards parsed commands to the render thread over a channel and returns each result.
Frame pacing #
A Wayland client draws its next frame after the compositor tells it the previous one was shown.
The live path sends that notice after presenting to the parent compositor,
and the parent in turn paces this tool the same way.
A parent that stops presenting the nested window,
for example because the host session is locked or the window is hidden,
would therefore leave the hosted app waiting to draw,
and screenshot showing an old frame.
To keep capture independent of host visibility, a timer at the nested output's 60 Hz refresh sends those notices itself whenever the parent has presented nothing for 50 ms and no recording is running. The log records when this fallback starts and when the parent presents again. While a recording runs, the recorder's own timer sets the pace instead.
Use mise run //package/cli/nested-wayland-session:inspect:stalled-parent to verify the built release binary.
The task hosts one session inside another and starts a very slow recording in the outer one,
which withholds frame notices from the inner one exactly as a hidden window would.
It then requires that inner screenshots follow three appearance switches.
It needs slint-viewer.
The withheld notices come from the outer session's recording,
not from the host's lock or window state.
60fps recording #
The record command captures a frame sequence at a steady rate (60fps by default) that
holds even when the hosted app is laggy or greedy.
Three design choices make that possible:
- The capture is decoupled from the app.
A drift-free timer (scheduled on absolute
deadlines) composites whatever the app LAST committed and reads it back,
whether or not
the app produced a new frame.
A slow app simply yields repeated frames;
the cadence never
stalls.
Frame callbacks still go out at the capture rate,
so an animating app keeps
drawing.
The recorder never calls
submit, so the parent compositor's vsync cannot throttle the capture (the visible window is intentionally frozen while recording). - The render thread's per-tick work is tiny: render, read back, and copy into a pooled buffer. PNG encoding, the expensive part, runs on a pool of worker threads sized to the machine, so it keeps up in parallel. If the encoders ever fall behind, frames are dropped (and counted) rather than blocking the timer, so the cadence is preserved and the shortfall is reported.
- A greedy app is contained with systemd.
Under
--isolatethe app runs in a transient systemd scope with aCPUQuota(hard cap) and a lowCPUWeight, reserving CPU for the capture pipeline. When systemd is unavailable this degrades to a direct launch with a warning; isolation is a robustness enhancement, never a hard requirement.
Formats:
png (compressed,
the default) and bmp (uncompressed,
near-zero encode cost)
are supported.
BMP is the reliable path for sustained high frame rates when PNG's deflate
cannot keep up,
at the cost of large files.
AVIF is deliberately not offered:
its AV1 intra
encode is far too CPU-heavy for real-time capture,
the opposite of what this mode needs.
Measured on a 16-core / AMD Radeon RX 7600 host at 1280x720: PNG and BMP both sustain 59.9 captured fps with zero dropped or failed frames over a three-second capture, and the rate holds while hosting a client that saturates every core.
Building and testing #
The host usually lacks the development headers Smithay links against,
so cargo work runs
in a Fedora build container (see Containerfile);
the resulting binary runs on the host.
Tasks fall back to the host automatically when the development libraries are present.
mise run //package/cli/nested-wayland-session:buildbuilds the release binary.mise run //package/cli/nested-wayland-session:testruns the unit tests.mise run //package/cli/nested-wayland-session:test:allruns them without stopping at the first failure.mise run //package/cli/nested-wayland-session:lint:clippyruns clippy with warnings denied.mise run //package/cli/nested-wayland-session:lint:rustruns the repo's Rust linter (max-lines plus require-rustdoc).mise run //package/cli/nested-wayland-session:verify:containeris the reference build that builds, clippys, and tests inside the container.
Scope #
This version supports the nested-winit path only: it needs a running parent Wayland session at run time. The headless-surfaceless variant, for a bare machine with no screen at all (such as a CI server), is the concentrated risk and is deferred to issue #273.
License #
LGPL-3.0-or-later.
See LICENSES/.