Files
chandra/README.md
T
Claude 77fcc4db1c
CI / test (push) Canceled after 12m58s
Screenshot editor: annotate, blur, pixelate, redact and crop before saving
Every screenshot now opens in an editor after KDE Spectacle's annotation mode:
Arrow, Line, Rectangle, Ellipse, Pen, Highlighter, Text, Number markers, Blur,
Pixelate, Redact and Crop, 8 colours, 3 sizes, undo/redo. Enter saves and
copies, Ctrl+C copies only, Esc discards.

- Drawn by the compositor (shot_editor.mbt), keyboard owned by it while up.
- Annotations are drawn into the picture's pixels at full size (annotate.mbt),
  so what is shown is what is saved. Blur = 6x6 block average + 3 box-blur
  passes; redact is opaque; both touch only their box (pixel tests).
- The picture goes to the renderer as <=2 MB strips: one 8 MB image-pixels
  call exhausts wasmtime's hostcall fuel and killed the wasm host.
- Frame callbacks are held while the overlay/editor freeze the screen, so apps
  behind stop drawing (0% CPU vs 52% with a full-screen animating app).
- wasmhost: error buffer 16 KB so trap causes aren't cut off; image-pixels
  limit 1024 -> 16384 a side (both hosts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hh3TaFJh7nhCxAjV4Q
2026-11-26 05:37:03 +00:00

241 lines
15 KiB
Markdown

# Chandra
A modular, KDE-Plasma-inspired Wayland desktop where **every part is a WebAssembly component**
(Component Model, WIT interfaces) written in [MoonBit](https://www.moonbitlang.com), on top of a
deliberately small host. The compositor itself (Wayland server, window manager, scene, shell) is a
component, and so is every panel module: the clock, the dock (task manager), the launcher, the settings.
Chandra was called moon-plasma until 2026-11-25. The code, the WIT packages (`chandra:*`), the
session (`chandra-session`) and the paths (`~/.config/chandra`) all use the new name; an old
`~/.config/moon-plasma/panel.edn` and `state.edn` are still read when the new ones don't exist yet.
Repository: <https://git.site.latha.org/experiments/chandra>
![Chandra desktop](docs/screenshots/desktop.png)
*A frame rendered headless by `build/wasmhost --gfx-out`: the wallpaper, the desktop card and every
panel button are drawn by wasm components.*
## Vision
Plasma's strength is its decomposition (shell, widgets, window manager, runner, settings modules,
notifications, tray). Chandra keeps that decomposition and makes each seam a **typed WIT
interface** with **deny-by-default capabilities**:
* the **host** only owns the wasm engine, devices (sockets, files, DRM/KMS, libinput), the
capability broker and the rasteriser;
* **everything else is a component**: swap the clock for another implementation, swap the shell,
change the theme, without rebuilding the rest;
* components draw by returning a **render list** (`list<draw-op>`), never pixels;
* components can't touch anything their imports and the desktop config don't grant.
Design: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) (Plasma to component mapping, permissions,
versioning) and [docs/compositor-design.md](docs/compositor-design.md) (the compositor and its
hosts). Toolchain notes: [docs/TOOLCHAIN.md](docs/TOOLCHAIN.md). Dark mode and the portal: [docs/dark-mode.md](docs/dark-mode.md). Running as root and run0:
[docs/run0.md](docs/run0.md). Kiosk mode (`--kiosk CMD`, one fullscreen app, locked down): [docs/kiosk.md](docs/kiosk.md). Picking up a new build without logging out (`just reload`, `chandra-ctl reload`): [docs/reloading.md](docs/reloading.md). Chandra as the kiosk shell of the gamerig streaming rigs (feasibility, gaps, plan): [docs/kiosk-gamerig.md](docs/kiosk-gamerig.md).
## How it runs
```
build/compositor.wasm the compositor, a wasm component (components/compositor, code in compositor/)
build/wasmhost the host that runs it: MoonBit, linked to the prebuilt wasmtime C API
build/components/*.wasm panel modules, loaded by the host and drawn by the compositor
```
The **MoonBit host** ([wasmhost/](wasmhost/README.md)) is the only host. It links
`libwasmtime` from the upstream C API release instead of compiling wasmtime, so a cold build takes
about 4 seconds. (An earlier host in Rust on the wasmtime crate, `host-wasm/`, was removed on
2026-11-26.) A **native build** of the same
compositor code (no wasm, `just run-native`) is used by the test suite.
The compositor runs **nested**, as a window on your current Wayland session, as a **login
session** on DRM/KMS with libinput (`--drm`, through libseat/logind), or **on an X server**
(`--x11`: a window under an X window manager, or the whole screen without one), for NVIDIA's
proprietary driver on Xorg ([docs/x11.md](docs/x11.md)).
## Quickstart
Requirements: Linux x86_64, [MoonBit](https://www.moonbitlang.com/download),
[pixi](https://pixi.sh) (it provides `just`, tcc and seatd/libseat), and the dev headers for
libdrm, libinput, libudev and libxkbcommon (on Debian/Ubuntu:
`apt install libdrm-dev libinput-dev libudev-dev libxkbcommon-dev libseat-dev`).
Screen recording needs `ffmpeg` on `PATH`.
```bash
export PATH="$HOME/.moon/bin:$PATH"
moon update # fetch mooncakes dependencies
scripts/setup-toolchain.sh # wasm-tools, wit-bindgen, wasmtime + its C API -> ./.tools (no root)
just run # build compositor.wasm, wasmhost and the modules; open in a window
just client # start foot inside it (or: just client konsole)
```
| Recipe | What it does |
|---|---|
| `just run` | Nested in a window on your Wayland session, MoonBit host |
| `just run-drm` | As a login session on the real screen (from a text console, as yourself) |
| `just run-x11` | On the X server in `$DISPLAY` (NVIDIA on Xorg; the whole screen when no window manager runs) |
| `just install` | Install everything: the "Chandra" display-manager session, "Chandra (X11)" for Xorg, and face unlock (asks for root once). `--link` symlinks into this checkout (later just rebuild), `--native` picks the native compositor, `--pam` turns face unlock on, `--no-face` skips it |
| `just uninstall` | Remove it all again (`--purge` also deletes enrolled faces) |
| `just reload` | Reload the running session's panel modules from disk (`chandra-ctl reload [NAME]`) |
| `just run-native`, `run-drm-native` | The native (non-wasm) build |
| `just compositor-wasm`, `wasmhost`, `modules` | Build one piece |
| `just test` | Native compositor tests and lib tests |
| `just frame` | Render one composed frame to `_build/e2e_frame.png` |
| `just remote-build` | Build on a sprites.dev sprite (`CHANDRA_SPRITE`) and pull the artifacts back |
`build/wasmhost build/compositor.wasm --socket PATH` takes `--window` (nested), `--drm` (login
session), `--x11` (on Xorg; `--fullscreen` under a window manager, `--login-session` to act as the
desktop session), `--theme PATH`, `--no-restore`, `--profile`, `--size WxH` and `--gfx-out frame.png`
(render to a PNG, headless; add `--serve` to keep refreshing it). `WASMHOST_PROFILE=1` prints the
time spent in each host function every 5 seconds; `WASMHOST_TRACE=1` logs every host call.
No GPU? Chandra detects it and asks less of the CPU; `CHANDRA_RENDER=software|hardware` or
Settings > Session > Lighter animations overrides it, and `CHANDRA_FRAME_TRACE=1` logs frame times
([docs/rendering.md](docs/rendering.md)).
`CHANDRA_DEBUG_CONFIGURE=1` (any host) logs each window's configures, acks and committed buffer
sizes, for an app that draws at the wrong size.
The installed session logs to `~/.local/state/chandra/session.log`. Start it as yourself, never
as root: `chandra-session` refuses to run as root (`CHANDRA_ALLOW_ROOT=1` overrides). Installing
goes through `scripts/as-root`, which prefers run0 and falls back to sudo, doas or pkexec
(`CHANDRA_AS_ROOT` picks one). What it installs and its flags: [docs/install.md](docs/install.md). To run a graphical app as root inside Chandra, use
`chandra-root gparted`. Details, including polkit agents (`CHANDRA_POLKIT_AGENT`), are in
[docs/run0.md](docs/run0.md).
Face unlock, in the style of Howdy, comes with `just install`: then Settings > Session > Face unlock to
add a face and use it for the password dialog and sudo (a PAM module; the password always still
works). See [docs/face-unlock.md](docs/face-unlock.md), including what 2D face recognition can't
protect against.
## What works
**Windows**
* Wayland clients (xdg-shell, wl_shm buffers, clipboard), tiling or floating (the Tile | Float
panel toggle).
* Drag a window by its title bar, resize floating windows from corners and edges, double-click
the title bar to maximize or restore. Clicking a window raises it.
* App right-click menus (xdg_popup) stay open and on screen; apps that draw with Vulkan on wl_shm
(Zed, Delta) show every frame; buffers stay valid after their pool is destroyed.
* The mouse wheel scrolls windows.
* Window positions are remembered per app, and on login the session reopens the windows the last
one ended with (switch it off in Settings, or start with `--no-restore`).
**Shortcuts** (the defaults; rebind any of them in Settings > Shortcuts: click one and press the
new keys)
| Keys | Action |
|---|---|
| Super (tap) | Open the application launcher, with an overview of every window beside it (typing filters both) |
| Super+W | Overview alone: every window side by side; click one to bring it forward, middle-click to close it |
| Alt+Tab | Window switcher, with a live preview of each window |
| Super+D | Show the desktop (minimize every window); again to bring them back |
| Super+1 .. Super+9 | Open the dock's first nine apps (or bring their windows forward) |
| Super+Shift+S | Screenshot: select a region or click a window (F full screen, W active window) |
| Print / Super+Print / Super+Ctrl+Print | Screenshot of the full screen / active window / window under the pointer |
| Super+Shift+R | Record a region or window (Enter starts) |
| Super+Alt+R / Super+Ctrl+R | Record the whole screen / the window under the pointer |
Every screenshot opens in the screenshot editor first: annotate it (arrow, line, rectangle,
ellipse, pen, highlighter, text, numbered markers), hide parts of it (blur, pixelate, redact) or
crop it, then Enter saves and copies it, Ctrl+C only copies it and Esc discards it. See
[docs/screenshot-editor.md](docs/screenshot-editor.md).
Screenshots go to `~/Pictures/Screenshots/` and the clipboard; recordings (H.264 MP4, via
`ffmpeg`) go to `~/Videos/Screencasts/`. A red REC pill shows while recording; click it or press
a recording shortcut again to stop.
**Panel modules** (each one a separate `.wasm` component in `components/`)
* **Launcher** (application menu with search). Its menu ends in a session row: **Reload**
(reload every panel module from disk, keeping the panel and module settings; windows and apps
keep running), **Log out**, **Suspend**, **Restart** and **Power off**. Log out, Restart and
Power off ask for a second click.
* **Dock**, the panel's task manager: the pinned apps that aren't running as plain icons, then
after a divider every running app (pinned ones in pin order first), with their theme icons and
a dot per open window (lit when the app has focus). An app with windows is a pill with its window's title (or its name and window count) while there is room,
just its icon when the panel gets crowded. Click to start an app or bring its newest window
forward (restoring it if minimized); click a focused app again to step through its windows.
**Super+1** .. **Super+9** do the same for the first nine. Right-click an app for Open / New
window, Pin or Unpin, Move left / right, its window's Minimize and Maximize (or a list of its
windows), Quit, and Dock settings (icon size, magnification, running apps, window titles).
Pin apps from there or by right-clicking them in the Launcher's menu; an empty dock shows a "+"
that opens it. Pins live in state.edn. (It replaced the separate Task Manager: a saved panel
with the old `tasks` module gets the dock in its place.)
* **Network**: Wi-Fi and wired status, connect to Wi-Fi networks (with passwords), Wi-Fi and
airplane switches, through NetworkManager over D-Bus (read-only sysfs status without it).
* **Battery**: charge, charging state, time left, low-battery warning (only added on machines
with a battery).
* **Clocks**: the Digital Clock (12-hour with AM/PM by default, 24-hour in its Module settings)
and a binary clock.
* **Screenshot**, **Layout** (Tile | Float), **Inspector** (interface explorer).
* **Settings**: tabs for Session (reopen windows at login, remember window positions, dark
mode), Desktop (what fills the desktop, wallpapers), Panel (add, remove and replace modules), Power (screen off and
suspend when idle, battery, suspend / restart / power off), Shortcuts and Apps (the default web
browser, email, file manager, terminal, text editor, image viewer, video and music player, PDF
viewer and archive manager, chosen from the installed apps; written to
`~/.config/mimeapps.list`, so xdg-open and other apps follow it). Dark mode also sets the system
preference for apps: GTK, Qt and KDE settings, and in the login session Chandra serves
xdg-desktop-portal's Settings color-scheme itself, so Chrome, Firefox and Electron apps follow
the switch live (see [docs/dark-mode.md](docs/dark-mode.md)).
**Desktop modules**: a module can fill the desktop itself, behind the windows, instead of sitting
in the panel. Choose one in Settings > Desktop (*Wallpaper only*, *Clock card*, or any installed
desktop module); right-click the empty desktop for its settings. Three ship: **Icon Desktop** (app
icons you click to launch and drag to arrange, positions remembered), **Live Starfield** (an
animated starfield you steer with the pointer) and **Gamerig Library** (gamerig's game library
for a streaming rig, [docs/gamerig-library.md](docs/gamerig-library.md)). See
[docs/desktop-modules.md](docs/desktop-modules.md) to write one.
Right-click any module for **Module settings** (its own options, such as the clock's format,
saved in `state.edn`), **System settings**, Replace with and Remove widget. Right-clicking empty
panel space opens System settings on the Panel tab.
**Performance**: an idle desktop sleeps instead of redrawing (about 0.35 % CPU, down from about
9 %), only changed parts of the screen are redrawn, and screenshots, recording and `--gfx-out`
keep pixels on the host rather than copying them through the component.
## Configuration and state
* `~/.config/chandra/panel.edn`: the panel's modules, in order.
* `~/.config/chandra/state.edn`: layout mode, recent apps, window positions, the windows to
reopen, wallpaper, theme, power timeouts, the terminal terminal apps run in (`:terminal`, also
put first in `~/.config/xdg-terminals.list`), per-module settings (`:module-config`), what fills the desktop (`:desktop`), and the
Settings switches (`:restore-session false`, `:remember-windows false`, `:theme :light`).
* Themes: `config/themes/moon-night.json` (default) and `moon-day.json`.
## Known gaps
* 5 to 6 compositor tests fail on main in a cloud container and are not regressions
(`input_test`, plus `screenshot_test` when the screenshot module isn't built). Build the panel
modules first and run with `CHANDRA_TEST_CONFIG=1`, or more tests fail.
* The DRM/KMS login session and real-hardware paths (power actions, battery, NetworkManager on a
real machine) are not exercised by CI; they have been built and unit-tested, not run on
hardware in automation.
* Not done yet: lock screen, notifications daemon, system tray, virtual desktops, multi-monitor
configuration, idle-inhibit (a playing video doesn't keep the screen on), lid and power-button
actions (logind's defaults apply), VPN and enterprise Wi-Fi.
* Desktop Pulse (`compositor/wasm/testdata/pulse.component.wasm`) and the `moon-disc` panel
module have no source in the tree, so `scripts/build-modules.sh` skips moon-disc and a fresh
panel shows a "Module 'moon-disc' not found" notice (remove it in Settings, Panel tab).
## Layout
```
wit/ WIT packages: chandra:desktop (components) and chandra:host (wit/host, what hosts serve)
compositor/ the compositor in MoonBit: wayland/, shell/, scene/, raster/, kms/, network/, portal/, host/, ...
components/<n>/ one wasm component each: compositor, shell, panel modules (gen/ bindings + thin stub.mbt)
lib/ pure, unit-tested logic (panel layout, clock, launcher, battery, task pills, ...)
wasmhost/ the host (MoonBit + wasmtime C API)
host/ the original M0 browser/Node host (jco), kept for the component demos
session/ chandra-session, chandra-root, chandra-ctl, chandra.desktop, chandra.portal, install.py
config/ desktop configs, themes, app list
scripts/ setup-toolchain, build-*, gen-bindings, as-root, remote-build, test
docs/ ARCHITECTURE, compositor-design, TOOLCHAIN, run0, dark-mode, reloading, screenshots
```
## License
Apache-2.0 (see LICENSE).