# Development environment: test a desktop without replacing yours

## Recommendation and scope

Start with a separate X server on the existing Linux desktop: Xephyr for visible experiments and Xvfb for automated tests. Neither needs a VM or a full guest desktop. The WM manages only the windows on that test server, so a WM crash cannot rearrange the ordinary desktop. Use a disposable VM as an optional stronger boundary when testing installation, login sessions, packages, or broad filesystem changes. Keep Rust policy tests independent of any display server.

This is an environment plan, not an installed environment. The repository has a compiled policy sketch, not a runnable Rust window manager. On the host inspected on 3 October 2026, Arch Linux has cargo, rustc, cc, pkg-config, xauth and Xorg; Xephyr, Xvfb and xdpyinfo were not found on PATH. The CPU reports Intel VT-x, but `/dev/kvm` is absent and QEMU/libvirt executables were not found; a hardware feature alone does not make a VM runnable. Guest provisioning, server runners and regression suites below remain to be implemented.

## 1. Pick the lightest environment that answers the question

**Default for this project: Xephyr and Xvfb directly on Linux.** This is a small X11 development setup: no VM provider, hypervisor, virtual disk, guest OS or VM viewer. Xephyr provides an independent desktop rendered inside one window on the existing graphical desktop. DWM connects to Xephyr's display ID (for example, `:100`) and can manage only windows on that nested X server. The existing desktop's window manager still manages the Xephyr window. If test DWM crashes, it loses control of the inner desktop; it cannot take over or rearrange the outer desktop.

Xephyr is a real nested X server, not a VM, window manager, package manager or acronym that the project needs to expand. It implements a separate X server and draws its framebuffer through a window on an already-running X display. The upstream manual describes it as an “X server outputting to a window on a pre-existing X display”; it supports extensions including Composite, Damage and RandR. [Xephyr manual](https://xorg.freedesktop.org/archive/X11R7.5/doc/man/man1/Xephyr.1.html)

Xvfb is another real X server, with a virtual framebuffer in memory and no visible window or physical display device. Use it for event-driven tests and C/Rust comparisons. [X.Org Xvfb manual](https://xorg.freedesktop.org/releases/X11R6.9.0/doc/html/Xvfb.1.html)

A separate X server isolates window trees and input routing. It does **not** isolate program files, processes or privileges: a test program still runs as your Linux user. This is usually suitable for developing DWM's window-management code because the experiment is which server receives X requests. Use a disposable VM when the experiment changes a whole session, system packages or startup configuration. A normal unprivileged process can still write any files permitted to its user account.

### VM provider and hypervisor, if the stronger boundary is needed

A **hypervisor** runs and controls a guest computer. QEMU creates the virtual machine; on Linux, KVM uses the CPU's hardware virtualization support to run it efficiently. Libvirt can manage the QEMU/KVM machine; virt-manager is an optional graphical front end. QEMU, KVM, libvirt and virt-manager are related pieces, not four competing VM providers. See the [QEMU overview](https://www.qemu.org/docs/master/system/introduction.html) and [QEMU hypervisor glossary](https://www.qemu.org/docs/master/glossary.html).

This host's CPU reports VT-x, but there is no visible `/dev/kvm` device and no QEMU/libvirt commands installed. So QEMU/KVM is a sensible future VM choice, but is not available as-is and is unnecessary for normal WM iteration. Docker is installed, but a container shares the host Linux kernel; it is not the same isolation boundary as a VM and is not needed for the light Xephyr workflow.

If you later install VM software, use QEMU/KVM with a small stable Linux guest, a minimal Xfce desktop, 2 virtual CPUs, 3 GiB RAM and a dynamically growing 16 GiB disk as a starting point. Xfce gives Xephyr a graphical guest display without a heavier desktop. Take a guest snapshot before experimenting with guest startup or packages. Keep a private guest checkout instead of sharing your host home directory. A VM viewer shows the guest screen in a host window.

## 2. Understand what DISPLAY selects

An X server process owns its own window tree, input focus and connection endpoint. DWM can manage only the server to which it connects. It does not become the operating system's window manager just because its binary is running.

`DISPLAY` tells X11 programs which server to connect to. For example, `:100` means local server number 100; `:100.0` explicitly names that server's X screen 0. This number does not mean monitor 100. `XAUTHORITY` points to a file containing authorization credentials for that server. In the ordinary Xephyr workflow, Xephyr connects to the existing graphical display, while DWM and its test applications connect to Xephyr's separate display. Do not launch DWM with the outer desktop's DISPLAY.

```text
Existing desktop's X server
  └── one window: Xephyr, independent test X server :100
        ├── either C DWM or Rust WM
        └── terminal, dialog, controllable test client

Automated job: Xvfb :101, independent test server in memory
  ├── either C DWM or Rust WM
  └── scenario driver and observer

Optional later: QEMU/KVM guest OS → guest display → Xephyr
```

Xephyr requires an existing graphical desktop on which to draw its window. On a Wayland desktop this may be the desktop's XWayland compatibility server. If no graphical display is available, use Xvfb for automated tests. For visible testing, start a minimal graphical guest in the optional VM.

## 3. Four test levels

| Environment | What it checks | When to use it | Limits |
| --- | --- | --- | --- |
| No X server | Tag sets, view history, geometry, layout, state relationships | On every change; debugger and ordinary Rust unit tests | Does not exercise protocol requests or real events |
| Xvfb on Linux or inside optional VM | Mapping, configure requests, properties, focus, lifecycle and event handling | Automated scenarios and C/Rust comparison | No visible desktop; no assumption of real monitor hotplug or GPU behavior |
| Xephyr on host (or inside optional VM) | Visible tiling, dialogs, shortcuts, bar, drag and resize | Interactive debugging and reproducing a failed scenario | Outer shortcuts can interfere; nested input and extensions differ from a normal session |
| Guest's own Xorg session | Full WM startup/exit and real application session behavior | Later release checks, after nested tests pass | Virtual display topology still differs from physical hardware |

A small final real-hardware trial may be needed for physical monitor changes and device-specific issues. Record that as a separate release check; a VM result is not evidence for every GPU or monitor setup.

Sources: [Xephyr manual from X.Org](https://xorg.freedesktop.org/archive/X11R7.5/doc/man/man1/Xephyr.1.html), [X.Org Xvfb manual](https://xorg.freedesktop.org/releases/X11R6.9.0/doc/html/Xvfb.1.html), [QEMU system emulation](https://www.qemu.org/docs/master/system/introduction.html). Check installed server manuals and extension probes as part of provisioning.

## 4. Optional VM setup for full guest-session checks

If the VM profile becomes necessary, use QEMU/KVM on Linux and optionally manage it with libvirt/virt-manager. That stack is currently unavailable on this host. Choose a stable Linux guest supported by the project; Debian stable is a reasonable reference guest even though the host is Arch. Record the exact guest image identity and package versions rather than relying on an unrecorded rolling installation.

Suggested starting allocation: 2 virtual CPUs, 3 GiB RAM and a 16 GiB expandable disk with a minimal Xfce desktop. This leaves room for the guest GUI without choosing a full GNOME/KDE session. Adjust after measuring builds. Use an ordinary unprivileged development user. The guest needs:

- Rust toolchain, rustfmt and Clippy; choose and pin a toolchain when the actual Cargo package is introduced. Commit Cargo.lock for the WM executable.
- C compiler, make and pkg-config; Xlib, Xft, fontconfig, FreeType and Xinerama development files for the unchanged C baseline.
- Xephyr, Xvfb, xauth, xdpyinfo, xprop, xwininfo and a terminal such as xterm.
- XTEST support and its driver dependencies for real injected input; Xinerama querying support for the monitor cases DWM actually uses.
- A known font set, a fixed locale and keyboard mapping; record them alongside test results.
- A debugger and logging tools. Start with GDB for both binaries; add optional tooling only when it helps reproduce a specific problem.

Create a clean snapshot after provisioning. A snapshot is a restore point for the VM disk/state. Test installation and session changes after taking it, then restore when necessary. Keep personal accounts and real documents out of the guest. Use a cloned checkout or transfer a source archive; avoid a writable host-home share. If a shared checkout is used, its file changes affect the host, so it is not part of the isolation boundary. Store important result artifacts outside snapshots before reverting.

Record provisioning in a script and an environment manifest: optional guest image checksum, packages/versions, Rust toolchain, compiler flags, fonts, locale, keyboard mapping and X server options. Fetch dependencies during provisioning; run scenario jobs without external network dependencies where possible. Do not treat WMS Cloud's nginx documentation page as the WM execution environment.

## 5. Interactive loop in Xephyr

First build both implementations into local directories; do not run `make install`, replace the login session, or launch the WM with an inherited outer-desktop DISPLAY.

The C baseline build is a copy of `reference/dwm-6.8/` under `build/reference/`, with the test config written into the copy. Keep reference checksums intact. The future Rust debug executable will be `target/debug/rust-dwm` after its Cargo package exists.

The following are example commands for a future runner, not commands executed in this planning pass. In the light profile they run on the host and use its existing graphical display only as Xephyr’s drawing surface. The runner must allocate an unused nested display and create the matching private authorization file first:

```sh
# Run on Linux. Xephyr inherits the existing desktop connection for its outer window.
# :100 is illustrative: the runner must choose an unused server number.
Xephyr :100 -screen 1280x800 -resizeable -nolisten tcp \
  -auth /tmp/rust-dwm-run/authority

# A second terminal on the same machine, after the test server is ready:
env DISPLAY=:100 XAUTHORITY=/tmp/rust-dwm-run/authority \
  RUST_BACKTRACE=1 ./target/debug/rust-dwm

# Launch an application on that same inner server, not the outer desktop:
env DISPLAY=:100 XAUTHORITY=/tmp/rust-dwm-run/authority xterm
```

The Xephyr process uses the current desktop authorization to draw its outer window and the `-auth` credential for clients connecting to the nested server. The runner must preserve the current desktop DISPLAY for Xephyr, then set DISPLAY/XAUTHORITY only for DWM and test applications. Do not globally export a test DISPLAY and hope every process inherited the right one.

Watch a terminal open, resize and disappear. Break in `manage_window` to inspect a MapRequest; compare the local client record with `xwininfo` geometry on the same test server. Inspect properties with `xprop`. Pause or crash the WM deliberately: its test applications should remain confined to the nested display, and the outer desktop should remain usable. Restarting/adopting existing windows is a separate startup-scan test.

Use a debugging configuration whose shortcut modifier does not conflict with the outer desktop. Use identical configurations for actual C/Rust comparisons. Keep the test desktop windowed at first, and document how to leave an input grab for the installed Xephyr version. Stop processes through the runner; avoid broad commands that kill every X server or WM with the same name.

## 6. Automated loop in Xvfb

Xvfb runs a real X server with its framebuffer in memory. Tests still create server windows and exchange X11 messages; they simply need no physical screen or visible nested window.

A future runner creates a new server for each case/implementation. Illustrative server invocation:

```sh
Xvfb :101 -screen 0 1280x800x24 -nolisten tcp \
  -auth /tmp/rust-dwm-run/authority
```

Do not assume creating two Xvfb screens creates two DWM monitors. Probe the Xinerama information DWM consumes. Use simulated monitor-policy fixtures for unit tests and an explicitly verified server/VM topology for integration tests; required topology tests fail setup when their environment is missing.

Runner sequence:

1. Create a private run directory with permissions 0700; allocate an unused display and fresh random MIT-MAGIC-COOKIE-1 authorization data. Do not use `-ac`, `xhost +`, or the host display socket/credentials.
2. Launch the test server as an unprivileged child with TCP listening disabled. Check connection readiness using its credential and a bounded deadline; verify dimensions, depth and required extensions.
3. Launch exactly one WM on that display. Confirm it actually claimed management through a dedicated probe or test acknowledgement; `_NET_SUPPORTING_WM_CHECK` alone does not prove redirection ownership.
4. Launch the controllable scenario client and observer on that same display. Wait for observable conditions rather than fixed sleeps.
5. Save logical window IDs, geometry, borders, focus, stacking, map state and relevant properties. Visibility also checks coordinates because C DWM hides tagged-out windows offscreen.
6. Record stdout/stderr, event traces, environment manifest, scenario seed, exit status and framebuffer screenshot where useful.
7. On success, failure or timeout, terminate only this run's known child process groups, wait for them to exit, and clean up only owned resources. Never delete another server's lock/socket. Keep failure artifacts.
8. Run the same scenario with a fresh identically configured server and the other WM. Normalize resource IDs and timestamps, then compare the semantic observations.

Run C and Rust sequentially first to simplify debugging. Parallel runs later require independent displays, credentials, process groups and output directories. A timeout, crashed server or unsupported required extension is an explicit failure/setup result, never a pass.

## 7. Runner interface and repository layout

Use Python's standard library for process supervision initially; no JavaScript libraries are needed. Proposed commands are interface specifications, not existing scripts:

```sh
python3 tools/dev_session.py --server xephyr --wm build/reference/dwm
python3 tools/dev_session.py --server xephyr --wm target/debug/rust-dwm
python3 tools/compare_wms.py --server xvfb --scenario transient \
  --reference build/reference/dwm --candidate target/debug/rust-dwm
```

`dev_session.py` owns server allocation, credentials, readiness, child environments, logs and cleanup. `compare_wms.py` uses the same lifecycle code and shared scenarios; it adds normalization and assertions. Keep the environment runner separate from WM code so a WM defect does not invalidate the observations.

```text
tools/dev_session.py         interactive runner entry point (planned)
tools/compare_wms.py         differential runner entry point (planned)
tools/xsession.py            shared server/process lifecycle (planned)
dev/environment.md          provisioned versions and optional VM rebuild procedure
build/reference/            disposable C baseline build
artifacts/regressions/       per-run logs, snapshots and environment identity
```

No runnable runner or guest provisioning has been added yet. The first implementation should be a small host Xephyr/Xvfb runner and C-only transient scenario; do not wait for a finished Rust WM to start environment validation.

## 8. Debugging, CI and promotion

Every change: format/lint and pure policy tests. Changes touching X11: run focused Xvfb scenarios. Before merging an implementation slice: required C/Rust comparisons. Before release: Xephyr application trials, then an optional optional guest Xorg session, then explicitly scoped real-hardware checks if required.

For CI, a container can package build tools and Xvfb, provided the X server runs inside that job. Never forward the host X socket or host authorization into the test container. Containers share the host kernel; a VM is reserved for interactive guest-session and install testing. Use bounded job resources and retain failure artifacts.

Use debug builds with backtraces for Rust and symbols for C. Preserve ordinary optimized C behavior for the compatibility baseline. Optional sanitizer builds are separate diagnostic jobs; do not silently substitute them for the reference binary. Keep logs focused on event type, logical window name, local decision and outgoing operation so you can follow the cause of a bad rectangle.

## 9. Implementation milestones and acceptance checks

1. Check for a graphical X11/XWayland display; add Xephyr and Xvfb and record server extensions. Acceptance: open an isolated nested desktop and run a no-display test. Provision QEMU/KVM guest only when session/system-change checks are needed.
2. Implement server lifecycle runner. Acceptance: intentionally crash the WM, time out a scenario and interrupt the runner; child cleanup completes and the outer desktop remains usable.
3. Build unchanged C baseline and automate the transient test. Acceptance: bounded successful run with assertions and saved failure evidence after an injected defect.
4. Add Rust vertical slice. Acceptance: open a terminal, adopt it, tile/focus it, destroy it and exit; shared C/Rust observations agree.
5. Add monitor, input, fullscreen and real-application cases. Acceptance: every required scenario has a supported environment and meaningful pass/fail result.
6. Test installation/startup/exit in a guest snapshot. Acceptance: WM can be stopped, previous guest session restored, and evidence retained before reverting.

Xephyr validates window behavior without replacing the host desktop. It does not contain ordinary process or filesystem changes. The optional VM adds a separate guest OS and disk. Neither profile fully reproduces every physical GPU or hot-plug topology.
