Files
chandra/docs/desktop-modules.md
T
nandiandClaude Opus 5.5 7ce5b79af2
CI / test (push) Successful in 1m12s
Deploy to the handset / build-and-deploy (push) Failing after 1m31s
Drop the screenshot tests and the moon-disc module; just test runs every lib package
- Tests that only wrote PNGs to look at are gone: desktop, overview (and its overview_shot
  helper), editor, emoji picker, launcher/Icon Desktop and dock screenshots. They were among
  the slowest in the suite; the behaviour they touched has its own tests.
- moon-disc never had source in the tree, so every fresh panel said "Module 'moon-disc' not
  found". It is out of the default panel, and a saved panel drops it (migrate_panel). The
  settings module's sample rows and labels no longer mention it.
- The settings module lists Show Desktop under "Apps and windows", with a description.
- just test ran lib/taskbar, lib/layoutpick and lib/modmgr, which no longer exist, so the wasm
  lib tests failed to start; it now runs every package in lib/ (83 tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:05:40 -08:00

6.6 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 in lib/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 in lib/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 in lib/gamelib): gamerig's game library (categories, search, cards with Launch / Big Picture / Stop, running apps, rig status), fed by gamerig's library daemon through the game-library capability. See gamerig-library.md.

Icon Desktop Live Starfield Gamerig Library

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.render gets 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 unless backdrop returns replace-wallpaper; windows and the panel are drawn on top. The ops are cached: the shell calls render again only when the module asked for a redraw, the size changed or the theme changed. plasmoid.info's size fields and plasmoid.popup are not used.
  • Pointer. plasmoid.on-event gets 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-scroll gets 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-ms counts 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-config items 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 with set-config at 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, and reload. Run with:

scripts/test-native.py -p compositor/host desktop

Also checked headless on build/wasmhost (--gfx-out) with :desktop set in state.edn.