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

+13
View File
@@ -318,6 +318,11 @@ pub fn publish_screenshot(state : Int) -> Unit {
@hostpl.publish_screenshot(state.reinterpret_as_uint())
}
///| The power timeouts, in minutes (0: never).
pub fn publish_power(screen_off : Int, suspend : Int) -> Unit {
@hostpl.publish_power(screen_off.reinterpret_as_uint(), suspend.reinterpret_as_uint())
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -333,6 +338,11 @@ pub(all) enum HostRequest {
SetSessionSetting(Int, Bool)
/// The screenshot capability: 0-3 take, 10-12 record, 20 stop, 30/31 pointer off/on.
Screenshot(Int)
/// Power: screen-off / suspend timeouts in minutes (0: never), an action now (0 suspend,
/// 1 power off, 2 restart).
SetScreenOff(Int)
SetSuspendAfter(Int)
PowerAction(Int)
} derive(Eq, Debug)
///|
@@ -350,6 +360,9 @@ pub fn next_request() -> HostRequest? {
Some(SetWallpaper(i)) => Some(SetWallpaper(i))
Some(SetSessionSetting(c)) => Some(SetSessionSetting(c.index, c.on))
Some(Screenshot(code)) => Some(Screenshot(code))
Some(SetScreenOff(m)) => Some(SetScreenOff(m))
Some(SetSuspendAfter(m)) => Some(SetSuspendAfter(m))
Some(PowerAction(a)) => Some(PowerAction(a))
}
}
+14
View File
@@ -735,6 +735,12 @@ pub fn publish_screenshot(state : Int) -> Unit {
c_host_set_int(4, state)
}
///| Publish the power timeouts, in minutes (0: never).
pub fn publish_power(screen_off : Int, suspend : Int) -> Unit {
c_host_set_int(5, screen_off)
c_host_set_int(6, suspend)
}
///| Something a module asked the host to do during a call.
pub(all) enum HostRequest {
Launch(String)
@@ -750,6 +756,11 @@ pub(all) enum HostRequest {
SetSessionSetting(Int, Bool)
/// The screenshot capability: 0-3 take, 10-12 record, 20 stop, 30/31 pointer off/on.
Screenshot(Int)
/// Power: screen-off / suspend timeouts in minutes (0: never), an action now (0 suspend,
/// 1 power off, 2 restart).
SetScreenOff(Int)
SetSuspendAfter(Int)
PowerAction(Int)
} derive(Eq, Debug)
///|
@@ -774,6 +785,9 @@ pub fn next_request() -> HostRequest? {
10 => Some(SetSessionSetting(c_host_req_int(), false))
11 => Some(SetSessionSetting(c_host_req_int(), true))
12 => Some(Screenshot(c_host_req_int()))
13 => Some(SetScreenOff(c_host_req_int()))
14 => Some(SetSuspendAfter(c_host_req_int()))
15 => Some(PowerAction(c_host_req_int()))
_ => None
}
}
+22 -2
View File
@@ -55,7 +55,8 @@ enum {
K_SYSTEM_READ, K_WIN_ALL, K_WIN_FOCUS_ID, K_LOGOUT, K_WALLPAPERS, K_WALLPAPER_CUR, K_SET_WALLPAPER,
K_SESSION_SETTINGS, K_SESSION_IS_ON, K_SESSION_SET,
K_APP_ICON,
K_SHOT_TAKE, K_SHOT_RECORD, K_SHOT_STOP, K_SHOT_IS_REC, K_SHOT_PTR, K_SHOT_SET_PTR
K_SHOT_TAKE, K_SHOT_RECORD, K_SHOT_STOP, K_SHOT_IS_REC, K_SHOT_PTR, K_SHOT_SET_PTR,
K_PW_SCREEN, K_PW_SET_SCREEN, K_PW_SUSP, K_PW_SET_SUSP, K_PW_SUSPEND, K_PW_OFF, K_PW_REBOOT
};
typedef struct Env { Inst *inst; int kind; } Env;
@@ -65,7 +66,8 @@ enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SES
typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N];
static int32_t host_ints[8]; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
4 screenshot state (bit 0 recording, bit 1 pointer in recordings) */
4 screenshot state (bit 0 recording, bit 1 pointer in recordings),
5 screen-off minutes, 6 suspend minutes (0: never) */
/* ---- requests a guest made of the host (launch, focus, ...) ; drained by the shell after each call ---- */
typedef struct { int kind; int32_t n; char *s; } Req;
@@ -319,6 +321,17 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_SHOT_RECORD: if (a0 >= 0 && a0 <= 2) push_req(12, 10 + a0, NULL); break;
case K_SHOT_STOP: push_req(12, 20, NULL); break;
case K_SHOT_SET_PTR: push_req(12, a0 ? 31 : 30, NULL); break;
case K_PW_SCREEN:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[5]);
break;
case K_PW_SUSP:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[6]);
break;
case K_PW_SET_SCREEN: push_req(13, a0, NULL); break;
case K_PW_SET_SUSP: push_req(14, a0, NULL); break;
case K_PW_SUSPEND: push_req(15, 0, NULL); break; /* 15: power action n (0 suspend, 1 off, 2 restart) */
case K_PW_OFF: push_req(15, 1, NULL); break;
case K_PW_REBOOT: push_req(15, 2, NULL); break;
case K_SHOT_IS_REC:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[4] & 1);
break;
@@ -474,6 +487,13 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "screenshot") && !strcmp(fn, "is-recording")) return K_SHOT_IS_REC;
if (!strcmp(iface, "screenshot") && !strcmp(fn, "records-pointer")) return K_SHOT_PTR;
if (!strcmp(iface, "screenshot") && !strcmp(fn, "set-records-pointer")) return K_SHOT_SET_PTR;
if (!strcmp(iface, "power") && !strcmp(fn, "screen-off-minutes")) return K_PW_SCREEN;
if (!strcmp(iface, "power") && !strcmp(fn, "set-screen-off-minutes")) return K_PW_SET_SCREEN;
if (!strcmp(iface, "power") && !strcmp(fn, "suspend-minutes")) return K_PW_SUSP;
if (!strcmp(iface, "power") && !strcmp(fn, "set-suspend-minutes")) return K_PW_SET_SUSP;
if (!strcmp(iface, "power") && !strcmp(fn, "suspend")) return K_PW_SUSPEND;
if (!strcmp(iface, "power") && !strcmp(fn, "power-off")) return K_PW_OFF;
if (!strcmp(iface, "power") && !strcmp(fn, "reboot")) return K_PW_REBOOT;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "layout-modes")) return K_LAYOUTS;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "current-layout")) return K_LAYOUT_CUR;
if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT;