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

+96 -3
View File
@@ -644,6 +644,37 @@ pub fn ChandraCompositor::has_timed_work(self : ChandraCompositor) -> Bool {
self.shell.animating()
}
///| How long an idle main loop may sleep: `idle_ms` (until the wall clock's next second), or
/// less when a desktop module's next animation frame is due sooner.
pub fn ChandraCompositor::wake_timeout(self : ChandraCompositor, idle_ms : Int) -> Int {
let d = self.shell.desktop_wake_ms(@sys.monotonic_ms())
if d >= 0 && d < idle_ms {
d
} else {
idle_ms
}
}
///| True when a window covers the whole work area (or the output), give or take the tiling gaps:
/// the desktop can't be seen.
fn ChandraCompositor::desktop_covered(self : ChandraCompositor) -> Bool {
let m = 16
let wa = self.work_area
let wa : @wm.Rect = { x: wa.x + m, y: wa.y + m, w: wa.w - 2 * m, h: wa.h - 2 * m }
for wid in self.wm.stacking_order() {
match self.windows.get(wid) {
Some(win) => {
let g = win.geometry
if g.x <= wa.x && g.y <= wa.y && g.x + g.w >= wa.x + wa.w && g.y + g.h >= wa.y + wa.h {
return true
}
}
None => ()
}
}
false
}
///|
pub fn ChandraCompositor::set_layout_mode(
self : ChandraCompositor,
@@ -769,6 +800,9 @@ fn ChandraCompositor::build_scene(
self.shell.win_list = entries
self.shell.screenshot_state = (if self.rec is Some(_) { 1 } else { 0 }) |
(if self.rec_pointer { 2 } else { 0 })
// A window over the whole desktop (maximized, fullscreen, monocle) pauses a desktop module's
// animation: nobody can see it.
self.shell.set_desktop_covered(self.desktop_covered())
let t0 = @sys.monotonic_ms()
let (bg_ops, shell_ops) = self.shell.render(self.output_w, self.output_h, self.theme)
// The overview goes under the panel and the launcher.
@@ -1030,6 +1064,7 @@ fn ChandraCompositor::set_kbd_focus(self : ChandraCompositor, wid : UInt64?) ->
self.kbd_win = wid
match wid {
Some(w) => {
self.shell.desktop_unfocus() // a window has the keyboard now, not the desktop
self.server.keyboard_enter(w)
self.server.keyboard_modifiers(w, self.mods, 0U, 0U, 0U)
}
@@ -1330,6 +1365,12 @@ fn key_name(code : UInt, shift : Bool) -> String {
28U => "Enter"
57U => " "
12U => "-"
13U => if shift { "+" } else { "=" }
15U => "Tab"
103U => "ArrowUp"
108U => "ArrowDown"
105U => "ArrowLeft"
106U => "ArrowRight"
52U => "."
53U => "/"
_ => ""
@@ -1411,8 +1452,16 @@ pub fn ChandraCompositor::handle_input(
}
return
}
if self.shell.desktop_grabbing() {
// A press on the desktop is held (an icon being dragged): the desktop module follows the
// pointer wherever it goes until the release.
self.leave_pointer()
ignore(self.shell.desktop_pointer_move(xi, yi))
return
}
if self.shell.pointer_move(xi, yi) || self.shell.hit(xi, yi) {
self.leave_pointer()
self.shell.desktop_leave()
return
}
match self.split_drag {
@@ -1424,10 +1473,12 @@ pub fn ChandraCompositor::handle_input(
}
if self.handle_at(xi, yi) is Some(_) || self.resize_at(xi, yi) is Some(_) {
self.leave_pointer()
self.shell.desktop_leave()
return
}
match self.window_at(xi, yi) {
Some((wid, true)) =>
Some((wid, true)) => {
self.shell.desktop_leave()
match self.windows.get(wid) {
Some(win) => {
let lx = x - win.geometry.x.to_double()
@@ -1441,7 +1492,16 @@ pub fn ChandraCompositor::handle_input(
}
None => ()
}
_ => self.leave_pointer()
}
Some((_, false)) => {
self.leave_pointer()
self.shell.desktop_leave()
}
None => {
// The empty desktop: a desktop module sees the pointer here.
self.leave_pointer()
ignore(self.shell.desktop_pointer_move(xi, yi))
}
}
}
Scroll(axis, v, discrete) => {
@@ -1488,7 +1548,15 @@ pub fn ChandraCompositor::handle_input(
}
None => ()
}
_ => ()
Some((_, false)) => ()
None =>
if !self.shell.hit(xi, yi) {
// The empty desktop: a desktop module gets the wheel (in pixels; a notch is ~10).
let d = if v != 0.0 { v.to_int() } else { discrete * 10 }
ignore(
self.shell.desktop_scroll(xi, yi, if axis == 1U { d } else { 0 }, if axis == 0U { d } else { 0 }),
)
}
}
}
PointerButton(button, pressed) => {
@@ -1527,6 +1595,10 @@ pub fn ChandraCompositor::handle_input(
self.run_shell_actions()
return
}
if !pressed && self.shell.desktop_release(xi, yi) {
self.run_shell_actions()
return
}
if !pressed && self.split_drag is Some(_) {
self.split_drag = None
return
@@ -1549,6 +1621,11 @@ pub fn ChandraCompositor::handle_input(
if button == 273U && pressed && self.shell.right_click(xi, yi) {
return
}
// Right button on the empty desktop: the desktop menu (module settings, system settings).
if button == 273U && pressed && self.window_at(xi, yi) is None && !self.shell.hit(xi, yi) &&
self.shell.desktop_menu(xi, yi) {
return
}
if pressed {
self.super_solo = false
if button != 273U && self.shell.pointer_down(xi, yi) {
@@ -1593,6 +1670,13 @@ pub fn ChandraCompositor::handle_input(
self.leave_pointer()
return
}
// A left press on the empty desktop: a desktop module gets it, and the keyboard.
if button == 272U && self.window_at(xi, yi) is None && self.shell.desktop_press(xi, yi) {
self.leave_pointer()
self.set_kbd_focus(None)
self.run_shell_actions()
return
}
match self.window_at(xi, yi) {
Some((wid, _)) => {
self.activate_window(wid)
@@ -1642,6 +1726,15 @@ pub fn ChandraCompositor::handle_input(
self.shell.key_down(name)
}
}
} else if self.kbd_win is None && self.shell.desktop_has_focus() {
// The desktop has the keyboard (it was clicked): keys go to the desktop module.
self.super_solo = false
if pressed {
let name = key_name(code, (self.mods & 1U) != 0U)
if name.length() > 0 && self.shell.desktop_key(name) {
self.run_shell_actions()
}
}
} else {
self.super_solo = false
match self.kbd_win {