Session settings panel module: switch session restore and window placement on or off
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:
Claude committed 2026-11-25 18:43:27 +00:00
1 parent c169489d44
commit a0b878af23
32 files changed
+1192 -44

No files matched your search

+6
View File
@@ -202,6 +202,10 @@ pub(all) struct DesktopShell {
mut wallpaper_len : Int
/// Which wallpaper is drawn (an index into `@libshell.wallpaper_names`); the wallpaper module sets it.
mut wallpaper_sel : Int
/// Session settings (the session settings module flips them; saved in state.edn): reopen the
/// last session's windows at the next start, and remember where floating windows were left.
mut restore_session : Bool
mut remember_windows : Bool
mut desk_set : Bool
mut desk_x : Int
mut desk_y : Int
@@ -286,6 +290,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
screen_w: 0,
wallpaper_len: 0,
wallpaper_sel: 0,
restore_session: true,
remember_windows: true,
desk_set: false,
desk_x: 0,
desk_y: 0,
+50 -6
View File
@@ -9,7 +9,9 @@
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
/// ; the windows open when the last session ended, reopened at
/// ; the next start (see session.mbt in compositor/host)
/// :restore-session false} ; hand-written: don't reopen them (absent: reopen)
/// :restore-session false ; don't reopen them (absent: reopen); the session settings module
/// ; or a hand edit sets it
/// :remember-windows false} ; don't place windows where they were left (absent: do)
///
/// 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
@@ -26,6 +28,9 @@ pub(all) struct SavedState {
windows : Map[String, (Int, Int, Int, Int)]
/// Index into `@libshell.wallpaper_names`.
wallpaper : Int?
/// Session settings; None when the file doesn't say (both default to on).
restore_session : Bool?
remember_windows : Bool?
}
///|
@@ -37,7 +42,9 @@ 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", "wallpaper"]
let owned_keys : Array[String] = [
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
]
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
let wallpaper_keys : Array[String] = ["plasma-glow", "aurora", "starfield", "dusk", "solid"]
@@ -72,7 +79,15 @@ 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: {}, wallpaper: None }
return {
layout: None,
recent: None,
desk: None,
windows: {},
wallpaper: None,
restore_session: None,
remember_windows: None,
}
}
let entries = read_state_file()
let layout = match lookup_key(entries, "layout") {
@@ -157,7 +172,21 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
}
_ => None
}
{ layout, recent, desk, windows, wallpaper }
let flag = fn(k : String) -> Bool? {
match lookup_key(entries, k) {
Some(Bool(b)) => Some(b)
_ => None
}
}
{
layout,
recent,
desk,
windows,
wallpaper,
restore_session: flag("restore-session"),
remember_windows: flag("remember-windows"),
}
}
///| Take the saved recents (the layout is the compositor's to apply).
@@ -169,6 +198,14 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
Some(i) => self.wallpaper_sel = i
None => ()
}
match st.restore_session {
Some(b) => self.restore_session = b
None => ()
}
match st.remember_windows {
Some(b) => self.remember_windows = b
None => ()
}
match st.desk {
Some((x, y)) => {
self.desk_set = true
@@ -240,6 +277,13 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
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])))
}
// Session settings are written only when off: absent means on, as for a hand-written file.
if !self.remember_windows {
entries.insert(2, (@edn.Value::Keyword("remember-windows"), @edn.Value::Bool(false)))
}
if !self.restore_session {
entries.insert(2, (@edn.Value::Keyword("restore-session"), @edn.Value::Bool(false)))
}
write_state_file(entries)
}
@@ -278,7 +322,7 @@ fn parse_int_str(s : String) -> Int? {
///| Remember where an app's window was left (a no-op without an app id) and save.
pub fn DesktopShell::remember_window(self : DesktopShell, app_id : String, x : Int, y : Int, w : Int, h : Int) -> Unit {
if app_id.length() == 0 || w <= 0 || h <= 0 {
if app_id.length() == 0 || w <= 0 || h <= 0 || !self.remember_windows {
return
}
self.win_geoms.set(app_id, (x, y, w, h))
@@ -287,7 +331,7 @@ pub fn DesktopShell::remember_window(self : DesktopShell, app_id : String, x : I
///| The saved place of an app's window, if persistence is on and one was saved.
pub fn DesktopShell::saved_window(self : DesktopShell, app_id : String) -> (Int, Int, Int, Int)? {
if self.persist { self.win_geoms.get(app_id) } else { None }
if self.persist && self.remember_windows { self.win_geoms.get(app_id) } else { None }
}
///| One window of a saved session: the app id its window carried and how it was left.
+31 -1
View File
@@ -11,7 +11,8 @@
///| 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", "wallpaper", "logout",
"launcher", "inspector", "layout", "tasks", "moon-disc", "clock-digital12", "wallpaper", "session-settings",
"logout",
]
///| The module whose popup is the wasm picker.
@@ -391,6 +392,15 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
@wasm.publish(Wallpapers, pt)
@wasm.publish_wallpaper(self.wallpaper_sel)
}
if self.widgets.iter().any(w => w.has_cap("session-settings")) {
let st = @wasm.Table::new()
for n in session_setting_names {
st.str(n)
st.end_row()
}
@wasm.publish(SessionSettings, st)
@wasm.publish_session_settings(self.session_settings_bits())
}
let it = @wasm.Table::new()
for w in self.widgets {
it.str(w.slot)
@@ -435,6 +445,25 @@ pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
self.save_state()
}
///| The session settings the session settings module lists, in index order.
let session_setting_names : Array[String] = ["Reopen windows at login", "Remember window positions"]
///| Which session settings are on: bit i for `session_setting_names[i]`.
fn DesktopShell::session_settings_bits(self : DesktopShell) -> Int {
(if self.restore_session { 1 } else { 0 }) | (if self.remember_windows { 2 } else { 0 })
}
///| Turn session setting `i` on or off (ignored when out of range) and remember it in state.edn.
pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool) -> Unit {
match i {
0 => self.restore_session = on
1 => self.remember_windows = on
_ => return
}
@wasm.publish_session_settings(self.session_settings_bits())
self.save_state()
}
///| Carry out what modules asked of the host during their last calls.
fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
while true {
@@ -456,6 +485,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(SetLayout(m)) => self.actions.push(SetLayout(m))
Some(Logout) => self.actions.push(Logout)
Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
Some(SetInspector(on)) => self.set_inspecting(on)
Some(LoadModule(path)) => {
match self.load_path(path) {