Wallpaper chooser panel module, and four new wallpapers
CI / test (push) Failing after 17s

- New 'wallpaper' capability (wit/capabilities.wit: wallpapers, current-wallpaper, set-wallpaper)
  and 'wallpaper' panel module: a button whose popup lists the wallpapers with the current one
  ticked. Clicking a row switches the desktop at once (the list stays open to compare); Enter
  picks the highlighted row, Escape or a click elsewhere closes. In the default panel, before
  Log out.
- lib/shell: render_wallpaper(screen, tokens, index) with Plasma glow (the old background),
  Aurora, Starfield, Dusk and Solid, all draw ops; the themed ones follow a theme swap.
- The shell draws the chosen one (the renderer's wallpaper cache redraws it on change) and
  saves it in state.edn as :wallpaper (:aurora, ...); unknown names fall back to the default.
- Served by both hosts: wasmer stub (native) and host-wasm (publish-wallpaper, wallpapers
  table 5, set-wallpaper request).
- Tests: lib/shell wallpaper test, host-wasm module test, native end-to-end test (open, pick,
  Escape) and a state.edn round trip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhM8CTYpe2XVYTFQGn
This commit is contained in:
Claude authored and V committed 2026-11-25 17:08:39 +00:00
1 parent 7248e0ca6e
commit 5dfe34027b
37 files changed
+1311 -78

No files matched your search

+63
View File
@@ -1121,3 +1121,66 @@ test "super+d minimizes every window to show the desktop, and again brings them
key(32U, false, 21U)
assert_false(comp.wm.windows.get(2UL).unwrap().minimized)
}
///| Click (x, y) without drawing, then return the next scene's wallpaper op count (0: no new scene).
fn click_wallpaper_ops(comp : @host.MoonPlasmaCompositor, x : Int, y : Int, t : UInt) -> Int {
comp.handle_input(@nested.InputEvent::PointerMove(x.to_double(), y.to_double()), t)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t + 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 2U)
match comp.compose_scene() {
Some(sg) => sg.wallpaper_ops.length()
None => 0
}
}
///|
test "the wallpaper module lists the wallpapers and switches the desktop to the one clicked" {
let comp = new_comp("wallpaper")
let slot = comp.shell.slot_of("wallpaper")
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
assert_eq(comp.shell.wallpaper_sel, 0)
// A click opens the list; nothing changes yet.
click_module(comp, "wallpaper", 1U)
let pr = comp.shell.slot_popup_rect(slot)
assert_true(pr.h >= 6 * 2 + 5 * 30) // one row per wallpaper
assert_eq(comp.shell.wallpaper_sel, 0)
// Third row: Starfield. The list stays open and the backdrop is drawn anew.
let star = click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 2 * 30 + 5, 5U)
assert_eq(comp.shell.wallpaper_sel, 2)
assert_true(star > 0)
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
// Last row: Solid, a single fill. Escape then closes the list.
assert_eq(click_wallpaper_ops(comp, pr.x + 40, pr.y + 6 + 4 * 30 + 5, 10U), 1)
assert_eq(comp.shell.wallpaper_sel, 4)
comp.shell.key_down("Escape")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
// Out-of-range choices are ignored.
comp.shell.set_wallpaper(99)
assert_eq(comp.shell.wallpaper_sel, 4)
}
///|
test "the chosen wallpaper is saved to state.edn and restored" {
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\"}\n")
let a = new_comp("wall-a")
a.shell.persist = true
a.restore_state()
assert_eq(a.shell.wallpaper_sel, 0) // nothing saved: the default
a.shell.set_wallpaper(1)
let text = read_state_edn()
assert_true(text.contains(":wallpaper :aurora"))
assert_true(text.contains(":note \"keep\""))
let b = new_comp("wall-b")
b.shell.persist = true
b.restore_state()
assert_eq(b.shell.wallpaper_sel, 1)
// An unknown name falls back to the default.
write_state_edn("{:wallpaper :lava-lamp}\n")
let c = new_comp("wall-c")
c.shell.persist = true
c.restore_state()
assert_eq(c.shell.wallpaper_sel, 0)
}
}
+3
View File
@@ -22,6 +22,7 @@ pub fn DamageTracker::mark_rect(Self, Rect) -> Unit
pub fn DamageTracker::new() -> Self
pub fn DamageTracker::take_damage(Self, Int32, Int32) -> Array[Rect]
#derive(Eq)
pub(all) enum DrawOp {
FillRect(Rect, Rgba, Int32)
StrokeRect(Rect, Rgba, Int32, Int32)
@@ -65,6 +66,7 @@ pub fn Rgba::with_alpha(Self, Int32) -> Self
pub(all) struct SceneGraph {
output_w : Int32
output_h : Int32
mut wallpaper_ops : Array[DrawOp]
mut background_ops : Array[DrawOp]
mut windows : Array[WindowSceneNode]
mut panel_ops : Array[DrawOp]
@@ -79,6 +81,7 @@ pub(all) struct ShmBufferSnapshot {
stride : Int32
format : Int32
bytes : Bytes
host_id : UInt32
}
#derive(Eq, @debug.Debug)
+4 -1
View File
@@ -198,6 +198,8 @@ pub(all) struct DesktopShell {
/// Desktop card position (once moved) and drag state.
/// How many of the background ops are the static wallpaper (the rest is the desktop card).
mut wallpaper_len : Int
/// Which wallpaper is drawn (an index into `@libshell.wallpaper_names`); the wallpaper module sets it.
mut wallpaper_sel : Int
mut desk_set : Bool
mut desk_x : Int
mut desk_y : Int
@@ -276,6 +278,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
tokens: conv_theme(@scene.ThemeTokens::moon_night()),
screen_w: 0,
wallpaper_len: 0,
wallpaper_sel: 0,
desk_set: false,
desk_x: 0,
desk_y: 0,
@@ -765,7 +768,7 @@ pub fn DesktopShell::render(
@wasm.set_windows(self.win_list)
}
let bg : Array[@scene.DrawOp] = []
translate(@libshell.render_background(@ui.size(w, h), tokens), 0, 0, bg)
translate(@libshell.render_wallpaper(@ui.size(w, h), tokens, self.wallpaper_sel), 0, 0, bg)
self.wallpaper_len = bg.length()
let (dx, dy) = self.desk_pos()
render_desktop_widget(dx, dy, tokens, now(), bg)
+29 -4
View File
@@ -4,7 +4,8 @@
/// {:layout :tiling ; the Tile | Float switcher: :tiling, :monocle or :floating
/// :recent ["foot" "dolphin"] ; the launcher's recently started apps, newest first
/// :windows {"foot" {:x 80 :y 60 :w 640 :h 480}} ; floating windows' last place, by app id
/// :desktop-card {:x 900 :y 24}} ; where the desktop card was dragged to (absent: default spot)
/// :desktop-card {:x 900 :y 24} ; where the desktop card was dragged to (absent: default spot)
/// :wallpaper :aurora} ; the wallpaper module's choice (absent: :plasma-glow)
///
/// Saving merges into what is already in the file, so keys this build doesn't know (a future
/// widget's state, hand-written notes) survive. Everything is a no-op unless `persist` is on
@@ -19,6 +20,8 @@ pub(all) struct SavedState {
/// Top-left of the desktop card, when it was moved.
desk : (Int, Int)?
windows : Map[String, (Int, Int, Int, Int)]
/// Index into `@libshell.wallpaper_names`.
wallpaper : Int?
}
///|
@@ -30,7 +33,10 @@ fn state_path() -> String {
let layout_names : Array[String] = ["tiling", "monocle", "floating"]
///| The keys this build owns; everything else in the file is kept as it is.
let owned_keys : Array[String] = ["layout", "recent", "desktop-card", "windows"]
let owned_keys : Array[String] = ["layout", "recent", "desktop-card", "windows", "wallpaper"]
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
let wallpaper_keys : Array[String] = ["plasma-glow", "aurora", "starfield", "dusk", "solid"]
///|
fn read_state_file() -> Array[(@edn.Value, @edn.Value)] {
@@ -62,7 +68,7 @@ fn lookup_key(
///| Read state.edn. Without `persist` nothing is read.
pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
if !self.persist {
return { layout: None, recent: None, desk: None, windows: {} }
return { layout: None, recent: None, desk: None, windows: {}, wallpaper: None }
}
let entries = read_state_file()
let layout = match lookup_key(entries, "layout") {
@@ -135,7 +141,19 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
}
_ => ()
}
{ layout, recent, desk, windows }
let wallpaper = match lookup_key(entries, "wallpaper") {
Some(Keyword(k)) => {
let mut found : Int? = None
for i = 0; i < wallpaper_keys.length(); i = i + 1 {
if wallpaper_keys[i] == k {
found = Some(i)
}
}
found
}
_ => None
}
{ layout, recent, desk, windows, wallpaper }
}
///| Take the saved recents (the layout is the compositor's to apply).
@@ -143,6 +161,10 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
for app, g in st.windows {
self.win_geoms.set(app, g)
}
match st.wallpaper {
Some(i) => self.wallpaper_sel = i
None => ()
}
match st.desk {
Some((x, y)) => {
self.desk_set = true
@@ -211,6 +233,9 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
(@edn.Value::Keyword("y"), @edn.Value::Integer(y.to_string())),
])))
}
if self.wallpaper_sel > 0 && self.wallpaper_sel < wallpaper_keys.length() {
entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel])))
}
let body : String? = try Some(@edn.pretty(@edn.Value::Mapping(entries), layout={ width: 100, indent: 1 })) catch { _ => None }
match body {
Some(b) => {
+21 -1
View File
@@ -11,7 +11,7 @@
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
let default_panel : Array[String] = [
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "logout",
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "logout",
]
///| The module whose popup is the wasm picker.
@@ -382,6 +382,15 @@ 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")) {
let pt = @wasm.Table::new()
for n in @libshell.wallpaper_names {
pt.str(n)
pt.end_row()
}
@wasm.publish(Wallpapers, pt)
@wasm.publish_wallpaper(self.wallpaper_sel)
}
let it = @wasm.Table::new()
for w in self.widgets {
it.str(w.slot)
@@ -416,6 +425,16 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
}
}
///| Show wallpaper `i` (ignored when out of range) and remember it in state.edn.
pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
if i < 0 || i >= @libshell.wallpaper_names.length() || i == self.wallpaper_sel {
return
}
self.wallpaper_sel = i
@wasm.publish_wallpaper(i)
self.save_state()
}
///| Carry out what modules asked of the host during their last calls.
fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
while true {
@@ -436,6 +455,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(FocusWindow(n)) => self.actions.push(FocusWindow(n.to_int64().to_uint64()))
Some(SetLayout(m)) => self.actions.push(SetLayout(m))
Some(Logout) => self.actions.push(Logout)
Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetInspector(on)) => self.set_inspecting(on)
Some(LoadModule(path)) => {
match self.load_path(path) {
+9
View File
@@ -231,6 +231,7 @@ pub(all) enum HostTable {
Layouts
Modules
Instances
Wallpapers
}
///|
@@ -250,6 +251,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Layouts => 2U
Modules => 3U
Instances => 4U
Wallpapers => 5U
}
@hostpl.publish_table(id, out)
}
@@ -259,6 +261,11 @@ pub fn publish_state(layout_mode : Int, inspector_on : Bool) -> Unit {
@hostpl.publish_state(layout_mode, inspector_on)
}
///|
pub fn publish_wallpaper(current : Int) -> Unit {
@hostpl.publish_wallpaper(current)
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -269,6 +276,7 @@ pub(all) enum HostRequest {
UnloadInstance(String)
Browse
Logout
SetWallpaper(Int)
} derive(Eq, Debug)
///|
@@ -283,6 +291,7 @@ pub fn next_request() -> HostRequest? {
Some(UnloadInstance(s)) => Some(UnloadInstance(s))
Some(Browse) => Some(Browse)
Some(Logout) => Some(Logout)
Some(SetWallpaper(i)) => Some(SetWallpaper(i))
}
}
+9
View File
@@ -607,6 +607,7 @@ pub(all) enum HostTable {
Layouts
Modules
Instances
Wallpapers
}
///| Publish `t` as the data behind `which` for every module's next call.
@@ -617,6 +618,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Layouts => 2
Modules => 3
Instances => 4
Wallpapers => 5
}
let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 {
@@ -634,6 +636,11 @@ pub fn publish_state(layout_mode : Int, inspector_on : Bool) -> Unit {
c_host_set_int(1, if inspector_on { 1 } else { 0 })
}
///| Publish which wallpaper (an index into the Wallpapers table) is on the desktop.
pub fn publish_wallpaper(current : Int) -> Unit {
c_host_set_int(2, current)
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -644,6 +651,7 @@ pub(all) enum HostRequest {
UnloadInstance(String)
Browse
Logout
SetWallpaper(Int)
} derive(Eq, Debug)
///|
@@ -664,6 +672,7 @@ pub fn next_request() -> HostRequest? {
6 => Some(UnloadInstance(req_str()))
7 => Some(Browse)
8 => Some(Logout)
9 => Some(SetWallpaper(c_host_req_int()))
_ => None
}
}
+11 -3
View File
@@ -47,16 +47,16 @@ static Inst insts[MAX_INST];
enum {
K_OTHER, K_TOKENS, K_CLOCK, K_APPS, K_LAUNCH, K_WINDOWS, K_FOCUS, K_LAYOUTS, K_LAYOUT_CUR, K_SET_LAYOUT,
K_INSPECT_IS_ON, K_INSPECT_SET, K_MOD_AVAILABLE, K_MOD_LOADED, K_MOD_LOAD, K_MOD_UNLOAD, K_MOD_BROWSE,
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER
};
typedef struct Env { Inst *inst; int kind; } Env;
/* ---- host data the shell publishes before calling a guest ----
* A table is [u32 rows] then rows of fields, each field a LE i32 ('i') or a u32 byte length + UTF-8 ('s'). */
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_N };
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_N };
typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N];
static int32_t host_ints[4]; /* 0 layout mode, 1 inspector on */
static int32_t host_ints[4]; /* 0 layout mode, 1 inspector on, 2 current wallpaper */
/* ---- requests a guest made of the host (launch, focus, ...) ; drained by the shell after each call ---- */
typedef struct { int kind; int32_t n; char *s; } Req;
@@ -264,17 +264,22 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_APPS: build_list(in, T_APPS, "sssss", a0); break; /* id name comment category glyph */
case K_WINDOWS: build_list(in, T_WINDOWS, "isii", a0); break;
case K_LAYOUTS: build_list(in, T_LAYOUTS, "s", a0); break;
case K_WALLPAPERS: build_list(in, T_WALLPAPERS, "s", a0); break;
case K_MOD_AVAILABLE: build_list(in, T_MODULES, "sssi", a0); break;
case K_MOD_LOADED: build_list(in, T_INSTANCES, "sss", a0); break;
case K_LAYOUT_CUR:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[0]);
break;
case K_WALLPAPER_CUR:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[2]);
break;
case K_INSPECT_IS_ON:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[1]);
break;
case K_SET_LAYOUT: push_req(3, a0, NULL); break;
case K_FOCUS: push_req(2, a0, NULL); break;
case K_LOGOUT: push_req(8, 0, NULL); break;
case K_SET_WALLPAPER: push_req(9, a0, NULL); break;
case K_INSPECT_SET: push_req(4, a0, NULL); break;
case K_MOD_BROWSE: push_req(7, 0, NULL); break;
case K_MOD_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; }
@@ -403,6 +408,9 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "windows") && !strcmp(fn, "focus")) return K_WIN_FOCUS_ID;
if (!strcmp(iface, "system") && !strcmp(fn, "read")) return K_SYSTEM_READ;
if (!strcmp(iface, "session") && !strcmp(fn, "logout")) return K_LOGOUT;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "wallpapers")) return K_WALLPAPERS;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "current-wallpaper")) return K_WALLPAPER_CUR;
if (!strcmp(iface, "wallpaper") && !strcmp(fn, "set-wallpaper")) return K_SET_WALLPAPER;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "layout-modes")) return K_LAYOUTS;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "current-layout")) return K_LAYOUT_CUR;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT;