The MoonBit host (wasmhost/, build/wasmhost) is the only host now. Gone: host-wasm/ (Rust on the wasmtime crate, ~5,700 lines incl. Cargo.lock), the run-rust, run-drm-rust and host-wasm recipes, and `just install --rust` (both the recipe and session/install.py now stop with an error naming the removal instead of quietly ignoring the flag). remote-build.sh builds and pulls build/wasmhost. README, wasmhost/README and docs no longer describe a second host, apart from short history notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hiBxpbLoeUM9xfZayq
6.7 KiB
Desktop modules
A desktop module is a wasm module that fills the desktop: the whole output behind the windows, instead of a box in the panel. Use it for interactive desktops (an icon launcher, a live wallpaper, a game, a dashboard). It runs in the same sandbox as a panel module, draws with the same draw ops and asks for the same capabilities; only the way the shell drives it differs.
Three ship with Chandra:
-
Icon Desktop (
components/icon-desktop, logic inlib/icondesk): a grid of app icons on the wallpaper. Click to launch, drag to move (dropping on another icon swaps them), arrow keys and Enter after clicking the desktop, typing a letter jumps to the next app starting with it. Positions are kept across logins. Module settings: how many apps (8, 12, 24, all) and icon size. -
Live Starfield (
components/starfield, logic inlib/starfield): an animated starfield that replaces the wallpaper. The pointer steers it, a click or Space sends a warp pulse, the wheel changes speed. Module settings: speed, density, and Moving or Still (Still draws one frame and then costs nothing). -
Gamerig Library (
components/gamerig-library, logic inlib/gamelib): gamerig's game library (categories, search, cards with Launch / Big Picture / Stop, running apps, rig status), fed by gamerig's library daemon through thegame-librarycapability. See gamerig-library.md.
Choosing what fills the desktop
Settings > Desktop starts with On the desktop: Wallpaper only, Clock card (the default,
as before) and every installed desktop module. The choice takes effect at once, is saved in
~/.config/chandra/state.edn as :desktop ("wallpaper", "clock-card" or the module's id)
and is loaded again at login. A module that is missing or fails to load leaves the clock card,
and the saved choice is kept for when it comes back.
Right-click the empty desktop for Module settings... (the module's own options) and System settings... (Settings on the Desktop tab). A desktop module can't be added to the panel: Settings > Panel doesn't list it, and adding one by path is refused with a notice.
Writing one
A desktop module is a plasmoid (wit/plasmoid.wit) that also exports desktop-module
(wit/desktop.wit):
interface desktop-module {
enum wallpaper-mode { over-wallpaper, replace-wallpaper }
backdrop: func() -> wallpaper-mode;
on-scroll: func(at: point, dx: s32, dy: s32) -> bool;
tick: func(now-ms: u32) -> u32;
}
The smallest world is desktop-widget in wit/worlds.wit (include widget; export desktop-module;). Add imports and module-config as a panel module would; the samples use
icon-desktop-widget (app catalog, app launch, icons, module config) and starfield-widget.
Add a line to scripts/components.txt and scripts/build-modules.sh builds it into
build/components/NAME.wasm; just install copies it to /usr/local/share/chandra/modules/,
the same place as panel modules. The shell tells desktop modules apart by the export.
How the shell drives it:
- Drawing.
plasmoid.rendergets the output's full size, in desktop coordinates ((0, 0) is the output's top-left corner), and is called again with the new size when the output is resized. The wallpaper is drawn first unlessbackdropreturnsreplace-wallpaper; windows and the panel are drawn on top. The ops are cached: the shell callsrenderagain only when the module asked for a redraw, the size changed or the theme changed.plasmoid.info's size fields andplasmoid.popupare not used. - Pointer.
plasmoid.on-eventgets move, press, release and leave only where nothing else is: no window, panel, popup, menu or switcher covers that point. Moving onto a window or the panel sends a leave. A press on the desktop keeps the pointer (a drag stays with the module until release, even over a window). Right-click never reaches the module: it opens the desktop menu.on-scrollgets the wheel over the empty desktop (one notch is about 10 pixels). - Keys. Only while the desktop has the keyboard: after a click on the empty desktop, until a
window is focused (the module then gets
focus-lost). Shortcuts are handled first, and a focused window always gets its own keys. - Animation.
tick(now-ms)is the clock (now-mscounts from when the module was loaded). It is called once after loading, after every event, and again when the delay it last returned has passed. Return the ms until the next frame (16 for about 60 fps, 33 for 30) or 0 to sleep until the next event. Each timed tick is followed by a redraw. The compositor's main loop sleeps until the next frame is due, so a module that returns 0 costs no CPU while idle, and frames are paused while a window covers the whole desktop. Requests are capped at 10 s. - Saved state.
module-configitems with an empty label are hidden settings: the shell doesn't show them, but saves them in state.edn (:module-config, under the module's id) when their value changes after a release or a key, and hands them back withset-configat the next load. Icon Desktop keeps its icon positions this way (places,id=col,row;...).
Logic is easiest to test outside the component: the samples keep it in lib/ and test it with
moon test --target wasm -p chandra/desktop/lib/starfield (or lib/icondesk).
Reloading
chandra-ctl reload (or just reload, Applications > Reload, SIGUSR1) reloads the desktop
module along with the panel modules; chandra-ctl reload desktop or chandra-ctl reload starfield reloads only it. Settings and hidden state are handed back as at login. A broken file
is reported and the running instance stays (see reloading.md).
Hosts
Both module hosts serve desktop modules: the native compositor and the MoonBit
build/wasmhost, both through compositor/wasm/wasm_stub.c. The compositor-as-wasm reaches them
through desktop-backdrop, desktop-scroll, desktop-tick and publish-desktop in
wit/host/plasmoids.wit. The settings module reads the list through the wallpaper
capability's desktops, current-desktop and set-desktop (wit/capabilities.wit).
Tests
compositor/host/desktop_test.mbt: choosing and listing, input routing (windows and the panel
win, drags stay with the module), the right-click menu, resize, idle and animation pacing,
reload, and screenshots (_build/desktop_*.png). Run with:
XDG_CONFIG_HOME=$(mktemp -d) CHANDRA_TEST_CONFIG=1 \
moon test --target native --warn-list -a -p chandra/desktop/compositor/host --filter "*desktop*"
Also checked headless on build/wasmhost (--gfx-out) with :desktop set in
state.edn.

