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

+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
}
}