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

+72
View File
@@ -1253,3 +1253,75 @@ test "the open windows are saved as the session and a restored app's window gets
assert_eq(b.shell.load_session().length(), 0)
}
}
///|
test "the session settings module flips the session settings from its popup" {
let comp = new_comp("sessset")
let slot = comp.shell.slot_of("session-settings")
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
assert_true(comp.shell.restore_session)
assert_true(comp.shell.remember_windows)
// A click opens the list of switches; nothing changes yet.
click_module(comp, "session-settings", 1U)
let pr = comp.shell.slot_popup_rect(slot)
assert_true(pr.h >= 6 * 2 + 2 * 32) // one row per setting
assert_true(comp.shell.restore_session)
// First row: "Reopen windows at login" goes off, and on again with a second click.
click_at(comp, pr.x + 40, pr.y + 6 + 5, 5U)
assert_false(comp.shell.restore_session)
assert_true(comp.shell.remember_windows)
assert_true(comp.shell.slot_popup_rect(slot).w > 0) // the list stays open
click_at(comp, pr.x + 40, pr.y + 6 + 5, 10U)
assert_true(comp.shell.restore_session)
// Second row: "Remember window positions"; then Down and Enter flip it back from the keyboard.
click_at(comp, pr.x + 40, pr.y + 6 + 32 + 5, 15U)
assert_false(comp.shell.remember_windows)
comp.shell.key_down("Enter")
ignore(comp.compose_frame())
assert_true(comp.shell.remember_windows)
assert_true(comp.shell.restore_session)
comp.shell.key_down("Escape")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
// Out-of-range settings are ignored.
comp.shell.set_session_setting(7, false)
assert_true(comp.shell.restore_session && comp.shell.remember_windows)
}
///|
test "session settings are saved to state.edn and restored, and take effect" {
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\" :session [{:app \"foot\"}]}\n")
let a = new_comp("sess-a")
a.shell.persist = true
a.restore_state()
assert_true(a.shell.restore_session) // absent: on
assert_eq(a.shell.load_session().length(), 1)
a.shell.remember_window("foot", 10, 20, 300, 200)
assert_eq(a.shell.saved_window("foot"), Some((10, 20, 300, 200)))
// Turning them off writes them, keeps the other keys, and stops reopening and placing.
a.shell.set_session_setting(0, false)
a.shell.set_session_setting(1, false)
let text = read_state_edn()
assert_true(text.contains(":restore-session false"))
assert_true(text.contains(":remember-windows false"))
assert_true(text.contains(":note \"keep\""))
assert_true(text.contains(":session"))
assert_eq(a.shell.load_session().length(), 0)
assert_eq(a.shell.saved_window("foot"), None)
a.shell.remember_window("foot", 50, 60, 300, 200) // not recorded while off
let b = new_comp("sess-b")
b.shell.persist = true
b.restore_state()
assert_false(b.shell.restore_session)
assert_false(b.shell.remember_windows)
// On again: the keys go away (absent means on), and the old place is still known.
b.shell.set_session_setting(0, true)
b.shell.set_session_setting(1, true)
let text2 = read_state_edn()
assert_false(text2.contains(":restore-session"))
assert_false(text2.contains(":remember-windows"))
assert_eq(b.shell.load_session().length(), 1)
assert_eq(b.shell.saved_window("foot"), Some((10, 20, 300, 200)))
}
}
+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) {
+10
View File
@@ -232,6 +232,7 @@ pub(all) enum HostTable {
Modules
Instances
Wallpapers
SessionSettings
}
///|
@@ -252,6 +253,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Modules => 3U
Instances => 4U
Wallpapers => 5U
SessionSettings => 6U
}
@hostpl.publish_table(id, out)
}
@@ -266,6 +268,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
@hostpl.publish_wallpaper(current)
}
///| Which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
@hostpl.publish_session_settings(on.reinterpret_as_uint())
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -277,6 +284,8 @@ pub(all) enum HostRequest {
Browse
Logout
SetWallpaper(Int)
/// Turn session setting `index` on or off.
SetSessionSetting(Int, Bool)
} derive(Eq, Debug)
///|
@@ -292,6 +301,7 @@ pub fn next_request() -> HostRequest? {
Some(Browse) => Some(Browse)
Some(Logout) => Some(Logout)
Some(SetWallpaper(i)) => Some(SetWallpaper(i))
Some(SetSessionSetting(c)) => Some(SetSessionSetting(c.index, c.on))
}
}
+11
View File
@@ -608,6 +608,7 @@ pub(all) enum HostTable {
Modules
Instances
Wallpapers
SessionSettings
}
///| Publish `t` as the data behind `which` for every module's next call.
@@ -619,6 +620,7 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Modules => 3
Instances => 4
Wallpapers => 5
SessionSettings => 6
}
let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 {
@@ -641,6 +643,11 @@ pub fn publish_wallpaper(current : Int) -> Unit {
c_host_set_int(2, current)
}
///| Publish which session settings are on: bit i for row i of the SessionSettings table.
pub fn publish_session_settings(on : Int) -> Unit {
c_host_set_int(3, on)
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -652,6 +659,8 @@ pub(all) enum HostRequest {
Browse
Logout
SetWallpaper(Int)
/// Turn session setting `index` on or off.
SetSessionSetting(Int, Bool)
} derive(Eq, Debug)
///|
@@ -673,6 +682,8 @@ pub fn next_request() -> HostRequest? {
7 => Some(Browse)
8 => Some(Logout)
9 => Some(SetWallpaper(c_host_req_int()))
10 => Some(SetSessionSetting(c_host_req_int(), false))
11 => Some(SetSessionSetting(c_host_req_int(), true))
_ => None
}
}
+13 -3
View File
@@ -47,16 +47,17 @@ 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_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
K_SESSION_SETTINGS, K_SESSION_IS_ON, K_SESSION_SET
};
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_WALLPAPERS, T_N };
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, 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, 2 current wallpaper */
static int32_t host_ints[4]; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i) */
/* ---- 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;
@@ -265,6 +266,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
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_SESSION_SETTINGS: build_list(in, T_SESSION_SETTINGS, "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:
@@ -273,6 +275,10 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_WALLPAPER_CUR:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[2]);
break;
case K_SESSION_IS_ON:
if (results->size >= 1)
results->data[0] = (wasm_val_t)WASM_I32_VAL(a0 >= 0 && a0 < 32 ? (int32_t)(((uint32_t)host_ints[3] >> a0) & 1u) : 0);
break;
case K_INSPECT_IS_ON:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[1]);
break;
@@ -280,6 +286,7 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
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_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
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; }
@@ -411,6 +418,9 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
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, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;
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;