Lock: add session lock from power button and chandra-ctl lock
CI / test (push) Waiting to run

- Lock the session from the power button or `chandra-ctl lock`
- Unlock with a face or the password; the password always works
- Add compositor lock module with tests, and a polkit unlock policy (org.chandra.unlock)
- Document the lock flow in docs/lock.md and link it from the README
- Add generated interface bindings for the compositor and widget components
This commit is contained in:
nandi committed 2026-11-29 03:24:46 -08:00
1 parent 7501fc3ad9
commit c790f96e58
131 files changed
+4693 -274

No files matched your search

+59 -6
View File
@@ -35,9 +35,10 @@ fn fresh_panel(has_battery : Bool) -> Array[String] {
}
///| Compact default panel for handsets (omits desktop-only inspector, tiling toggle, and moon
/// disc so the dock, launcher, settings, Wi-Fi, battery, clock, and screenshot have room).
/// disc so the dock, launcher, settings, Wi-Fi, battery, clock, screenshot, rotate, and osk have room).
let handset_panel : Array[String] = [
"launcher", "dock", "session-settings", "network", "battery", "clock-digital", "screenshot",
"rotate", "osk",
]
///| Whether a fresh session runs on a handset chassis (tests keep the desktop layout).
@@ -55,6 +56,24 @@ test "a fresh panel gets the battery module only on a machine with a battery" {
assert_eq(p.search("battery").unwrap() + 1, p.search("clock-digital").unwrap())
}
///|
test "handset panel includes rotate and osk and v2 handset migration appends them once" {
assert_eq(handset_panel[handset_panel.length() - 2], "rotate")
assert_eq(handset_panel[handset_panel.length() - 1], "osk")
assert_eq(
migrate_handset_panel(["launcher", "dock", "clock-digital"]),
["launcher", "dock", "clock-digital", "rotate", "osk"],
)
assert_eq(
migrate_handset_panel(["launcher", "osk", "dock"]),
["launcher", "osk", "dock", "rotate"],
)
assert_eq(
migrate_handset_panel(["launcher", "rotate", "osk"]),
["launcher", "rotate", "osk"],
)
}
///| Modules folded into another one: old id -> the module that took over. The old id still
/// works everywhere a module is named (saved panels, load_module), it is just never listed:
/// a stale build/components/clock-digital12.wasm or an old installed copy stays out of the picker.
@@ -217,7 +236,9 @@ fn DesktopShell::panel_slots(self : DesktopShell) -> Array[@panel.SlotIn] {
(w.module_id == "launcher" ||
w.module_id == "session-settings" ||
w.module_id == "network" ||
w.module_id == "screenshot") {
w.module_id == "screenshot" ||
w.module_id == "rotate" ||
w.module_id == "osk") {
36
} else {
base_w
@@ -357,6 +378,19 @@ test "a saved panel's Log out button folds into the launcher" {
assert_false(default_panel.contains("logout"))
}
///| Append the Rotate and Keyboard panel modules when migrating a handset panel saved before
/// panel.edn version 3 (when those controls moved from floating pills into the panel).
fn migrate_handset_panel(entries : Array[String]) -> Array[String] {
let out = entries.copy()
if !out.contains("rotate") {
out.push("rotate")
}
if !out.contains("osk") {
out.push("osk")
}
out
}
///| Load the panel on first use: the saved layout if there is one, else the default modules.
fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
if self.booted {
@@ -365,8 +399,16 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
self.booted = true
self.scan_catalog()
let saved = self.load_panel_config()
let saved_ver = if saved is Some(_) { saved_panel_version() } else { panel_version }
let entries = match saved {
Some(e) => migrate_panel(e)
Some(e) => {
let migrated = migrate_panel(e)
if saved_ver < 3 && is_handset_panel() {
migrate_handset_panel(migrated)
} else {
migrated
}
}
None =>
if is_handset_panel() {
handset_panel
@@ -375,10 +417,12 @@ fn DesktopShell::ensure_booted(self : DesktopShell) -> Unit {
}
}
match saved {
Some(old) if saved_panel_version() < panel_version => {
Some(old) if saved_ver < panel_version => {
// Once, before the modules load so they pick up the moved settings; then the file is
// rewritten with the new names and version (also keeping modules that fail to load).
self.migrate_module_cfg(old)
if saved_ver < 2 {
self.migrate_module_cfg(old)
}
write_panel_file(entries)
}
// A renamed or folded module (the Log out button, now in the launcher): rewrite the file so
@@ -803,6 +847,12 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
if self.any_cap("screenshot") {
@wasm.publish_screenshot(self.screenshot_state)
}
if self.any_cap("osk") {
@wasm.publish_osk(self.osk_visible)
}
if self.any_cap("rotation") {
@wasm.publish_rotation(self.rotation)
}
if self.any_cap("battery") {
let b = self.battery.refresh()
@wasm.publish_battery(b.percent, b.state, b.secs_left)
@@ -979,6 +1029,8 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(DefaultApp(code)) => self.default_app_request(code)
Some(FaceUnlock(code)) => self.face.request(code)
Some(GameLibrary(code, game, mode)) => self.gamelib.request(code, game, mode)
Some(SetOskVisible(v)) => self.actions.push(SetOskVisible(v))
Some(SetRotation(r)) => self.actions.push(SetRotation(r))
Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
Some(Network(code, ssid, password)) => self.network_request(code, ssid, password)
Some(SetInspector(on)) => self.set_inspecting(on)
@@ -1447,7 +1499,8 @@ pub fn DesktopShell::save_panel_config(self : DesktopShell) -> Unit {
///| panel.edn's format version (`:version`; files without one are 1). 2: written after the
/// 12-hour clock (clock-digital12) became part of the Digital Clock, whose default went from
/// 24-hour to 12-hour; an older file gets its clock settings moved over once (migrate_module_cfg).
let panel_version : Int = 2
/// 3: handset panels move Rotate (`rotate`) and Keyboard (`osk`) into the panel.
let panel_version : Int = 3
///|
fn write_panel_file(names : Array[String]) -> Unit {