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
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user