Power settings: screen off and suspend when idle, battery, suspend / restart / power off
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:
Claude committed 2026-11-25 19:37:21 +00:00
1 parent ba82d3c59b
commit 2636373a4f
40 files changed
+817 -77

No files matched your search

+73 -2
View File
@@ -1221,10 +1221,10 @@ test "the settings module lists the wallpapers and switches the desktop to the o
assert_eq(comp.shell.slot_of("wallpaper"), "") // the standalone chooser is gone
assert_eq(comp.shell.wallpaper_sel, 0)
// A click opens the popup on its Session tab; the Desktop tab (the second of three 96 px
// tabs) lists the wallpapers below a heading. Nothing changes yet.
// tabs; four 72 px tabs) lists the wallpapers below a heading. Nothing changes yet.
click_module(comp, "session-settings", 1U)
let p0 = comp.shell.slot_popup_rect(slot)
click_at(comp, p0.x + 6 + 96 + 48, p0.y + 6 + 14, 3U)
click_at(comp, p0.x + 6 + 72 + 36, p0.y + 6 + 14, 3U)
let pr = comp.shell.slot_popup_rect(slot)
assert_true(pr.h >= 40 + 6 * 28) // heading and one row per wallpaper below the tab bar
assert_eq(comp.shell.wallpaper_sel, 0)
@@ -1443,3 +1443,74 @@ test "open_settings opens the settings module on the tab asked for" {
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, 40 + 3 * 28 + 6) // the three settings
}
///|
test "idle timeouts turn the screen off, suspend once per idle spell, and input wakes the screen" {
let comp = new_comp("powertick")
comp.shell.screen_off_min = 1
comp.shell.suspend_min = 2
comp.note_activity(0UL)
assert_eq(comp.power_tick(30000UL), NoChange)
assert_eq(comp.power_tick(60000UL), ScreenOff)
assert_eq(comp.power_tick(61000UL), NoChange)
assert_eq(comp.power_tick(120000UL), Suspend)
assert_eq(comp.power_tick(200000UL), NoChange) // not again in the same idle spell
comp.note_activity(210000UL)
assert_eq(comp.power_tick(210500UL), ScreenOn)
assert_eq(comp.power_tick(250000UL), NoChange)
// A new idle spell suspends again; 0 means never.
assert_eq(comp.power_tick(270000UL), ScreenOff)
assert_eq(comp.power_tick(330000UL), Suspend)
comp.shell.screen_off_min = 0
comp.shell.suspend_min = 0
comp.note_activity(400000UL)
assert_eq(comp.power_tick(400100UL), ScreenOn)
assert_eq(comp.power_tick(99999999UL), NoChange)
}
///|
test "the settings module's Power tab steps the timeouts and confirms power off" {
let comp = new_comp("powertab")
let slot = comp.shell.slot_of("session-settings")
assert_true(comp.shell.open_settings(Power))
ignore(comp.compose_frame())
let pr = comp.shell.slot_popup_rect(slot)
// Rows of 28 below the tab bar (40): [Battery heading, battery,] When idle, screen off,
// suspend, Now, Suspend, Restart, Power off.
let n = (pr.h - 40 - 6) / 28
assert_true(n == 7 || n == 9)
let first = n - 7
let row_y = fn(i : Int) { pr.y + 40 + (first + i) * 28 + 13 }
assert_eq(comp.shell.screen_off_min, 10)
click_at(comp, pr.x + 40, row_y(1), 5U) // screen off: 10 -> 15 min
assert_eq(comp.shell.screen_off_min, 15)
click_at(comp, pr.x + 40, row_y(2), 10U) // suspend: never -> 5 min
assert_eq(comp.shell.suspend_min, 5)
// Power off asks for a second click; outside the login session it only says so.
comp.shell.notice = ""
click_at(comp, pr.x + 40, row_y(6), 15U)
assert_eq(comp.shell.notice, "")
click_at(comp, pr.x + 40, row_y(6), 20U)
assert_true(comp.shell.notice.contains("login session"))
}
///|
test "power timeouts are saved to state.edn and restored" {
if @sys.getenv("CHANDRA_TEST_CONFIG") == "1" {
write_state_edn("{:note \"keep\"}\n")
let a = new_comp("pow-a")
a.shell.persist = true
a.restore_state()
assert_eq((a.shell.screen_off_min, a.shell.suspend_min), (10, 0)) // the defaults
a.shell.set_power_timeouts(5, 30)
let text = read_state_edn()
assert_true(text.contains(":power {:screen-off 5 :suspend 30}"))
assert_true(text.contains(":note \"keep\""))
let b = new_comp("pow-b")
b.shell.persist = true
b.restore_state()
assert_eq((b.shell.screen_off_min, b.shell.suspend_min), (5, 30))
b.shell.set_power_timeouts(10, 0)
assert_false(read_state_edn().contains(":power"))
}
}