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

+511
View File
@@ -0,0 +1,511 @@
///| Desktop modules (wit/desktop.wit, docs/desktop-modules.md): a wasm module that fills the
/// desktop, the whole output behind the windows, instead of a box in the panel.
///
/// What fills the desktop is one of: the wallpaper alone, the built-in clock card on it (the
/// default), or one installed desktop module, chosen in Settings > Desktop (the `wallpaper`
/// capability's `desktops` / `set-desktop`) and saved in state.edn as `:desktop`. The module is a
/// plasmoid like any panel module (same sandbox, draw ops, capabilities and right-click settings),
/// kept apart from the panel's `widgets` in `desk_mod` under the slot name "desktop".
///
/// The compositor routes input here only where nothing else is: no window, panel, popup or menu
/// (desktop_pointer_move / desktop_press / desktop_release / desktop_scroll), keys only while the
/// desktop has the keyboard (desktop_key), and a right-click on the empty desktop opens the
/// desktop menu (desktop_menu) instead of reaching the module. The module's drawing is cached and
/// redrawn only when it asks (an event returning true, an animation frame, a resize or theme
/// change); animation frames come from its `tick`, and the main loop sleeps until the next one is
/// due (desktop_wake_ms), so a still desktop module costs nothing while idle.
///| The slot name of the desktop module (menus, reload, settings).
pub let desktop_slot : String = "desktop"
///| The `:desktop` choices that aren't modules.
pub let wallpaper_desktop : String = "wallpaper"
///|
pub let clock_card_desktop : String = "clock-card"
///| What fills a fresh session's desktop: the clock card, as before desktop modules.
let default_desktop : String = "clock-card"
///| A module's frame request is capped at this (ms): a module can't put itself to sleep for
/// hours by mistake and miss its own animation.
let max_frame_delay : Int = 10000
///| Is any loaded module (panel or desktop) granted `cap`?
fn DesktopShell::any_cap(self : DesktopShell, cap : String) -> Bool {
self.widgets.iter().any(w => w.has_cap(cap)) ||
(match self.desk_mod {
Some(d) => d.has_cap(cap)
None => false
})
}
///| The desktop module, if one is loaded.
pub fn DesktopShell::desktop_module(self : DesktopShell) -> Widget? {
self.desk_mod
}
///| What fills the desktop now: "wallpaper", "clock-card" or the module's id.
pub fn DesktopShell::desktop_choice(self : DesktopShell) -> String {
self.read_desktop_choice()
self.desk_choice
}
// ---------------------------------------------------------------- choosing and loading
///| Read `:desktop` from state.edn once (with `persist`; else the default stays).
fn DesktopShell::read_desktop_choice(self : DesktopShell) -> Unit {
if self.desk_choice_read {
return
}
self.desk_choice_read = true
if !self.persist {
return
}
match lookup_key(read_state_file(), "desktop") {
Some(Text(s)) if s.length() > 0 => self.desk_choice = s
Some(Keyword(s)) if s.length() > 0 => self.desk_choice = s
_ => ()
}
}
///| Write `:desktop` (keeping every other key); nothing without `persist`. The default is left out.
fn DesktopShell::write_desktop_choice(self : DesktopShell) -> Unit {
if !self.persist {
return
}
let entries : Array[(@edn.Value, @edn.Value)] = []
for e in read_state_file() {
match e.0 {
Keyword("desktop") => ()
_ => entries.push(e)
}
}
if self.desk_choice != default_desktop {
entries.push((@edn.Value::Keyword("desktop"), @edn.Value::Text(self.desk_choice)))
}
write_state_file(entries)
}
///| At boot: load the saved desktop module, if that is the choice. A module that is gone or
/// fails leaves the clock card (the saved choice is kept for when it is back).
fn DesktopShell::boot_desktop(self : DesktopShell) -> Unit {
self.read_desktop_choice()
let c = self.desk_choice
if c == wallpaper_desktop || c == clock_card_desktop || self.desk_mod is Some(_) {
return
}
match self.load_desktop(c) {
Ok(_) => ()
Err(e) => self.say(e)
}
}
///| The desktop modules on the module path: (id, name), in catalog order.
pub fn DesktopShell::desktop_modules(self : DesktopShell) -> Array[(String, String)] {
self.name_catalog()
let out : Array[(String, String)] = []
for e in self.catalog {
if e.desktop {
out.push((e.id, e.name))
}
}
out
}
///| The Desktops table the settings module lists: wallpaper only, the clock card, each module;
/// and which of them is current.
fn DesktopShell::desktop_rows(self : DesktopShell) -> (Array[String], Int) {
let names = ["Wallpaper only", "Clock card"]
let mods = self.desktop_modules()
let choice = self.desktop_choice()
let mut cur = if choice == wallpaper_desktop { 0 } else { 1 }
for i, m in mods {
names.push(m.1)
match self.desk_mod {
Some(d) if d.module_id == m.0 => cur = i + 2
_ => ()
}
}
(names, cur)
}
///|
fn DesktopShell::publish_desktops(self : DesktopShell) -> Unit {
let (names, cur) = self.desktop_rows()
let t = @wasm.Table::new()
for n in names {
t.str(n)
t.end_row()
}
@wasm.publish(Desktops, t)
@wasm.publish_desktop(cur)
}
///| The settings module's `set-desktop`: index into the Desktops table.
fn DesktopShell::set_desktop_index(self : DesktopShell, i : Int) -> Unit {
let mods = self.desktop_modules()
let id = match i {
0 => wallpaper_desktop
1 => clock_card_desktop
_ if i - 2 < mods.length() && i >= 2 => mods[i - 2].0
_ => return
}
ignore(self.set_desktop(id))
}
///| Put `id` on the desktop ("wallpaper", "clock-card", or a desktop module's id or path) and
/// remember it. False, with a notice, when the module can't be loaded (what was there stays).
pub fn DesktopShell::set_desktop(self : DesktopShell, id : String) -> Bool {
self.ensure_booted()
self.read_desktop_choice()
if id == wallpaper_desktop || id == clock_card_desktop {
self.unload_desktop()
} else {
match self.load_desktop(id) {
Ok(w) => self.say("Desktop: " + w.pl.name)
Err(e) => {
self.say(e)
return false
}
}
}
self.desk_choice = id
self.write_desktop_choice()
self.bg_key = None
self.publish_desktops()
true
}
///| Load desktop module `id` (catalog id or path) in place of the current one.
fn DesktopShell::load_desktop(self : DesktopShell, id : String) -> Result[Widget, String] {
let path = match self.find_module(id) {
Some(c) => c.path
None => if id.contains("/") { id } else { return Err("Desktop module '" + id + "' not found") }
}
match @wasm.load(path, self.tokens) {
Err(e) => Err("Can't load desktop module: " + e)
Ok(pl) => {
let backdrop = pl.desktop_backdrop()
if backdrop < 0 {
pl.unload()
return Err(pl.name + " is a panel module, not a desktop module")
}
let known = match self.find_module(stem(path)) {
Some(c) => c.path == path
None => false
}
let w : Widget = {
slot: desktop_slot,
module_id: if known { stem(path) } else { path },
path,
pl,
caps: pl.imports(),
rect: { x: 0, y: 0, w: self.screen_w, h: self.screen_h },
popup_rect: { x: 0, y: 0, w: 0, h: 0 },
popup_ops: [],
popup_hot: false,
slide_t0: 0,
slide_in: false,
ghost_rect: { x: 0, y: 0, w: 0, h: 0 },
ghost_ops: [],
}
self.unload_desktop()
self.desk_mod = Some(w)
self.desk_backdrop = backdrop
self.apply_module_cfg(w)
self.desk_saved.clear()
for it in w.pl.config_items() {
if it.label.length() == 0 {
self.desk_saved.set(it.key, it.value)
}
}
self.desk_t0 = @sys.monotonic_ms()
self.desk_next = 0
self.desk_dirty = true
self.desk_drawn = None
self.bg_key = None
// Its clock starts: the first frame request.
self.desktop_tick(self.desk_t0)
Ok(w)
}
}
}
///| Unload the desktop module (the wallpaper / card shows again).
fn DesktopShell::unload_desktop(self : DesktopShell) -> Unit {
match self.desk_mod {
Some(d) => {
d.pl.unload()
self.desk_mod = None
self.desk_ops = []
self.desk_next = 0
self.desk_focus = false
self.desk_hover = false
self.desk_grab = false
self.desk_drawn = None
self.bg_key = None
if self.menu_slot == desktop_slot {
self.menu_open = false
}
}
None => ()
}
}
///| Reload the desktop module from its file (chandra-ctl reload): settings and hidden state are
/// handed back as at login. On failure the old instance stays.
fn DesktopShell::reload_desktop(self : DesktopShell) -> Result[Widget, String] {
match self.desk_mod {
None => Err("")
Some(old) => {
// Load the new one before dropping the old, so a broken build leaves the desktop as it was.
match @wasm.load(old.path, self.tokens) {
Err(e) => Err("Can't load module: " + e)
Ok(probe) => {
let ok = probe.desktop_backdrop() >= 0
probe.unload()
if !ok {
return Err("not a desktop module any more")
}
let id = if old.module_id.contains("/") { old.path } else { old.module_id }
let path = old.path
self.unload_desktop()
match self.load_desktop(if self.find_module(id) is Some(_) { id } else { path }) {
Ok(w) => Ok(w)
Err(e) => Err(e)
}
}
}
}
}
}
// ---------------------------------------------------------------- drawing and frames
///| Redraw the module's ops when needed: asked for, or the output size or theme changed (the
/// module is told the new size through `render`).
fn DesktopShell::desktop_render(
self : DesktopShell,
w : Int,
h : Int,
theme : @scene.ThemeTokens,
tokens : @theme.Tokens,
) -> Unit {
match self.desk_mod {
None => ()
Some(d) => {
self.desktop_pump(@sys.monotonic_ms())
let same = match self.desk_drawn {
Some((dw, dh, t)) => dw == w && dh == h && t == theme
None => false
}
if same && !self.desk_dirty {
return
}
let out : Array[@scene.DrawOp] = []
translate(d.pl.render(w, h, tokens), 0, 0, out)
self.process_requests()
d.rect = { x: 0, y: 0, w, h }
self.desk_ops = out
self.desk_gen = self.desk_gen + 1
self.desk_dirty = false
self.desk_drawn = Some((w, h, theme))
}
}
}
///| Run the module's clock: ask it when the next frame is due, and whether to redraw.
fn DesktopShell::desktop_tick(self : DesktopShell, now : UInt64) -> Unit {
match self.desk_mod {
None => ()
Some(d) => {
let ms = (now - self.desk_t0).to_int()
let r = d.pl.desktop_tick(ms)
let r = if r > max_frame_delay { max_frame_delay } else { r }
self.desk_next = if r > 0 { now + r.to_uint64() } else { 0 }
}
}
}
///| A due animation frame: tick, then redraw. Frames pause while a window covers the desktop.
fn DesktopShell::desktop_pump(self : DesktopShell, now : UInt64) -> Unit {
if self.desk_next != 0 && now >= self.desk_next && !self.desk_covered {
self.desktop_tick(now)
self.desk_dirty = true
}
}
///| Milliseconds until the desktop module's next animation frame, -1 when none is due (no
/// module, it asked for none, or a window covers the desktop). The main loop's idle sleep is
/// capped by this.
pub fn DesktopShell::desktop_wake_ms(self : DesktopShell, now : UInt64) -> Int {
if self.desk_mod is None || self.desk_next == 0 || self.desk_covered {
-1
} else if now >= self.desk_next {
0
} else {
(self.desk_next - now).to_int()
}
}
///| True while the desktop module is animating (it asked for a frame).
pub fn DesktopShell::desktop_animating(self : DesktopShell) -> Bool {
self.desk_mod is Some(_) && self.desk_next != 0
}
///| Tell the shell whether a window covers the whole desktop (the compositor, every frame).
pub fn DesktopShell::set_desktop_covered(self : DesktopShell, covered : Bool) -> Unit {
self.desk_covered = covered
}
///| After the module handled something: redraw if it asked, restart its clock, and save hidden
/// settings that changed (`save`: on releases and keys, not on every motion).
fn DesktopShell::desktop_changed(self : DesktopShell, redraw : Bool, save? : Bool = false) -> Unit {
if redraw {
self.desk_dirty = true
}
self.desktop_tick(@sys.monotonic_ms())
if save {
self.save_desktop_hidden()
}
}
///| Remember the module's hidden settings (empty label: e.g. where icons were put) that changed.
fn DesktopShell::save_desktop_hidden(self : DesktopShell) -> Unit {
match self.desk_mod {
None => ()
Some(d) =>
for it in d.pl.config_items() {
if it.label.length() == 0 && self.desk_saved.get(it.key) != Some(it.value) {
self.desk_saved.set(it.key, it.value)
self.remember_module_setting(d.module_id, it.key, it.value)
}
}
}
}
///| Deliver one event to the desktop module and carry out its requests.
fn DesktopShell::desktop_event(self : DesktopShell, ev : @wasm.PlasmoidEvent, save? : Bool = false) -> Bool {
match self.desk_mod {
None => false
Some(d) => {
self.publish_host_data()
let redraw = d.pl.on_event(false, ev)
self.process_requests()
self.desktop_changed(redraw, save~)
true
}
}
}
// ---------------------------------------------------------------- input
///| The pointer moved over the empty desktop (no window, panel, popup or menu there). True when
/// a desktop module took it.
pub fn DesktopShell::desktop_pointer_move(self : DesktopShell, x : Int, y : Int) -> Bool {
if self.desk_mod is None {
return false
}
self.desk_hover = true
self.desktop_event(PointerMove(x, y))
}
///| The pointer left the empty desktop (onto a window, the panel ...). While a press on the
/// desktop is held it keeps getting the motion instead (see `desktop_grabbing`).
pub fn DesktopShell::desktop_leave(self : DesktopShell) -> Unit {
if self.desk_hover && !self.desk_grab {
self.desk_hover = false
ignore(self.desktop_event(PointerLeave))
}
}
///| A left press on the empty desktop: the desktop takes the keyboard and the module the press.
/// True when a desktop module took it.
pub fn DesktopShell::desktop_press(self : DesktopShell, x : Int, y : Int) -> Bool {
self.ensure_booted()
if self.desk_mod is None {
return false
}
self.dismiss_popups("")
self.desk_focus = true
self.desk_grab = true
self.desk_hover = true
self.desktop_event(PointerDown(x, y))
}
///| True while a press on the desktop is held: motion and the release go to the module wherever
/// the pointer is.
pub fn DesktopShell::desktop_grabbing(self : DesktopShell) -> Bool {
self.desk_grab && self.desk_mod is Some(_)
}
///| The release of a press that went to the desktop. True when there was one.
pub fn DesktopShell::desktop_release(self : DesktopShell, x : Int, y : Int) -> Bool {
if !self.desk_grab {
return false
}
self.desk_grab = false
ignore(self.desktop_event(PointerUp(x, y), save=true))
true
}
///| Wheel over the empty desktop. True when a desktop module took it.
pub fn DesktopShell::desktop_scroll(self : DesktopShell, x : Int, y : Int, dx : Int, dy : Int) -> Bool {
match self.desk_mod {
None => false
Some(d) => {
self.publish_host_data()
let redraw = d.pl.desktop_scroll(x, y, dx, dy)
self.process_requests()
self.desktop_changed(redraw, save=true)
true
}
}
}
///| Does the desktop have the keyboard (clicked, and no window focused since)?
pub fn DesktopShell::desktop_has_focus(self : DesktopShell) -> Bool {
self.desk_focus && self.desk_mod is Some(_)
}
///| A key for the desktop module (only while it has the keyboard). True when it took it.
pub fn DesktopShell::desktop_key(self : DesktopShell, name : String) -> Bool {
if !self.desktop_has_focus() {
return false
}
self.desktop_event(KeyDown(name), save=true)
}
///| A window took the keyboard: the desktop module hears `focus-lost`.
pub fn DesktopShell::desktop_unfocus(self : DesktopShell) -> Unit {
if self.desk_focus {
self.desk_focus = false
ignore(self.desktop_event(FocusLost))
}
}
///| Right-click on the empty desktop: the desktop menu at the pointer, with the module's settings
/// (when it has any) and System settings on the Desktop tab. Always consumed.
pub fn DesktopShell::desktop_menu(self : DesktopShell, x : Int, y : Int) -> Bool {
self.ensure_booted()
if self.inspect_on {
return false
}
self.dismiss_popups("")
let rows : Array[MenuRow] = []
let title = match self.desk_mod {
Some(d) => {
if config_rows(d.pl.config_items()).length() > 0 {
rows.push(menu_row("Module settings...", 3))
} else {
rows.push(menu_row("No module settings", 5))
}
d.pl.name
}
None => "Desktop"
}
rows.push(menu_row("System settings...", 2, arg="desktop"))
self.open_menu(title, rows, desktop_slot, x, y~)
true
}
+3
View File
@@ -57,6 +57,9 @@ fn DesktopShell::desk_pos(self : DesktopShell) -> (Int, Int) {
///| 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
}
+1 -1
View File
@@ -26,7 +26,7 @@ pub fn DesktopShell::set_network_backend(self : DesktopShell, b : &@network.NetB
///| Refresh and publish network state while a module imports `network`; drop the service (and
/// its bus connection) when none does any more.
fn DesktopShell::publish_network(self : DesktopShell) -> Unit {
if !self.widgets.iter().any(w => w.has_cap("network")) {
if !self.any_cap("network") {
match self.net {
Some(n) if n.probe() => {
n.close()
+97 -17
View File
@@ -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)
+70 -16
View File
@@ -138,7 +138,7 @@ fn DesktopShell::scan_catalog(self : DesktopShell) -> Unit {
let id = stem(f)
if !seen.contains(id) && !retired_modules.contains(id) {
seen.set(id, true)
self.catalog.push({ id, path: dir + "/" + f, name: "" })
self.catalog.push({ id, path: dir + "/" + f, name: "", desktop: false })
}
}
}
@@ -156,6 +156,7 @@ fn DesktopShell::name_catalog(self : DesktopShell) -> Unit {
match @wasm.load(e.path, self.tokens) {
Ok(pl) => {
e.name = pl.name
e.desktop = pl.desktop_backdrop() >= 0
pl.unload()
keep.push(e)
}
@@ -316,6 +317,7 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
Some(old) if old != entries => write_panel_file(entries)
_ => ()
}
self.boot_desktop()
for e in entries {
let path = if e.has_prefix("/") {
e
@@ -350,6 +352,11 @@ pub fn DesktopShell::load_path(self : DesktopShell, path : String) -> Widget? {
fn DesktopShell::try_load_path(self : DesktopShell, path : String) -> Result[Widget, String] {
match @wasm.load(path, self.tokens) {
Err(e) => Err("Can't load module: " + e)
Ok(pl) if pl.desktop_backdrop() >= 0 => {
// It fills the desktop, not a panel slot: Settings > Desktop puts it there.
pl.unload()
Err(pl.name + " is a desktop module: choose it in Settings > Desktop")
}
Ok(pl) => {
let id = stem(path)
let known = match self.find_module(id) {
@@ -510,6 +517,12 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
targets.push((w.slot, w.module_id, w.path))
}
}
// The desktop module too (slot "desktop").
match self.desk_mod {
Some(d) if name == "" || d.module_id == name || stem(d.path) == name || name == desktop_slot || d.path == name =>
targets.push((d.slot, d.module_id, d.path))
_ => ()
}
if targets.length() == 0 {
let msg = if name == "" {
"no modules are loaded"
@@ -523,7 +536,8 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
let mut last_err = ""
for t in targets {
let (slot, id, path) = t
match self.replace_slot_result(slot, path) {
let res = if slot == desktop_slot { self.reload_desktop() } else { self.replace_slot_result(slot, path) }
match res {
Ok(nw) => lines.push("reloaded " + nw.slot + " " + id)
Err(e) => {
failed = failed + 1
@@ -551,7 +565,12 @@ pub fn DesktopShell::reload_modules(self : DesktopShell, name : String) -> (Arra
///| The loaded modules in panel order: (slot, module id, path).
pub fn DesktopShell::loaded_modules(self : DesktopShell) -> Array[(String, String, String)] {
self.ensure_booted()
self.widgets.map(w => (w.slot, w.module_id, w.path))
let out = self.widgets.map(w => (w.slot, w.module_id, w.path))
match self.desk_mod {
Some(d) => out.push((d.slot, d.module_id, d.path)) // the desktop module, last
None => ()
}
out
}
///| Unload every module (the compositor is closing).
@@ -560,6 +579,7 @@ pub fn DesktopShell::shutdown(self : DesktopShell) -> Unit {
w.pl.unload()
}
self.widgets.clear()
self.unload_desktop()
}
///| Slot ids of the loaded modules, in panel order.
@@ -652,7 +672,7 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
}
@wasm.publish(Layouts, lt)
@wasm.publish_state(self.layout_sel, self.inspect_on)
if self.widgets.iter().any(w => w.has_cap("wallpaper")) {
if self.any_cap("wallpaper") {
let pt = @wasm.Table::new()
for n in @libshell.wallpaper_names {
pt.str(n)
@@ -660,8 +680,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
}
@wasm.publish(Wallpapers, pt)
@wasm.publish_wallpaper(self.wallpaper_sel)
self.publish_desktops()
}
if self.widgets.iter().any(w => w.has_cap("session-settings")) {
if self.any_cap("session-settings") {
let st = @wasm.Table::new()
for n in session_setting_names {
st.str(n)
@@ -670,19 +691,19 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
@wasm.publish(SessionSettings, st)
@wasm.publish_session_settings(self.session_settings_bits())
}
if self.widgets.iter().any(w => w.has_cap("power")) {
if self.any_cap("power") {
@wasm.publish_power(self.screen_off_min, self.suspend_min)
}
if self.widgets.iter().any(w => w.has_cap("shortcuts")) {
if self.any_cap("shortcuts") {
self.publish_shortcuts()
}
if self.widgets.iter().any(w => w.has_cap("default-apps")) {
if self.any_cap("default-apps") {
self.publish_default_apps()
}
if self.widgets.iter().any(w => w.has_cap("screenshot")) {
if self.any_cap("screenshot") {
@wasm.publish_screenshot(self.screenshot_state)
}
if self.widgets.iter().any(w => w.has_cap("battery")) {
if self.any_cap("battery") {
let b = self.battery.refresh()
@wasm.publish_battery(b.percent, b.state, b.secs_left)
}
@@ -705,6 +726,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
self.name_catalog()
let mt = @wasm.Table::new()
for e in self.catalog {
if e.desktop {
continue // chosen in Settings > Desktop, not added to the panel
}
let mut n = 0
for w in self.widgets {
if w.path == e.path {
@@ -810,6 +834,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
self.actions.push(ModulesReloaded)
}
Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetDesktop(i)) => self.set_desktop_index(i)
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
Some(Screenshot(code)) => self.actions.push(Screenshot(code))
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
@@ -900,7 +925,7 @@ fn DesktopShell::poll_picker(self : DesktopShell) -> Unit {
pub(all) enum SettingsTab {
/// The session switches.
Session
/// What is on the desktop: the wallpaper (modules can't be placed on the desktop yet).
/// What is on the desktop: the wallpaper, the clock card or a desktop module.
Desktop
/// The panel's modules: remove, add, browse.
Panel
@@ -1065,7 +1090,7 @@ fn DesktopShell::open_module_settings(self : DesktopShell, slot : String) -> Uni
if rows.length() == 0 {
rows.push(menu_row("No module settings", 5))
}
self.open_menu(w.pl.name + " settings", rows, slot, self.menu_anchor_x)
self.open_menu(w.pl.name + " settings", rows, slot, self.menu_anchor_x, y=self.menu_anchor_y)
}
}
}
@@ -1081,6 +1106,13 @@ pub fn DesktopShell::set_module_setting(self : DesktopShell, slot : String, key
ignore(o.pl.set_config(key, value))
}
}
match self.desk_mod {
Some(d) if d.module_id == w.module_id => {
ignore(d.pl.set_config(key, value))
self.desktop_changed(true)
}
_ => ()
}
}
}
}
@@ -1110,7 +1142,15 @@ fn DesktopShell::choose_module_setting(self : DesktopShell, slot : String, key :
}
///|
fn DesktopShell::open_menu(self : DesktopShell, title : String, rows : Array[MenuRow], slot : String, x : Int) -> Unit {
fn DesktopShell::open_menu(
self : DesktopShell,
title : String,
rows : Array[MenuRow],
slot : String,
x : Int,
y? : Int = -1,
) -> Unit {
self.menu_anchor_y = y
self.menu_open = true
self.menu_title = title
self.menu_rows = rows
@@ -1143,7 +1183,16 @@ fn DesktopShell::menu_pointer_down(self : DesktopShell, x : Int, y : Int) -> Boo
match row.kind {
0 => ignore(self.replace_slot(slot, row.arg))
1 => ignore(self.unload_slot(slot))
2 => ignore(self.open_settings(if row.arg == "panel" { Panel } else { Session }))
2 =>
ignore(
self.open_settings(
match row.arg {
"panel" => Panel
"desktop" => Desktop
_ => Session
},
),
)
3 => self.open_module_settings(slot)
4 => self.choose_module_setting(slot, row.arg, row.value)
6 => self.actions.push(Window(row.window_id, row.window_cmd))
@@ -1170,8 +1219,13 @@ fn DesktopShell::render_menu(
) -> Unit {
let n = self.menu_rows.length()
let mh = menu_title_h + n * menu_item_h + 6
let mx = clamp_menu(self.menu_anchor_x - menu_w / 2, 4, w - menu_w - 4)
let my = self.panel_rect.y - mh - 6
// Above the panel, centred on the click; or (the desktop menu) at the pointer.
let (mx, my) = if self.menu_anchor_y >= 0 {
let bottom = if self.panel_rect.h > 0 { self.panel_rect.y } else { self.screen_h }
(clamp_menu(self.menu_anchor_x, 4, w - menu_w - 4), clamp_menu(self.menu_anchor_y, 4, bottom - mh - 4))
} else {
(clamp_menu(self.menu_anchor_x - menu_w / 2, 4, w - menu_w - 4), self.panel_rect.y - mh - 6)
}
self.menu_rect = { x: mx, y: my, w: menu_w, h: mh }
let fs = tokens.font_size.reinterpret_as_int()
let r = tokens.radius.reinterpret_as_int()