Desktop modules: a wasm module can fill the desktop, with Icon Desktop and Live Starfield
CI / test (push) Failing after 30s

A module that exports chandra:desktop/desktop-module (wit/desktop.wit) owns the desktop behind
the windows instead of a box in the panel: same sandbox, draw ops and capabilities, drawn at the
output's full size and re-rendered on resize. It gets pointer and scroll events only on the empty
desktop (windows, panel, popups and menus always win; a drag stays with the module until
release), keys only while the desktop has focus, and can draw over the wallpaper or replace it.
Its tick() asks for animation frames only while something moves; the main loop sleeps until the
next one (wake_timeout), and frames pause while a window covers the desktop, so an idle desktop
module costs nothing.

Settings > Desktop gets "On the desktop": Wallpaper only, Clock card (default) or any installed
desktop module, saved in state.edn as :desktop, loaded at login and reloaded by chandra-ctl
reload. Right-click the empty desktop for Module settings and System settings. Hidden settings
(empty label) are persisted by the shell, which is how Icon Desktop keeps icon positions.

Samples: Icon Desktop (click to launch, drag to arrange, keyboard navigation, count and size
settings) and Live Starfield (pointer steers, click or Space warps, wheel sets speed). Served by
all hosts: compositor/wasm (native + MoonBit wasmhost) and Rust host-wasm. Docs in
docs/desktop-modules.md; tests in compositor/host/desktop_test.mbt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgf1SwPMHVfLUbJKsB
This commit is contained in:
Claude committed 2026-11-26 00:30:32 +00:00
1 parent 30f5e88639
commit 0f71779819
79 files changed
+4591 -113

No files matched your search

+70 -16
View File
@@ -138,7 +138,7 @@ fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
let id = stem(f)
if !seen.contains(id) && !retired_modules.contains(id) {
seen.set(id, true)
self.catalog.push({ id, path: dir + "/" + f, name: "" })
self.catalog.push({ id, path: dir + "/" + f, name: "", desktop: false })
}
}
}
@@ -156,6 +156,7 @@ fn DesktopShell::name_catalog(self : DesktopShell) -> Unit {
match @wasm.load(e.path, self.tokens) {
Ok(pl) => {
e.name = pl.name
e.desktop = pl.desktop_backdrop() >= 0
pl.unload()
keep.push(e)
}
@@ -316,6 +317,7 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
Some(old) if old != entries => write_panel_file(entries)
_ => ()
}
self.boot_desktop()
for e in entries {
let path = if e.has_prefix("/") {
e
@@ -350,6 +352,11 @@ pub fn DesktopShell::load_path(self : DesktopShell, path : String) -> Widget? {
fn DesktopShell::try_load_path(self : DesktopShell, path : String) -> Result[Widget, String] {
match @wasm.load(path, self.tokens) {
Err(e) => Err("Can't load module: " + e)
Ok(pl) if pl.desktop_backdrop() >= 0 => {
// It fills the desktop, not a panel slot: Settings > Desktop puts it there.
pl.unload()
Err(pl.name + " is a desktop module: choose it in Settings > Desktop")
}
Ok(pl) => {
let id = stem(path)
let known = match self.find_module(id) {
@@ -510,6 +517,12 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
targets.push((w.slot, w.module_id, w.path))
}
}
// The desktop module too (slot "desktop").
match self.desk_mod {
Some(d) if name == "" || d.module_id == name || stem(d.path) == name || name == desktop_slot || d.path == name =>
targets.push((d.slot, d.module_id, d.path))
_ => ()
}
if targets.length() == 0 {
let msg = if name == "" {
"no modules are loaded"
@@ -523,7 +536,8 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
let mut last_err = ""
for t in targets {
let (slot, id, path) = t
match self.replace_slot_result(slot, path) {
let res = if slot == desktop_slot { self.reload_desktop() } else { self.replace_slot_result(slot, path) }
match res {
Ok(nw) => lines.push("reloaded " + nw.slot + " " + id)
Err(e) => {
failed = failed + 1
@@ -551,7 +565,12 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
///| The loaded modules in panel order: (slot, module id, path).
pub fn DesktopShell::loaded_modules(self : DesktopShell) -> Array[(String, String, String)] {
self.ensure_booted()
self.widgets.map(w => (w.slot, w.module_id, w.path))
let out = self.widgets.map(w => (w.slot, w.module_id, w.path))
match self.desk_mod {
Some(d) => out.push((d.slot, d.module_id, d.path)) // the desktop module, last
None => ()
}
out
}
///| Unload every module (the compositor is closing).
@@ -560,6 +579,7 @@ pub fn DesktopShell::shutdown(self : DesktopShell) -> Unit {
w.pl.unload()
}
self.widgets.clear()
self.unload_desktop()
}
///| Slot ids of the loaded modules, in panel order.
@@ -652,7 +672,7 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
}
@wasm.publish(Layouts, lt)
@wasm.publish_state(self.layout_sel, self.inspect_on)
if self.widgets.iter().any(w => w.has_cap("wallpaper")) {
if self.any_cap("wallpaper") {
let pt = @wasm.Table::new()
for n in @libshell.wallpaper_names {
pt.str(n)
@@ -660,8 +680,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
}
@wasm.publish(Wallpapers, pt)
@wasm.publish_wallpaper(self.wallpaper_sel)
self.publish_desktops()
}
if self.widgets.iter().any(w => w.has_cap("session-settings")) {
if self.any_cap("session-settings") {
let st = @wasm.Table::new()
for n in session_setting_names {
st.str(n)
@@ -670,19 +691,19 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
@wasm.publish(SessionSettings, st)
@wasm.publish_session_settings(self.session_settings_bits())
}
if self.widgets.iter().any(w => w.has_cap("power")) {
if self.any_cap("power") {
@wasm.publish_power(self.screen_off_min, self.suspend_min)
}
if self.widgets.iter().any(w => w.has_cap("shortcuts")) {
if self.any_cap("shortcuts") {
self.publish_shortcuts()
}
if self.widgets.iter().any(w => w.has_cap("default-apps")) {
if self.any_cap("default-apps") {
self.publish_default_apps()
}
if self.widgets.iter().any(w => w.has_cap("screenshot")) {
if self.any_cap("screenshot") {
@wasm.publish_screenshot(self.screenshot_state)
}
if self.widgets.iter().any(w => w.has_cap("battery")) {
if self.any_cap("battery") {
let b = self.battery.refresh()
@wasm.publish_battery(b.percent, b.state, b.secs_left)
}
@@ -705,6 +726,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
self.name_catalog()
let mt = @wasm.Table::new()
for e in self.catalog {
if e.desktop {
continue // chosen in Settings > Desktop, not added to the panel
}
let mut n = 0
for w in self.widgets {
if w.path == e.path {
@@ -810,6 +834,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
self.actions.push(ModulesReloaded)
}
Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetDesktop(i)) => self.set_desktop_index(i)
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
Some(Screenshot(code)) => self.actions.push(Screenshot(code))
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
@@ -900,7 +925,7 @@ fn DesktopShell::poll_picker(self : DesktopShell) -> Unit {
pub(all) enum SettingsTab {
/// The session switches.
Session
/// What is on the desktop: the wallpaper (modules can't be placed on the desktop yet).
/// What is on the desktop: the wallpaper, the clock card or a desktop module.
Desktop
/// The panel's modules: remove, add, browse.
Panel
@@ -1065,7 +1090,7 @@ fn DesktopShell::open_module_settings(self : DesktopShell, slot : String) -> Uni
if rows.length() == 0 {
rows.push(menu_row("No module settings", 5))
}
self.open_menu(w.pl.name + " settings", rows, slot, self.menu_anchor_x)
self.open_menu(w.pl.name + " settings", rows, slot, self.menu_anchor_x, y=self.menu_anchor_y)
}
}
}
@@ -1081,6 +1106,13 @@ pub fn DesktopShell::set_module_setting(self : DesktopShell, slot : String, key
ignore(o.pl.set_config(key, value))
}
}
match self.desk_mod {
Some(d) if d.module_id == w.module_id => {
ignore(d.pl.set_config(key, value))
self.desktop_changed(true)
}
_ => ()
}
}
}
}
@@ -1110,7 +1142,15 @@ fn DesktopShell::choose_module_setting(self : DesktopShell, slot : String, key :
}
///|
fn DesktopShell::open_menu(self : DesktopShell, title : String, rows : Array[MenuRow], slot : String, x : Int) -> Unit {
fn DesktopShell::open_menu(
self : DesktopShell,
title : String,
rows : Array[MenuRow],
slot : String,
x : Int,
y? : Int = -1,
) -> Unit {
self.menu_anchor_y = y
self.menu_open = true
self.menu_title = title
self.menu_rows = rows
@@ -1143,7 +1183,16 @@ fn DesktopShell::menu_pointer_down(self : DesktopShell, x : Int, y : Int) -> Boo
match row.kind {
0 => ignore(self.replace_slot(slot, row.arg))
1 => ignore(self.unload_slot(slot))
2 => ignore(self.open_settings(if row.arg == "panel" { Panel } else { Session }))
2 =>
ignore(
self.open_settings(
match row.arg {
"panel" => Panel
"desktop" => Desktop
_ => Session
},
),
)
3 => self.open_module_settings(slot)
4 => self.choose_module_setting(slot, row.arg, row.value)
6 => self.actions.push(Window(row.window_id, row.window_cmd))
@@ -1170,8 +1219,13 @@ fn DesktopShell::render_menu(
) -> Unit {
let n = self.menu_rows.length()
let mh = menu_title_h + n * menu_item_h + 6
let mx = clamp_menu(self.menu_anchor_x - menu_w / 2, 4, w - menu_w - 4)
let my = self.panel_rect.y - mh - 6
// Above the panel, centred on the click; or (the desktop menu) at the pointer.
let (mx, my) = if self.menu_anchor_y >= 0 {
let bottom = if self.panel_rect.h > 0 { self.panel_rect.y } else { self.screen_h }
(clamp_menu(self.menu_anchor_x, 4, w - menu_w - 4), clamp_menu(self.menu_anchor_y, 4, bottom - mh - 4))
} else {
(clamp_menu(self.menu_anchor_x - menu_w / 2, 4, w - menu_w - 4), self.panel_rect.y - mh - 6)
}
self.menu_rect = { x: mx, y: my, w: menu_w, h: mh }
let fs = tokens.font_size.reinterpret_as_int()
let r = tokens.radius.reinterpret_as_int()