Session settings panel module: switch session restore and window placement on or off
CI / test (push) Failing after 16s
CI / test (push) Failing after 16s
- New 'session-settings' capability (wit/capabilities.wit: settings, is-on, set-setting) and 'session-settings' panel module: a "Session" button whose popup lists the session settings, each with an on/off switch. Clicking a row flips it at once (the list stays open); Up/Down move the highlight, Enter or Space flips it, Escape or a click elsewhere closes. In the default panel, between Wallpaper and Log out. - Two settings to start with, kept in state.edn and written only when off (absent means on): "Reopen windows at login" (:restore-session, the key session restore already read) and "Remember window positions" (:remember-windows; when off, floating windows aren't placed where their app was left and new places aren't recorded, but the saved ones are kept). - Served by both hosts: wasmer stub (native; settings table 6, bit mask in host int 3, requests 10/11) and host-wasm (publish-session-settings, set-session-setting request). - Tests: native end-to-end (open, click both rows, keyboard, Escape), a state.edn round trip that checks both settings take effect, and a host-wasm module test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
32 files changed
+1192
-44
No files matched your search
@@ -183,6 +183,10 @@ impl chandra::host::plasmoids::Host for State {
|
||||
self.pl().shared.borrow_mut().wallpaper = current;
|
||||
}
|
||||
|
||||
fn publish_session_settings(&mut self, on: u32) {
|
||||
self.pl().shared.borrow_mut().session_settings = on;
|
||||
}
|
||||
|
||||
fn publish_system(&mut self, s: chandra::host::plasmoids::SystemSnapshot) {
|
||||
use plasmoid::ph::chandra::desktop::system::Snapshot;
|
||||
self.pl().shared.borrow_mut().system = Some(Snapshot {
|
||||
@@ -217,6 +221,9 @@ impl chandra::host::plasmoids::Host for State {
|
||||
Req::Browse => R::Browse,
|
||||
Req::Logout => R::Logout,
|
||||
Req::SetWallpaper(n) => R::SetWallpaper(n),
|
||||
Req::SetSessionSetting(index, on) => {
|
||||
R::SetSessionSetting(chandra::host::plasmoids::SettingChange { index, on })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ pub enum Req {
|
||||
Browse,
|
||||
Logout,
|
||||
SetWallpaper(i32),
|
||||
SetSessionSetting(i32, bool),
|
||||
}
|
||||
|
||||
pub const T_APPS: usize = 0;
|
||||
@@ -44,13 +45,16 @@ pub const T_LAYOUTS: usize = 2;
|
||||
pub const T_MODULES: usize = 3;
|
||||
pub const T_INSTANCES: usize = 4;
|
||||
pub const T_WALLPAPERS: usize = 5;
|
||||
pub const T_SESSION_SETTINGS: usize = 6;
|
||||
|
||||
/// Host data every module reads from, shared by all loaded modules.
|
||||
#[derive(Default)]
|
||||
pub struct Shared {
|
||||
pub tables: [Vec<u8>; 6],
|
||||
pub tables: [Vec<u8>; 7],
|
||||
pub layout_mode: i32,
|
||||
pub wallpaper: i32,
|
||||
/// Which session settings are on: bit i for row i of the session settings table.
|
||||
pub session_settings: u32,
|
||||
pub inspector_on: bool,
|
||||
pub system: Option<d::system::Snapshot>,
|
||||
/// (id, title, app id, focused)
|
||||
@@ -288,6 +292,18 @@ impl d::wallpaper::Host for PState {
|
||||
}
|
||||
}
|
||||
|
||||
impl d::session_settings::Host for PState {
|
||||
fn settings(&mut self) -> Vec<String> {
|
||||
self.rows(T_SESSION_SETTINGS, "s").iter().map(|r| s(&r[0])).collect()
|
||||
}
|
||||
fn is_on(&mut self, index: u32) -> bool {
|
||||
index < 32 && (self.shared.borrow().session_settings >> index) & 1 == 1
|
||||
}
|
||||
fn set_setting(&mut self, index: u32, on: bool) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::SetSessionSetting(index as i32, on));
|
||||
}
|
||||
}
|
||||
|
||||
impl d::system::Host for PState {
|
||||
fn read(&mut self) -> d::system::Snapshot {
|
||||
self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot {
|
||||
@@ -611,4 +627,39 @@ mod tests {
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
rt.unload(h);
|
||||
}
|
||||
#[test]
|
||||
fn session_settings_module_shows_switches_and_requests_a_flip() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("session-settings")).expect("session-settings loads");
|
||||
assert!(l.imports.contains(&"session-settings".to_string()));
|
||||
let h = l.handle;
|
||||
let names = ["Reopen windows at login", "Remember window positions"];
|
||||
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_SESSION_SETTINGS] = t;
|
||||
rt.shared.borrow_mut().session_settings = 0b01; // reopen on, remember off
|
||||
assert!(texts(&rt.render(h, Size { w: 86, h: 34 })).contains(&"Session".to_string()));
|
||||
// A click opens the list of every setting; 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());
|
||||
// First row is on: a click asks to turn it off. Second row is off: a click asks for on.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(0, false))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 6 + 32 + 5 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(1, true))));
|
||||
// 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