Desktop modules: a wasm module can fill the desktop, with Icon Desktop and Live Starfield
CI / test (push) Failing after 30s
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:
79 files changed
+4591
-113
No files matched your search
+97
-17
@@ -197,6 +197,9 @@ pub(all) struct CatalogEntry {
|
||||
path : String
|
||||
/// Filled in (by loading the module once) the first time names are needed; "" until then.
|
||||
mut name : String
|
||||
/// A desktop module (it exports `desktop-module`): it fills the desktop, not a panel slot.
|
||||
/// Known once names are (see `name_catalog`).
|
||||
mut desktop : Bool
|
||||
}
|
||||
|
||||
///| One row of the right-click menu. `kind`: 0 replace with module `arg` (a path), 1 remove,
|
||||
@@ -359,6 +362,34 @@ pub(all) struct DesktopShell {
|
||||
/// The launcher module's state as the shell follows it (dock.mbt `follow_launcher`): what its
|
||||
/// popup lists, for the right-click "Pin to dock" menu.
|
||||
launcher_state : @launcher.State
|
||||
/// What fills the desktop (desktop_module.mbt): "wallpaper", "clock-card" or a desktop
|
||||
/// module's id (or path); saved in state.edn as `:desktop`.
|
||||
mut desk_choice : String
|
||||
mut desk_choice_read : Bool
|
||||
/// The loaded desktop module (slot "desktop"), its backdrop (0 over the wallpaper, 1 instead of
|
||||
/// it) and when it was loaded (its clock's zero, monotonic ms).
|
||||
mut desk_mod : Widget?
|
||||
mut desk_backdrop : Int
|
||||
mut desk_t0 : UInt64
|
||||
/// When its next animation frame is due (monotonic ms, 0: none asked for).
|
||||
mut desk_next : UInt64
|
||||
/// Its last drawing (desktop coordinates), a counter bumped each time it is redrawn, whether it
|
||||
/// must be redrawn, and the size and theme it was drawn for.
|
||||
mut desk_ops : Array[@scene.DrawOp]
|
||||
mut desk_gen : Int
|
||||
mut desk_dirty : Bool
|
||||
mut desk_drawn : (Int, Int, @scene.ThemeTokens)?
|
||||
/// Input: the desktop has the keyboard (clicked, no window focused since), the pointer is over
|
||||
/// it, a press on it is held (moves and the release go to it even over a window).
|
||||
mut desk_focus : Bool
|
||||
mut desk_hover : Bool
|
||||
mut desk_grab : Bool
|
||||
/// A window covers the whole desktop: animation frames pause (the compositor sets it).
|
||||
mut desk_covered : Bool
|
||||
/// The module's hidden settings (empty label) as last saved, to save only changes.
|
||||
desk_saved : Map[String, String]
|
||||
/// The menu's top edge when it opens at the pointer (the desktop menu); -1 above the panel.
|
||||
mut menu_anchor_y : Int
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -469,6 +500,22 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
wit_cache: {},
|
||||
recents: [],
|
||||
launcher_state: @launcher.State::new(),
|
||||
desk_choice: default_desktop,
|
||||
desk_choice_read: false,
|
||||
desk_mod: None,
|
||||
desk_backdrop: 0,
|
||||
desk_t0: 0,
|
||||
desk_next: 0,
|
||||
desk_ops: [],
|
||||
desk_gen: 0,
|
||||
desk_dirty: false,
|
||||
desk_drawn: None,
|
||||
desk_focus: false,
|
||||
desk_hover: false,
|
||||
desk_grab: false,
|
||||
desk_covered: false,
|
||||
desk_saved: {},
|
||||
menu_anchor_y: -1,
|
||||
}
|
||||
sh.order_apps()
|
||||
sh
|
||||
@@ -608,6 +655,9 @@ fn DesktopShell::widget_at(self : DesktopShell, x : Int, y : Int) -> Widget? {
|
||||
|
||||
///|
|
||||
fn DesktopShell::widget_by_slot(self : DesktopShell, slot : String) -> Widget? {
|
||||
if slot == desktop_slot {
|
||||
return self.desk_mod
|
||||
}
|
||||
for w in self.widgets {
|
||||
if w.slot == slot {
|
||||
return Some(w)
|
||||
@@ -920,6 +970,9 @@ struct BgKey {
|
||||
date : (UInt, Byte, Byte, Byte)
|
||||
hour : Byte
|
||||
minute : Byte
|
||||
/// The desktop module's drawing (`desk_gen`), -1 with the clock card, -2 with the wallpaper
|
||||
/// alone.
|
||||
desk : Int
|
||||
}
|
||||
|
||||
///| The wallpaper and the desktop card. Building them costs most of an idle frame (the card's
|
||||
@@ -932,26 +985,53 @@ fn DesktopShell::background(
|
||||
theme : @scene.ThemeTokens,
|
||||
tokens : @theme.Tokens,
|
||||
) -> Array[@scene.DrawOp] {
|
||||
let at = now()
|
||||
let (dx, dy) = self.desk_pos()
|
||||
let key : BgKey = {
|
||||
w,
|
||||
h,
|
||||
theme,
|
||||
wallpaper: self.wallpaper_sel,
|
||||
x: dx,
|
||||
y: dy,
|
||||
date: (at.year, at.month, at.day, at.weekday),
|
||||
hour: at.hour,
|
||||
minute: at.minute,
|
||||
let card = self.desk_choice == clock_card_desktop && self.desk_mod is None
|
||||
let key : BgKey = if card {
|
||||
let at = now()
|
||||
let (dx, dy) = self.desk_pos()
|
||||
{
|
||||
w,
|
||||
h,
|
||||
theme,
|
||||
wallpaper: self.wallpaper_sel,
|
||||
x: dx,
|
||||
y: dy,
|
||||
date: (at.year, at.month, at.day, at.weekday),
|
||||
hour: at.hour,
|
||||
minute: at.minute,
|
||||
desk: -1,
|
||||
}
|
||||
} else {
|
||||
// The wallpaper alone, or under / instead of the desktop module: nothing follows the clock.
|
||||
self.desktop_render(w, h, theme, tokens)
|
||||
let replaced = self.desk_mod is Some(_) && self.desk_backdrop == 1
|
||||
{
|
||||
w,
|
||||
h,
|
||||
theme,
|
||||
wallpaper: if replaced { -1 } else { self.wallpaper_sel },
|
||||
x: 0,
|
||||
y: 0,
|
||||
date: (0, b'\x00', b'\x00', b'\x00'),
|
||||
hour: b'\x00',
|
||||
minute: b'\x00',
|
||||
desk: if self.desk_mod is Some(_) { self.desk_gen } else { -2 },
|
||||
}
|
||||
}
|
||||
if self.bg_key == Some(key) {
|
||||
return self.bg_cache
|
||||
}
|
||||
let bg : Array[@scene.DrawOp] = []
|
||||
translate(@libshell.render_wallpaper(@ui.size(w, h), tokens, self.wallpaper_sel), 0, 0, bg)
|
||||
if key.wallpaper >= 0 {
|
||||
translate(@libshell.render_wallpaper(@ui.size(w, h), tokens, self.wallpaper_sel), 0, 0, bg)
|
||||
}
|
||||
self.wallpaper_len = bg.length()
|
||||
render_desktop_widget(dx, dy, tokens, at, bg)
|
||||
if card {
|
||||
let (dx, dy) = self.desk_pos()
|
||||
render_desktop_widget(dx, dy, tokens, now(), bg)
|
||||
} else if self.desk_mod is Some(_) {
|
||||
bg.append(self.desk_ops)
|
||||
}
|
||||
self.bg_cache = bg
|
||||
self.bg_key = Some(key)
|
||||
bg
|
||||
@@ -973,14 +1053,14 @@ pub fn DesktopShell::render(
|
||||
self.poll_picker()
|
||||
self.publish_host_data()
|
||||
// Machine state and the rich window list only matter to modules that import them.
|
||||
if self.widgets.iter().any(w => w.has_cap("system")) {
|
||||
if self.any_cap("system") {
|
||||
self.sampler.refresh() // reads /proc once a second
|
||||
}
|
||||
if self.widgets.iter().any(w => w.has_cap("system") || w.has_cap("windows")) {
|
||||
if self.any_cap("system") || self.any_cap("windows") {
|
||||
@wasm.set_windows(self.win_list)
|
||||
}
|
||||
self.settle_dock_pins()
|
||||
if self.widgets.iter().any(w => w.has_cap("icons")) {
|
||||
if self.any_cap("icons") {
|
||||
self.publish_icons()
|
||||
}
|
||||
let bg = self.background(w, h, theme, tokens)
|
||||
|
||||
Reference in new issue
Block a user