- 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:
37 files changed
+1311
-78
No files matched your search
@@ -35,6 +35,7 @@ pub enum Req {
|
||||
UnloadInstance(String),
|
||||
Browse,
|
||||
Logout,
|
||||
SetWallpaper(i32),
|
||||
}
|
||||
|
||||
pub const T_APPS: usize = 0;
|
||||
@@ -42,12 +43,14 @@ pub const T_WINDOWS: usize = 1;
|
||||
pub const T_LAYOUTS: usize = 2;
|
||||
pub const T_MODULES: usize = 3;
|
||||
pub const T_INSTANCES: usize = 4;
|
||||
pub const T_WALLPAPERS: usize = 5;
|
||||
|
||||
/// Host data every module reads from, shared by all loaded modules.
|
||||
#[derive(Default)]
|
||||
pub struct Shared {
|
||||
pub tables: [Vec<u8>; 5],
|
||||
pub tables: [Vec<u8>; 6],
|
||||
pub layout_mode: i32,
|
||||
pub wallpaper: i32,
|
||||
pub inspector_on: bool,
|
||||
pub system: Option<d::system::Snapshot>,
|
||||
/// (id, title, app id, focused)
|
||||
@@ -273,6 +276,18 @@ impl d::session::Host for PState {
|
||||
}
|
||||
}
|
||||
|
||||
impl d::wallpaper::Host for PState {
|
||||
fn wallpapers(&mut self) -> Vec<String> {
|
||||
self.rows(T_WALLPAPERS, "s").iter().map(|r| s(&r[0])).collect()
|
||||
}
|
||||
fn current_wallpaper(&mut self) -> u32 {
|
||||
self.shared.borrow().wallpaper.max(0) as u32
|
||||
}
|
||||
fn set_wallpaper(&mut self, index: u32) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::SetWallpaper(index as i32));
|
||||
}
|
||||
}
|
||||
|
||||
impl d::system::Host for PState {
|
||||
fn read(&mut self) -> d::system::Snapshot {
|
||||
self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot {
|
||||
@@ -562,4 +577,38 @@ mod tests {
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::Logout)));
|
||||
rt.unload(h);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wallpaper_module_lists_the_wallpapers_and_requests_a_switch() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("wallpaper")).expect("wallpaper loads");
|
||||
assert!(l.imports.contains(&"wallpaper".to_string()));
|
||||
let h = l.handle;
|
||||
let names = ["Plasma glow", "Aurora", "Starfield"];
|
||||
let mut t = (names.len() as u32).to_le_bytes().to_vec();
|
||||
for n in names {
|
||||
t.extend((n.len() as u32).to_le_bytes());
|
||||
t.extend(n.as_bytes());
|
||||
}
|
||||
rt.shared.borrow_mut().tables[T_WALLPAPERS] = t;
|
||||
rt.shared.borrow_mut().wallpaper = 1;
|
||||
assert!(texts(&rt.render(h, Size { w: 96, h: 34 })).contains(&"Wallpaper".to_string()));
|
||||
// A click opens the list of every wallpaper; nothing is requested yet.
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
|
||||
let p = rt.popup(h).expect("popup open");
|
||||
for n in names {
|
||||
assert!(texts(&p.ops).contains(&n.to_string()), "{n} listed");
|
||||
}
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
// Third row: Starfield.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 2 * 30 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetWallpaper(2))));
|
||||
// The list stays open; Escape closes it without another request.
|
||||
assert!(rt.popup(h).is_some());
|
||||
assert!(rt.on_event(h, true, InputEvent::KeyDown("Escape".to_string())));
|
||||
assert!(rt.popup(h).is_none());
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
rt.unload(h);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user