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

+16 -7
View File
@@ -10,15 +10,13 @@ fn wasmImportCurrentWallpaper() -> Int = "chandra:desktop/wallpaper@0.1.0" "curr
fn wasmImportSetWallpaper(p0 : Int) = "chandra:desktop/wallpaper@0.1.0" "set-wallpaper"
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
fn wasmImportDesktops(p0 : Int) = "chandra:desktop/wallpaper@0.1.0" "desktops"
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
fn wasmImportCurrentDesktop() -> Int = "chandra:desktop/wallpaper@0.1.0" "current-desktop"
///|
fn wasmImportSetDesktop(p0 : Int) = "chandra:desktop/wallpaper@0.1.0" "set-desktop"
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
@@ -31,3 +29,14 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
@@ -35,4 +35,42 @@ pub fn set_wallpaper(index : UInt) -> Unit {
wasmImportSetWallpaper((index).reinterpret_as_int());
}
///|
/// What fills the desktop, as display names indexed by choice: 0 "Wallpaper only", 1 "Clock
/// card" (the built-in card), then every installed desktop module (docs/desktop-modules.md).
pub fn desktops() -> Array[String] {
let return_area = mbt_ffi_malloc(8)
wasmImportDesktops(return_area);
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
pub fn current_desktop() -> UInt {
let result : Int = wasmImportCurrentDesktop();
let ret = (result).reinterpret_as_uint()
return ret
}
///|
/// Put desktop `index` on the desktop (out-of-range indices are ignored). The choice is
/// remembered (state.edn `:desktop`).
pub fn set_desktop(index : UInt) -> Unit {
wasmImportSetDesktop((index).reinterpret_as_int());
}
+31 -19
View File
@@ -24,6 +24,15 @@ fn wasmImportConfigItems(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "
///|
fn wasmImportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "set-config"
///|
fn wasmImportDesktopBackdrop(p0 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "desktop-backdrop"
///|
fn wasmImportDesktopScroll(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "desktop-scroll"
///|
fn wasmImportDesktopTick(p0 : Int, p1 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "desktop-tick"
///|
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasmoids@0.1.0" "publish-table"
@@ -33,6 +42,9 @@ fn wasmImportPublishState(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0"
///|
fn wasmImportPublishWallpaper(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-wallpaper"
///|
fn wasmImportPublishDesktop(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-desktop"
///|
fn wasmImportPublishSessionSettings(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-session-settings"
@@ -67,22 +79,39 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
@@ -90,15 +119,6 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
@@ -110,11 +130,3 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
@@ -40,6 +40,21 @@ fn wasmImportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int
abort("wasm-only host import")
}
///|
fn wasmImportDesktopBackdrop(p0 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportDesktopScroll(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportDesktopTick(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
@@ -55,6 +70,11 @@ fn wasmImportPublishWallpaper(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishDesktop(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishSessionSettings(p0 : Int) -> Unit {
abort("wasm-only host import")
@@ -111,27 +131,7 @@ fn wasmImportPickerPoll(p0 : Int) -> Unit {
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_load64(offset : Int) -> Int64 {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
@@ -140,27 +140,47 @@ fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
abort("wasm-only")
}
///|
fn mbt_ffi_load8_u(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load64(offset : Int) -> Int64 {
abort("wasm-only")
}
///|
fn mbt_ffi_store8(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
@@ -9,6 +9,12 @@ import {
// Values
pub fn config_items(UInt32) -> Array[ConfigItem]
pub fn desktop_backdrop(UInt32) -> Int32
pub fn desktop_scroll(UInt32, Int32, Int32, Int32, Int32) -> Bool
pub fn desktop_tick(UInt32, UInt32) -> UInt32
pub fn list_wasm_files(String) -> Array[String]
pub fn load(String) -> Result[Loaded, String]
@@ -25,6 +31,8 @@ pub fn popup(UInt32) -> PopupSurface?
pub fn publish_battery(Int32, UInt32, UInt32) -> Unit
pub fn publish_desktop(Int32) -> Unit
pub fn publish_power(UInt32, UInt32) -> Unit
pub fn publish_screenshot(UInt32) -> Unit
@@ -113,6 +121,7 @@ pub(all) enum Request {
Shortcut(Int32)
ReloadSession
DefaultApp(Int32)
SetDesktop(Int32)
}
pub(all) struct SettingChange {
+44 -1
View File
@@ -61,6 +61,7 @@ pub(all) enum Request {
Shortcut(Int)
ReloadSession
DefaultApp(Int)
SetDesktop(Int)
}
///|
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
@@ -384,6 +385,36 @@ pub fn set_config(handle : UInt, key : String, value : String) -> Bool {
mbt_ffi_free(ptr0)
return ret
}
///|
/// Desktop modules (chandra:desktop/desktop-module, wit/desktop.wit): the module's backdrop (0
/// over the wallpaper, 1 replacing it), or -1 when it doesn't export desktop-module (a panel
/// module).
pub fn desktop_backdrop(handle : UInt) -> Int {
let result : Int = wasmImportDesktopBackdrop((handle).reinterpret_as_int());
let ret = result
return ret
}
///|
/// Scroll over the desktop at (x, y), `dx` / `dy` pixels. True when it wants a redraw.
pub fn desktop_scroll(handle : UInt, x : Int, y : Int, dx : Int, dy : Int) -> Bool {
let result : Int = wasmImportDesktopScroll((handle).reinterpret_as_int(), x, y, dx, dy);
let ret = (result != 0)
return ret
}
///|
/// The module's animation clock (`now-ms` since it was loaded): ms until it wants the next
/// frame, 0 for none.
pub fn desktop_tick(handle : UInt, now_ms : UInt) -> UInt {
let result : Int = wasmImportDesktopTick((handle).reinterpret_as_int(), (now_ms).reinterpret_as_int());
let ret = (result).reinterpret_as_uint()
return ret
}
///|
/// ---- host data modules read through their capabilities ----
@@ -395,7 +426,8 @@ pub fn set_config(handle : UInt, key : String, value : String) -> Bool {
/// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane
/// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved), 10 keyboard
/// shortcuts (ssssi: name binding default-binding conflict capturing), 11 default-app
/// categories (sss: name current missing), 12 default-app choices (issii: category id name icon current).
/// categories (sss: name current missing), 12 default-app choices (issii: category id name icon current),
/// 20 desktops (s: name) served by `wallpaper.desktops`.
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
let ptr = mbt_ffi_bytes2ptr(rows)
@@ -417,6 +449,13 @@ pub fn publish_wallpaper(current : Int) -> Unit {
wasmImportPublishWallpaper(current);
}
///|
/// What is on the desktop now (an index into the desktops table).
pub fn publish_desktop(current : Int) -> Unit {
wasmImportPublishDesktop(current);
}
///|
/// Which session settings are on: bit i for row i of the session settings table.
@@ -581,6 +620,10 @@ pub fn next_request() -> Request? {
Request::DefaultApp(mbt_ffi_load32((return_area) + 8))
}
19 => {
Request::SetDesktop(mbt_ffi_load32((return_area) + 8))
}
_ => panic()
}