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

+17
View File
@@ -193,6 +193,18 @@ impl chandra::host::plasmoids::Host for State {
self.pl().set_config(handle, &key, &value)
}
fn desktop_backdrop(&mut self, handle: u32) -> i32 {
self.pl().desktop_backdrop(handle)
}
fn desktop_scroll(&mut self, handle: u32, x: i32, y: i32, dx: i32, dy: i32) -> bool {
self.pl().desktop_scroll(handle, x, y, dx, dy)
}
fn desktop_tick(&mut self, handle: u32, now_ms: u32) -> u32 {
self.pl().desktop_tick(handle, now_ms)
}
fn publish_table(&mut self, which: u32, rows: Vec<u8>) {
if let Some(t) = self.pl().shared.borrow_mut().tables.get_mut(which as usize) {
*t = rows;
@@ -210,6 +222,10 @@ impl chandra::host::plasmoids::Host for State {
self.pl().shared.borrow_mut().wallpaper = current;
}
fn publish_desktop(&mut self, current: i32) {
self.pl().shared.borrow_mut().desktop = current;
}
fn publish_session_settings(&mut self, on: u32) {
self.pl().shared.borrow_mut().session_settings = on;
}
@@ -278,6 +294,7 @@ impl chandra::host::plasmoids::Host for State {
}
Req::Shortcut(code) => R::Shortcut(code),
Req::DefaultApp(code) => R::DefaultApp(code),
Req::SetDesktop(i) => R::SetDesktop(i),
})
}
+55 -2
View File
@@ -31,6 +31,14 @@ pub mod cfg {
});
}
pub use cfg::exports::chandra::desktop::module_config::ConfigItem;
/// The optional `desktop-module` export (wit/desktop.wit, world `desktop-export`): a module that
/// fills the desktop. Bound separately, like `module-config`.
pub mod desk {
wasmtime::component::bindgen!({
path: "../wit",
world: "desktop-export",
});
}
use ph::exports::chandra::desktop as ex;
use ph::chandra::desktop as d;
@@ -63,6 +71,8 @@ pub enum Req {
Shortcut(i32),
/// A default-apps request: category * 1000 + app sets a default, -1 scans again.
DefaultApp(i32),
/// `wallpaper.set-desktop`: an index into the desktops table.
SetDesktop(i32),
}
pub const T_APPS: usize = 0;
@@ -84,13 +94,17 @@ pub const T_SHORTCUTS: usize = 10;
pub const T_APP_CATS: usize = 11;
/// Default-app choices (issii): category id name icon current.
pub const T_APP_CHOICES: usize = 12;
/// What can fill the desktop (s): name, behind `wallpaper.desktops`.
pub const T_DESKTOPS: usize = 20;
/// Host data every module reads from, shared by all loaded modules.
#[derive(Default)]
pub struct Shared {
pub tables: [Vec<u8>; 13],
pub tables: [Vec<u8>; 21],
pub layout_mode: i32,
pub wallpaper: i32,
/// What fills the desktop (an index into the desktops table).
pub desktop: i32,
/// Which session settings are on: bit i for row i of the session settings table.
pub session_settings: u32,
/// Screenshot state: bit 0 a recording is running, bit 1 recordings show the pointer.
@@ -341,6 +355,15 @@ impl d::wallpaper::Host for PState {
fn set_wallpaper(&mut self, index: u32) {
self.shared.borrow_mut().requests.push_back(Req::SetWallpaper(index as i32));
}
fn desktops(&mut self) -> Vec<String> {
self.rows(T_DESKTOPS, "s").iter().map(|r| s(&r[0])).collect()
}
fn current_desktop(&mut self) -> u32 {
self.shared.borrow().desktop.max(0) as u32
}
fn set_desktop(&mut self, index: u32) {
self.shared.borrow_mut().requests.push_back(Req::SetDesktop(index as i32));
}
}
impl d::power::Host for PState {
@@ -585,6 +608,8 @@ struct Loaded {
inst: ph::PlasmoidHost,
/// Present when the module exports `module-config`.
cfg: Option<cfg::Configurable>,
/// Present when it exports `desktop-module` (a desktop module).
desk: Option<desk::DesktopExport>,
}
/// A file-chooser dialog in flight (zenity on the host session).
@@ -642,11 +667,12 @@ impl Runtime {
let inst = ph::PlasmoidHost::new(&mut store, &instance)
.map_err(|_| "no plasmoid (chandra:desktop/plasmoid) in this module".to_string())?;
let cfg = cfg::Configurable::new(&mut store, &instance).ok();
let desk = desk::DesktopExport::new(&mut store, &instance).ok();
let info = inst
.chandra_desktop_plasmoid()
.call_info(&mut store)
.map_err(|_| "widget trapped in info()".to_string())?;
let l = Loaded { store, inst, cfg };
let l = Loaded { store, inst, cfg, desk };
let handle = match self.slots.iter().position(|s| s.is_none()) {
Some(h) => {
self.slots[h] = Some(l);
@@ -695,6 +721,33 @@ impl Runtime {
c.chandra_desktop_module_config().call_set_config(&mut l.store, key, value).unwrap_or(false)
}
/// A desktop module's backdrop: 0 over the wallpaper, 1 replacing it; -1 for a panel module.
pub fn desktop_backdrop(&mut self, handle: u32) -> i32 {
use desk::exports::chandra::desktop::desktop_module::WallpaperMode;
let Some(l) = self.get(handle) else { return -1 };
let Some(dm) = &l.desk else { return -1 };
match dm.chandra_desktop_desktop_module().call_backdrop(&mut l.store) {
Ok(WallpaperMode::OverWallpaper) => 0,
Ok(WallpaperMode::ReplaceWallpaper) => 1,
Err(_) => -1,
}
}
/// Scroll over a desktop module; true when it wants a redraw.
pub fn desktop_scroll(&mut self, handle: u32, x: i32, y: i32, dx: i32, dy: i32) -> bool {
let Some(l) = self.get(handle) else { return false };
let Some(dm) = &l.desk else { return false };
let at = desk::chandra::desktop::types::Point { x, y };
dm.chandra_desktop_desktop_module().call_on_scroll(&mut l.store, at, dx, dy).unwrap_or(false)
}
/// A desktop module's animation clock: ms until its next frame, 0 for none (or a trap).
pub fn desktop_tick(&mut self, handle: u32, now_ms: u32) -> u32 {
let Some(l) = self.get(handle) else { return 0 };
let Some(dm) = &l.desk else { return 0 };
dm.chandra_desktop_desktop_module().call_tick(&mut l.store, now_ms).unwrap_or(0)
}
pub fn on_event(&mut self, handle: u32, on_popup: bool, ev: d::types::InputEvent) -> bool {
let Some(l) = self.get(handle) else { return false };
let target = if on_popup { ex::plasmoid::Surface::Popup } else { ex::plasmoid::Surface::Widget };