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

+4
View File
@@ -11,6 +11,10 @@ pub fn render_background(@types.Size, @theme.Tokens) -> Array[@types.DrawOp]
pub fn render_panel(@types.Rect, @theme.Tokens) -> Array[@types.DrawOp]
pub fn render_wallpaper(@types.Size, @theme.Tokens, Int32) -> Array[@types.DrawOp]
pub let wallpaper_names : Array[String]
// Errors
// Types and methods
+167 -13
View File
@@ -1,26 +1,49 @@
///| Desktop background and panel chrome (pure render logic).
///| Vertical gradient built from horizontal bands, a soft "plasma" glow and a
/// wordmark. Everything derives from theme tokens.
///| The wallpapers the shell can draw, in choice order (what `wallpaper.wallpapers` lists).
pub let wallpaper_names : Array[String] = ["Plasma glow", "Aurora", "Starfield", "Dusk", "Solid"]
///| The default desktop background: wallpaper 0, "Plasma glow".
pub fn render_background(
screen : @types.Size,
t : @theme.Tokens,
) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let p = t.palette
let bands = 48
let ops = []
render_wallpaper(screen, t, 0)
}
///| Draw wallpaper `index` (see `wallpaper_names`) to fill `screen`; an unknown index draws wallpaper 0.
/// Everything is draw ops, coloured from the theme (Dusk keeps its own warm colours), so a
/// theme swap recolours the wallpaper too.
pub fn render_wallpaper(
screen : @types.Size,
t : @theme.Tokens,
index : Int,
) -> Array[@types.DrawOp] {
match index {
1 => aurora(screen, t)
2 => starfield(screen, t)
3 => dusk(screen)
4 => [@ui.fill_rect(@ui.rect(0, 0, screen.w.reinterpret_as_int(), screen.h.reinterpret_as_int()), t.palette.desktop_bottom)]
_ => plasma_glow(screen, t)
}
}
///| `bands` horizontal strips blending `top` into `bottom`.
fn gradient(w : Int, h : Int, top : @types.Color, bottom : @types.Color, bands : Int, ops : Array[@types.DrawOp]) -> Unit {
for i = 0; i < bands; i = i + 1 {
let y0 = h * i / bands
let y1 = h * (i + 1) / bands
ops.push(
@ui.fill_rect(
@ui.rect(0, y0, w, y1 - y0 + 1),
@ui.lerp_color(p.desktop_top, p.desktop_bottom, i, bands - 1),
),
)
ops.push(@ui.fill_rect(@ui.rect(0, y0, w, y1 - y0 + 1), @ui.lerp_color(top, bottom, i, bands - 1)))
}
}
///|
fn plasma_glow(screen : @types.Size, t : @theme.Tokens) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let p = t.palette
let ops = []
gradient(w, h, p.desktop_top, p.desktop_bottom, 48, ops)
// Plasma glow: concentric translucent discs.
let gx = w * 3 / 4
let gy = h * 3 / 10
@@ -47,6 +70,109 @@ pub fn render_background(
ops
}
///| sin(2*pi*num/den) * 1000, by Bhaskara I's approximation (good to about 0.2%).
fn sin_milli(num : Int, den : Int) -> Int {
let d = if den > 0 { den } else { 1 }
let mut t = num % d
if t < 0 {
t = t + d
}
// Angle in degrees, 0..359, then fold the second half onto the first with a sign flip.
let deg = t * 360 / d
let (x, sign) = if deg < 180 { (deg, 1) } else { (deg - 180, -1) }
sign * 4000 * x * (180 - x) / (40500 - x * (180 - x))
}
///| Curtains of light across the upper sky, like northern lights: each ribbon is a wave of thin
/// vertical strokes whose colour fades out above and below the crest.
fn aurora(screen : @types.Size, t : @theme.Tokens) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let p = t.palette
let ops = []
gradient(w, h, p.desktop_top, p.desktop_bottom, 48, ops)
let col = 4
let layers = 5
let ribbons = 3
for k = 0; k < ribbons; k = k + 1 {
let base = h * (22 + k * 11) / 100
let amp = h * (5 + k * 2) / 100
let period = w * (3 + k) / 4 + 1
let thick = h * (14 - k * 3) / 100
let tint = @ui.lerp_color(p.accent, p.foreground, k, ribbons)
let mut x = 0
while x < w {
let crest = base + sin_milli(x + k * period / 3, period) * amp / 1000
// The curtain hangs from the crest; its height breathes along the ribbon.
let len = thick * (1000 + sin_milli(x * 2 + k * 97, period) / 2) / 1000
for j = 0; j < layers; j = j + 1 {
let y0 = crest + len * j / layers
let y1 = crest + len * (j + 1) / layers
let alpha = (56 - k * 12) * (layers - j) / layers
ops.push(@ui.fill_rect(@ui.rect(x, y0, col, y1 - y0), @ui.with_alpha(tint, alpha)))
}
x = x + col
}
}
ops
}
///| A small deterministic pseudo-random generator (the same stars every frame).
fn next_rand(seed : Int) -> Int {
(seed * 1103515245 + 12345) & 0x7fffffff
}
///| A night sky: scattered stars and a crescent moon.
fn starfield(screen : @types.Size, t : @theme.Tokens) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let p = t.palette
let ops = []
let night = @ui.lerp_color(p.desktop_top, @ui.color(0, 0, 0, 255), 1, 2)
gradient(w, h, night, p.desktop_top, 32, ops)
let n = (w / 16) * (h / 16) / 12 + 20
let mut seed = 20261125
for i = 0; i < n; i = i + 1 {
seed = next_rand(seed)
let x = seed % (if w > 0 { w } else { 1 })
seed = next_rand(seed)
let y = seed % (if h > 0 { h } else { 1 })
seed = next_rand(seed)
let bright = 90 + seed % 166
let r = if i % 17 == 0 { 2 } else { 1 }
ops.push(@ui.circle(x, y, r, @ui.with_alpha(p.foreground, bright)))
}
// Crescent: a bright disc with a sky-coloured disc over it.
let mx = w / 5
let my = h / 4
ops.push(@ui.circle(mx, my, 64, @ui.with_alpha(p.foreground, 18)))
ops.push(@ui.circle(mx, my, 40, @ui.with_alpha(p.foreground, 230)))
ops.push(@ui.circle(mx + 16, my - 10, 36, @ui.lerp_color(night, p.desktop_top, my, h)))
ops
}
///| A warm sunset: violet sky over orange, a low sun and hills, independent of the theme.
fn dusk(screen : @types.Size) -> Array[@types.DrawOp] {
let w = screen.w.reinterpret_as_int()
let h = screen.h.reinterpret_as_int()
let ops = []
let sky = @ui.color(46, 32, 84, 255)
let glow = @ui.color(240, 128, 84, 255)
gradient(w, h * 7 / 10, sky, glow, 40, ops)
// The sun, half set, with a halo.
let sx = w * 2 / 3
let sy = h * 7 / 10
for i = 0; i < 5; i = i + 1 {
ops.push(@ui.circle(sx, sy, 70 + (5 - i) * 24, @ui.color(255, 196, 120, 12 + i * 5)))
}
ops.push(@ui.circle(sx, sy, 64, @ui.color(255, 214, 140, 255)))
// Ground, then two hills on top of it.
ops.push(@ui.fill_rect(@ui.rect(0, h * 7 / 10, w, h - h * 7 / 10), @ui.color(44, 24, 52, 255)))
ops.push(@ui.circle(w / 4, h * 7 / 10 + h / 3, h / 2, @ui.color(60, 32, 68, 255)))
ops.push(@ui.circle(w * 9 / 10, h * 7 / 10 + h / 2, h * 3 / 5, @ui.color(36, 20, 44, 255)))
ops
}
///|
pub fn render_panel(
panel : @types.Rect,
@@ -102,3 +228,31 @@ test "background gradient covers the screen top to bottom" {
_ => fail("expected fill")
}
}
///|
test "every wallpaper fills the screen and an unknown index falls back to the first" {
let t = test_tokens()
let screen = @ui.size(640, 400)
for i = 0; i < wallpaper_names.length(); i = i + 1 {
let ops = render_wallpaper(screen, t, i)
assert_true(ops.length() > 0)
// The first op paints from the top-left corner across the full width.
match ops[0] {
FillRect(f) => {
assert_eq(f.rect.x, 0)
assert_eq(f.rect.y, 0)
assert_eq(f.rect.w.reinterpret_as_int(), 640)
}
_ => fail("wallpaper \{i} should start with a fill")
}
}
// (DrawOp has no Eq: compare op counts.)
let glow = render_wallpaper(screen, t, 0).length()
assert_eq(render_wallpaper(screen, t, 99).length(), glow)
assert_eq(render_wallpaper(screen, t, -1).length(), glow)
assert_eq(render_background(screen, t).length(), glow)
// Different choices draw different things.
assert_true(render_wallpaper(screen, t, 1).length() != glow)
assert_true(render_wallpaper(screen, t, 2).length() != glow)
assert_eq(render_wallpaper(screen, t, 4).length(), 1)
}