Files
Claude 0f71779819
CI / test (push) Failing after 30s
Desktop modules: a wasm module can fill the desktop, with Icon Desktop and Live Starfield
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
2026-11-26 00:30:32 +00:00

83 lines
2.9 KiB
MoonBit

///| Desktop widget: a card on the wallpaper (below all windows, top-right) showing
/// the time, the date and the current moon phase. Built from the same pure lib/*
/// renderers as the panel widgets.
///|
let desktop_widget_w : Int = 260
///|
let desktop_widget_h : Int = 120
///|
fn render_desktop_widget(
x0 : Int,
y0 : Int,
tokens : @theme.Tokens,
at : @types.Datetime,
out : Array[@scene.DrawOp],
) -> Unit {
let r = tokens.radius.reinterpret_as_int()
let hour = at.hour.to_int()
let minute = at.minute.to_int()
let time = @timefmt.hhmm12(hour, minute)
let date = @timefmt.weekday_short(at.weekday.to_int()) +
", " +
at.day.to_int().to_string() +
" " +
@timefmt.month_short(at.month.to_int())
let p = @moon.phase(at.year.reinterpret_as_int(), at.month.to_int(), at.day.to_int())
let ops : Array[@types.DrawOp] = [
@ui.fill_rect(@ui.rect(0, 0, desktop_widget_w, desktop_widget_h), tokens.palette.surface, radius=r),
@ui.stroke_rect(@ui.rect(0, 0, desktop_widget_w, desktop_widget_h), tokens.palette.border, width=1, radius=r),
@ui.text(18, 38, time, 32, tokens.palette.foreground, bold=true),
@ui.text(18, 74, date, tokens.font_size.reinterpret_as_int(), tokens.palette.foreground),
@ui.text(
18,
98,
@moon.phase_name(p) + " " + @moon.illumination(p).to_string() + "%",
tokens.font_size.reinterpret_as_int() - 2,
tokens.palette.foreground,
),
]
translate(ops, x0, y0, out)
translate(@moon.render_disc(@ui.size(56, 56), tokens, p), x0 + desktop_widget_w - 56 - 18, y0 + 18, out)
}
///| Default top-right position of the card, and the clamp that keeps it on screen.
fn DesktopShell::desk_pos(self : DesktopShell) -> (Int, Int) {
let (x, y) = if self.desk_set {
(self.desk_x, self.desk_y)
} else {
(self.screen_w - desktop_widget_w - 24, 24)
}
let mx = if self.screen_w > desktop_widget_w { self.screen_w - desktop_widget_w } else { 0 }
let my = if self.screen_h > desktop_widget_h { self.screen_h - desktop_widget_h } else { 0 }
(if x < 0 { 0 } else if x > mx { mx } else { x }, if y < 0 { 0 } else if y > my { my } else { y })
}
///| True if (x, y) is over the desktop card.
pub fn DesktopShell::desk_hit(self : DesktopShell, x : Int, y : Int) -> Bool {
if self.desk_choice != clock_card_desktop || self.desk_mod is Some(_) {
return false // the clock card isn't on the desktop
}
let (cx, cy) = self.desk_pos()
x >= cx && x < cx + desktop_widget_w && y >= cy && y < cy + desktop_widget_h
}
///| Start dragging the card if the press is on it. Call only when no window covers (x, y).
pub fn DesktopShell::desk_press(self : DesktopShell, x : Int, y : Int) -> Bool {
if !self.desk_hit(x, y) {
return false
}
let (cx, cy) = self.desk_pos()
self.desk_drag = true
self.desk_off_x = x - cx
self.desk_off_y = y - cy
true
}
///| True while the card is being dragged.
pub fn DesktopShell::desk_dragging(self : DesktopShell) -> Bool {
self.desk_drag
}