Power settings: screen off and suspend when idle, battery, suspend / restart / power off
CI / test (push) Failing after 18s
CI / test (push) Failing after 18s
- Settings gets a Power tab (fourth; key 4 or SettingsTab::Power): the battery when there is
one (the system capability), "Turn screen off after" (Never, 1 min ... 1 hour; default 10 min)
and "Suspend after" (Never, 5 min ... 2 hours; default never), a click stepping through the
choices, and Suspend / Restart / Power off now. Restart and Power off need a second click.
- New `power` capability (screen-off-minutes, suspend-minutes and setters, suspend, power-off,
reboot), served by the wasmer stub (host ints 5/6, requests 13-15) and host-wasm
(publish-power, set-screen-off / set-suspend-after / power-action).
- The timeouts are kept in state.edn as :power {:screen-off N :suspend N} when not the defaults.
- Login session only (compositor/host/power.mbt): input restarts the idle time; power_tick,
run every pass of the main loop (an idle loop still wakes about once a second), turns the
screen off through DPMS and back on at the next input, and suspends once per idle spell.
Monotonic time stops in suspend, so a resumed machine waits for input and a new idle spell.
Suspend, restart and power off run `systemctl <verb> || loginctl <verb>` (logind, so its
inhibitors and polkit rules apply); a nested window only shows a notice.
- Display: chandra:host/display set-power and Kms::set_power; the shared C shim sets the
connector's legacy DPMS property, shows no frames while off (frame_ready false, so the idle
loop still sleeps), redoes the modeset when turned on, and keeps the screen off across a VT
switch.
- components/screenshot bindings regenerated (they were stale: the module didn't build).
- Tests: idle timer sequence, the Power tab driving the shell (timeouts, two-click power off),
the state.edn round trip, a host-wasm test of the tab, and logind commands.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgxf6exeYrDGcy4WW3
This commit is contained in:
40 files changed
+817
-77
No files matched your search
@@ -48,6 +48,10 @@ pub enum Req {
|
||||
SetSessionSetting(i32, bool),
|
||||
/// The screenshot capability: 0-3 take, 10-12 record, 20 stop, 30/31 pointer off/on.
|
||||
Screenshot(i32),
|
||||
SetScreenOff(i32),
|
||||
SetSuspendAfter(i32),
|
||||
/// 0 suspend, 1 power off, 2 restart.
|
||||
PowerAction(i32),
|
||||
}
|
||||
|
||||
pub const T_APPS: usize = 0;
|
||||
@@ -70,6 +74,9 @@ pub struct Shared {
|
||||
pub session_settings: u32,
|
||||
/// Screenshot state: bit 0 a recording is running, bit 1 recordings show the pointer.
|
||||
pub screenshot: u32,
|
||||
/// Power timeouts in minutes (0: never).
|
||||
pub screen_off_min: u32,
|
||||
pub suspend_min: u32,
|
||||
pub inspector_on: bool,
|
||||
pub system: Option<d::system::Snapshot>,
|
||||
/// (id, title, app id, focused)
|
||||
@@ -307,6 +314,30 @@ impl d::wallpaper::Host for PState {
|
||||
}
|
||||
}
|
||||
|
||||
impl d::power::Host for PState {
|
||||
fn screen_off_minutes(&mut self) -> u32 {
|
||||
self.shared.borrow().screen_off_min
|
||||
}
|
||||
fn set_screen_off_minutes(&mut self, minutes: u32) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::SetScreenOff(minutes as i32));
|
||||
}
|
||||
fn suspend_minutes(&mut self) -> u32 {
|
||||
self.shared.borrow().suspend_min
|
||||
}
|
||||
fn set_suspend_minutes(&mut self, minutes: u32) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::SetSuspendAfter(minutes as i32));
|
||||
}
|
||||
fn suspend(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::PowerAction(0));
|
||||
}
|
||||
fn power_off(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::PowerAction(1));
|
||||
}
|
||||
fn reboot(&mut self) {
|
||||
self.shared.borrow_mut().requests.push_back(Req::PowerAction(2));
|
||||
}
|
||||
}
|
||||
|
||||
impl d::screenshot::Host for PState {
|
||||
fn take(&mut self, mode: u32) {
|
||||
if mode <= 3 {
|
||||
@@ -722,9 +753,9 @@ mod tests {
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(1, true))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 2 * 28 + 13 })));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSessionSetting(2, false))));
|
||||
// The Desktop tab (second of three 96 px tabs): row 0 is the "Wallpaper" heading
|
||||
// The Desktop tab (second of four 72 px tabs): row 0 is the "Wallpaper" heading
|
||||
// (nothing), rows 1.. the wallpapers: Starfield.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 6 + 96 + 48, y: 6 + 14 })));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 6 + 72 + 36, y: 6 + 14 })));
|
||||
assert!(texts(&rt.popup(h).unwrap().ops).contains(&"Starfield".to_string()));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(Point { x: 20, y: 40 + 13 })));
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
@@ -800,4 +831,33 @@ mod tests {
|
||||
rt.unload(h);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settings_power_tab_steps_timeouts_and_confirms_power_off() {
|
||||
let mut rt = runtime();
|
||||
let l = rt.load(&module("session-settings")).expect("session-settings loads");
|
||||
assert!(l.imports.contains(&"power".to_string()));
|
||||
let h = l.handle;
|
||||
rt.shared.borrow_mut().screen_off_min = 10;
|
||||
rt.shared.borrow_mut().suspend_min = 0;
|
||||
assert!(rt.on_event(h, false, InputEvent::PointerDown(Point { x: 5, y: 5 })));
|
||||
assert!(rt.on_event(h, true, InputEvent::KeyDown("4".to_string()))); // the Power tab
|
||||
let ts = texts(&rt.popup(h).expect("popup open").ops);
|
||||
for want in ["Turn screen off after", "10 min", "Suspend after", "Never", "Power off"] {
|
||||
assert!(ts.contains(&want.to_string()), "{want} shown");
|
||||
}
|
||||
// No battery: rows of 28 below the tab bar (40) are When idle, screen off, suspend, Now,
|
||||
// Suspend, Restart, Power off.
|
||||
let row = |i: i32| Point { x: 20, y: 40 + i * 28 + 13 };
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(row(1))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetScreenOff(15))));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(row(2))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::SetSuspendAfter(5))));
|
||||
// Power off takes two clicks.
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(row(6))));
|
||||
assert!(rt.shared.borrow().requests.is_empty());
|
||||
assert!(texts(&rt.popup(h).unwrap().ops).contains(&"Click again to power off".to_string()));
|
||||
assert!(rt.on_event(h, true, InputEvent::PointerDown(row(6))));
|
||||
assert!(matches!(rt.shared.borrow_mut().requests.pop_front(), Some(Req::PowerAction(1))));
|
||||
rt.unload(h);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user