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

+31
View File
@@ -246,6 +246,26 @@ pub fn Plasmoid::set_config(self : Plasmoid, key : String, value : String) -> Bo
@hostpl.set_config(self.handle.reinterpret_as_uint(), key, value)
}
///| A desktop module's backdrop: 0 over the wallpaper, 1 replacing it, -1 for a panel module.
pub fn Plasmoid::desktop_backdrop(self : Plasmoid) -> Int {
@hostpl.desktop_backdrop(self.handle.reinterpret_as_uint())
}
///| Scroll over a desktop module at (x, y) by (dx, dy) pixels. True when it wants a redraw.
pub fn Plasmoid::desktop_scroll(self : Plasmoid, x : Int, y : Int, dx : Int, dy : Int) -> Bool {
@hostpl.desktop_scroll(self.handle.reinterpret_as_uint(), x, y, dx, dy)
}
///| A desktop module's animation clock: ms until it wants the next frame, 0 for none.
pub fn Plasmoid::desktop_tick(self : Plasmoid, now_ms : Int) -> Int {
let r = @hostpl.desktop_tick(self.handle.reinterpret_as_uint(), now_ms.reinterpret_as_uint()).reinterpret_as_int()
if r < 0 {
0
} else {
r
}
}
///|
pub fn Plasmoid::imports(self : Plasmoid) -> Array[String] {
self.imports
@@ -309,6 +329,8 @@ pub(all) enum HostTable {
AppCategories
/// Default-app choices (issii: category id name icon current).
AppChoices
/// What can fill the desktop (s: name), served by `wallpaper.desktops`.
Desktops
}
///|
@@ -336,6 +358,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Shortcuts => 10U
AppCategories => 11U
AppChoices => 12U
Desktops => 20U
}
// Most tables are republished every frame unchanged: skip the copy into the host then.
let slot = id.reinterpret_as_int()
@@ -363,6 +386,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
@hostpl.publish_wallpaper(current)
}
///| What fills the desktop now (an index into the Desktops table).
pub fn publish_desktop(current : Int) -> Unit {
@hostpl.publish_desktop(current)
}
///| Which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
@hostpl.publish_session_settings(on.reinterpret_as_uint())
@@ -416,6 +444,8 @@ pub(all) enum HostRequest {
DefaultApp(Int)
/// The session capability's `reload`: reload every loaded panel module from disk.
ReloadSession
/// The wallpaper capability's `set-desktop`: an index into the Desktops table.
SetDesktop(Int)
} derive(Eq, Debug)
///|
@@ -441,6 +471,7 @@ pub fn next_request() -> HostRequest? {
Some(Shortcut(code)) => Some(Shortcut(code))
Some(DefaultApp(code)) => Some(DefaultApp(code))
Some(ReloadSession) => Some(ReloadSession)
Some(SetDesktop(i)) => Some(SetDesktop(i))
}
}
+47
View File
@@ -152,6 +152,15 @@ let ex_post_cfg_items : Int = 9
///|
let ex_set_cfg : Int = 10
///| The optional `desktop-module` exports (wit/desktop.wit): absent in panel modules.
let ex_desk_backdrop : Int = 11
///|
let ex_desk_scroll : Int = 12
///|
let ex_desk_tick : Int = 13
///| The 64-byte `theme.tokens` record (name left empty) the guest reads through get-tokens.
pub fn pack_tokens(t : @theme.Tokens) -> Bytes {
let b = FixedArray::make(64, b'\x00')
@@ -625,6 +634,33 @@ pub fn Plasmoid::set_config(self : Plasmoid, key : String, value : String) -> Bo
}
}
///| A desktop module's backdrop (`desktop-module.backdrop`): 0 drawn over the wallpaper, 1
/// replacing it; -1 when the module doesn't export `desktop-module` (a panel module).
pub fn Plasmoid::desktop_backdrop(self : Plasmoid) -> Int {
let r = c_wasm_call(self.handle, ex_desk_backdrop, 0, 0, 0, 0)
if r == 0 || r == 1 {
r
} else {
-1
}
}
///| Scroll over a desktop module at (x, y) by (dx, dy) pixels. True when it wants a redraw.
pub fn Plasmoid::desktop_scroll(self : Plasmoid, x : Int, y : Int, dx : Int, dy : Int) -> Bool {
c_wasm_call(self.handle, ex_desk_scroll, x, y, dx, dy) == 1
}
///| A desktop module's animation clock (`now_ms` since it was loaded): the ms until it wants the
/// next frame, 0 for none (also when it trapped or has no `desktop-module`).
pub fn Plasmoid::desktop_tick(self : Plasmoid, now_ms : Int) -> Int {
let r = c_wasm_call(self.handle, ex_desk_tick, now_ms, 0, 0, 0)
if r < 0 {
0
} else {
r
}
}
///| Host interfaces (capabilities) the module's binary imports, e.g. ["theme", "clock"].
pub fn Plasmoid::imports(self : Plasmoid) -> Array[String] {
let buf = Bytes::make(512, b'\x00')
@@ -701,6 +737,8 @@ pub(all) enum HostTable {
AppCategories
/// Default-app choices (issii: category id name icon current).
AppChoices
/// What can fill the desktop (s: name), served by `wallpaper.desktops`.
Desktops
}
///| Publish `t` as the data behind `which` for every module's next call.
@@ -719,6 +757,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Shortcuts => 10
AppCategories => 11
AppChoices => 12
Desktops => 20
}
let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 {
@@ -741,6 +780,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
c_host_set_int(2, current)
}
///| Publish what fills the desktop now (an index into the Desktops table).
pub fn publish_desktop(current : Int) -> Unit {
c_host_set_int(20, current)
}
///| Publish which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
c_host_set_int(3, on)
@@ -798,6 +842,8 @@ pub(all) enum HostRequest {
DefaultApp(Int)
/// The session capability's `reload`: reload every loaded panel module from disk.
ReloadSession
/// The wallpaper capability's `set-desktop`: an index into the Desktops table.
SetDesktop(Int)
} derive(Eq, Debug)
///|
@@ -839,6 +885,7 @@ pub fn next_request() -> HostRequest? {
}
18 => Some(Shortcut(c_host_req_int()))
19 => Some(DefaultApp(c_host_req_int()))
40 => Some(SetDesktop(c_host_req_int()))
_ => None
}
}
+20 -5
View File
@@ -17,7 +17,7 @@
#define MAX_INST 2048
enum { EX_INFO, EX_RENDER, EX_ONEVENT, EX_POPUP, EX_POST_INFO, EX_POST_RENDER, EX_POST_POPUP, EX_REALLOC,
EX_CFG_ITEMS, EX_POST_CFG_ITEMS, EX_SET_CFG, EX_N };
EX_CFG_ITEMS, EX_POST_CFG_ITEMS, EX_SET_CFG, EX_DESK_BACKDROP, EX_DESK_SCROLL, EX_DESK_TICK, EX_N };
static const char *ex_names[EX_N] = {
"chandra:desktop/plasmoid@0.1.0#info",
"chandra:desktop/plasmoid@0.1.0#render",
@@ -31,6 +31,10 @@ static const char *ex_names[EX_N] = {
"chandra:desktop/module-config@0.1.0#config-items",
"cabi_post_chandra:desktop/module-config@0.1.0#config-items",
"chandra:desktop/module-config@0.1.0#set-config",
/* optional: chandra:desktop/desktop-module (a module that fills the desktop, wit/desktop.wit) */
"chandra:desktop/desktop-module@0.1.0#backdrop",
"chandra:desktop/desktop-module@0.1.0#on-scroll",
"chandra:desktop/desktop-module@0.1.0#tick",
};
typedef struct Inst {
@@ -61,17 +65,20 @@ enum {
K_NET_STATUS, K_NET_LIST, K_NET_SCAN, K_NET_CONNECT, K_NET_DISCONNECT, K_NET_FORGET, K_NET_SET_WIFI,
K_NET_SET_AIRPLANE,
K_SC_LIST, K_SC_CAPTURE, K_SC_CANCEL, K_SC_RESET, K_SC_RESET_ALL,
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH,
K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP
};
typedef struct Env { Inst *inst; int kind; } Env;
/* ---- host data the shell publishes before calling a guest ----
* A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS,
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES, T_N };
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES,
/* fixed numbers from here (wit/host/plasmoids.wit publish-table) */
T_DESKTOPS = 20, T_N = 32 };
typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N];
static int32_t host_ints[12] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
static int32_t host_ints[24] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
4 screenshot state (bit 0 recording, bit 1 pointer in recordings),
5 screen-off minutes, 6 suspend minutes (0: never),
7 battery percent (-1: none), 8 battery charge-state, 9 battery seconds left */
@@ -375,6 +382,11 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_LOGOUT: push_req(8, 0, NULL); break;
case K_RELOAD: push_req(8, 1, NULL); break; /* 8: session; n 0 log out, 1 reload */
case K_SET_WALLPAPER: push_req(9, a0, NULL); break;
case K_DESKTOPS: build_list(in, T_DESKTOPS, "s", a0); break;
case K_DESKTOP_CUR:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[20]);
break;
case K_SET_DESKTOP: push_req(40, a0, NULL); break;
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
/* Request 12 carries the screenshot code: 0-3 take, 10-12 record, 20 stop, 30/31 pointer. */
case K_SHOT_TAKE: if (a0 >= 0 && a0 <= 3) push_req(12, a0, NULL); break;
@@ -589,6 +601,9 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "desktops")) return K_DESKTOPS;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-desktop")) return K_DESKTOP_CUR;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-desktop")) return K_SET_DESKTOP;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;
@@ -882,7 +897,7 @@ void mp_host_set_table(int32_t which, moonbit_bytes_t data) {
MOONBIT_FFI_EXPORT
void mp_host_set_int(int32_t which, int32_t v) {
if (which >= 0 && which < 12) host_ints[which] = v;
if (which >= 0 && which < 24) host_ints[which] = v; /* 20: the desktop (wallpaper.current-desktop) */
}
/* Pop the next guest request: returns its kind (0 = none). Fetch its arguments with req_int / req_str. */