Restore the session on login: reopen the windows the last session ended with
CI / test (push) Failing after 20s

- state.edn gets :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]: the open
  windows by app id, in opening order, with whether each was minimized or maximized. Dialogs
  (xdg_toplevel.set_parent, now tracked by the Wayland server) are left out.
- Written at the end of a session (logout, or the display/window going away) and, against
  crashes, whenever the set of windows changes and then holds for 3 s; that delay also keeps a
  shutdown, where apps die a moment before the compositor, from saving an empty desktop.
- At start (both the native binary and the wasm compositor) each saved app is launched through
  its .desktop file: the app id is matched to the desktop file id, StartupWMClass (now parsed),
  case-insensitively, or by its last dotted part. Restored apps don't count as recent launches.
  A launched app stays in the session until its window shows up (30 s at most), and that window
  gets its minimized/maximized state back; placement is the existing layout mode and per-app
  floating geometry.
- --no-restore, or :restore-session false in state.edn, starts with an empty desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjkHnYqipToGkWFC9P
This commit is contained in:
Claude committed 2026-11-25 18:31:31 +00:00
1 parent f7f90e1c41
commit 46780c399b
10 files changed
+435 -2

No files matched your search

+63 -1
View File
@@ -8,6 +8,8 @@ priv struct DesktopApp {
comment : String
category : String
command : String
/// StartupWMClass: the app id its windows carry when that is not the desktop file's name.
wm_class : String
}
///| Directories scanned, lowest priority first (later ones override by file name).
@@ -63,6 +65,7 @@ fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp
let mut hidden = false
let mut terminal = false
let mut kind = "Application"
let mut wm_class = ""
for raw in text.split("\n") {
let line = raw.trim(chars=" \r\t").to_string()
if line.length() == 0 || line.has_prefix("#") {
@@ -89,6 +92,7 @@ fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp
"Type" => kind = val
"NoDisplay" | "Hidden" => if val == "true" { hidden = true }
"Terminal" => terminal = val == "true"
"StartupWMClass" => wm_class = val
_ => ()
}
}
@@ -109,7 +113,7 @@ fn parse_desktop(id : String, text : String, have_terminal : Bool) -> DesktopApp
_ => "Other"
}
let comment = if comment.length() > 0 { comment } else { generic }
Some({ id, name, comment, category, command })
Some({ id, name, comment, category, command, wm_class })
}
///| Scan every applications dir; later dirs override earlier ones, result sorted by name.
@@ -158,9 +162,67 @@ test "parse_desktop reads a normal entry and strips field codes" {
}
}
///|
test "parse_desktop keeps StartupWMClass" {
let t = "[Desktop Entry]\nType=Application\nName=Code\nExec=code %F\nStartupWMClass=Code\n"
match parse_desktop("visual-studio-code", t, true) {
Some(a) => assert_eq(a.wm_class, "Code")
None => fail("expected entry")
}
}
///|
test "parse_desktop hides NoDisplay entries" {
let t = "[Desktop Entry]\nType=Application\nName=X\nExec=x\nNoDisplay=true\n"
assert_true(parse_desktop("x", t, true) is None)
}
///| The desktop file id that launches the app whose windows carry `app_id`: the file of that
/// name, else one whose StartupWMClass is it, else a case-insensitive match on either, else one
/// whose last dotted part matches (a window "nautilus" for org.gnome.Nautilus.desktop).
fn resolve_app_id(
app_id : String,
exec : Map[String, String],
wm_classes : Map[String, String],
) -> String? {
if app_id.length() == 0 {
return None
}
if exec.contains(app_id) {
return Some(app_id)
}
let low = app_id.to_lower()
match wm_classes.get(low) {
Some(id) => return Some(id)
None => ()
}
for id, _ in exec {
if id.to_lower() == low {
return Some(id)
}
}
for id, _ in exec {
let parts : Array[String] = id.split(".").map(x => x.to_string()).collect()
if parts.length() > 1 && parts[parts.length() - 1].to_lower() == low {
return Some(id)
}
}
None
}
///|
test "resolve_app_id finds the desktop file for a window's app id" {
let exec : Map[String, String] = {
"foot": "foot",
"org.gnome.Nautilus": "nautilus --new-window",
"visual-studio-code": "code",
}
let wm : Map[String, String] = { "code": "visual-studio-code" }
assert_eq(resolve_app_id("foot", exec, wm), Some("foot"))
assert_eq(resolve_app_id("Code", exec, wm), Some("visual-studio-code"))
assert_eq(resolve_app_id("org.gnome.nautilus", exec, wm), Some("org.gnome.Nautilus"))
assert_eq(resolve_app_id("nautilus", exec, wm), Some("org.gnome.Nautilus"))
assert_eq(resolve_app_id("unknown", exec, wm), None)
assert_eq(resolve_app_id("", exec, wm), None)
}