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
@@ -0,0 +1,3 @@
|
||||
Power: when the login session turns the screen off and suspends after no input, and suspend,
|
||||
restart or power off now (through logind). A module with this capability is the settings
|
||||
module's Power tab. The shell keeps the timeouts in state.edn.
|
||||
@@ -0,0 +1,23 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
fn wasmImportScreenOffMinutes() -> Int = "chandra:desktop/power@0.1.0" "screen-off-minutes"
|
||||
|
||||
///|
|
||||
fn wasmImportSetScreenOffMinutes(p0 : Int) = "chandra:desktop/power@0.1.0" "set-screen-off-minutes"
|
||||
|
||||
///|
|
||||
fn wasmImportSuspendMinutes() -> Int = "chandra:desktop/power@0.1.0" "suspend-minutes"
|
||||
|
||||
///|
|
||||
fn wasmImportSetSuspendMinutes(p0 : Int) = "chandra:desktop/power@0.1.0" "set-suspend-minutes"
|
||||
|
||||
///|
|
||||
fn wasmImportSuspend() = "chandra:desktop/power@0.1.0" "suspend"
|
||||
|
||||
///|
|
||||
fn wasmImportPowerOff() = "chandra:desktop/power@0.1.0" "power-off"
|
||||
|
||||
///|
|
||||
fn wasmImportReboot() = "chandra:desktop/power@0.1.0" "reboot"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
warnings = "-44"
|
||||
@@ -0,0 +1,51 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
/// Minutes without input before the screen turns off; 0: never.
|
||||
pub fn screen_off_minutes() -> UInt {
|
||||
|
||||
let result : Int = wasmImportScreenOffMinutes();
|
||||
let ret = (result).reinterpret_as_uint()
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn set_screen_off_minutes(minutes : UInt) -> Unit {
|
||||
|
||||
wasmImportSetScreenOffMinutes((minutes).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// Minutes without input before the computer suspends; 0: never.
|
||||
pub fn suspend_minutes() -> UInt {
|
||||
|
||||
let result : Int = wasmImportSuspendMinutes();
|
||||
let ret = (result).reinterpret_as_uint()
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn set_suspend_minutes(minutes : UInt) -> Unit {
|
||||
|
||||
wasmImportSetSuspendMinutes((minutes).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// Suspend, power off or restart now.
|
||||
pub fn suspend() -> Unit {
|
||||
|
||||
wasmImportSuspend();
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn power_off() -> Unit {
|
||||
|
||||
wasmImportPowerOff();
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn reboot() -> Unit {
|
||||
|
||||
wasmImportReboot();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Live machine state, sampled by the host about once a second. The widget never
|
||||
opens /proc or /sys itself: it can only see what this interface hands it, and
|
||||
the host can serve it from anything (Linux /proc, a mock, a remote machine).
|
||||
@@ -0,0 +1,28 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
fn wasmImportRead(p0 : Int) = "chandra:desktop/system@0.1.0" "read"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
warnings = "-44"
|
||||
@@ -0,0 +1,16 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
pub(all) struct Snapshot {
|
||||
cpu_permille : UInt; mem_used_kib : UInt64; mem_total_kib : UInt64; battery_percent : Int; charging : Bool; uptime_secs : UInt64; net_rx_bytes_per_sec : UInt64; net_tx_bytes_per_sec : UInt64; load_centi : UInt
|
||||
}
|
||||
///|
|
||||
pub fn read() -> Snapshot {
|
||||
|
||||
let return_area = mbt_ffi_malloc(64)
|
||||
wasmImportRead(return_area);
|
||||
let ret = Snapshot::{cpu_permille : (mbt_ffi_load32((return_area) + 0)).reinterpret_as_uint(), mem_used_kib : (mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64(), mem_total_kib : (mbt_ffi_load64((return_area) + 16)).reinterpret_as_uint64(), battery_percent : mbt_ffi_load32((return_area) + 24), charging : (mbt_ffi_load8_u((return_area) + 28) != 0), uptime_secs : (mbt_ffi_load64((return_area) + 32)).reinterpret_as_uint64(), net_rx_bytes_per_sec : (mbt_ffi_load64((return_area) + 40)).reinterpret_as_uint64(), net_tx_bytes_per_sec : (mbt_ffi_load64((return_area) + 48)).reinterpret_as_uint64(), load_centi : (mbt_ffi_load32((return_area) + 56)).reinterpret_as_uint()}
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
|
||||
@@ -18,39 +18,19 @@ fn wasmImportPresentFrame() = "chandra:host/display@0.1.0" "present-frame"
|
||||
///|
|
||||
fn wasmImportSetCursorShape(p0 : Int) = "chandra:host/display@0.1.0" "set-cursor-shape"
|
||||
|
||||
///|
|
||||
fn wasmImportSetPower(p0 : Int) = "chandra:host/display@0.1.0" "set-power"
|
||||
|
||||
///|
|
||||
fn wasmImportTakeInput(p0 : Int) = "chandra:host/display@0.1.0" "take-input"
|
||||
|
||||
///|
|
||||
fn wasmImportClose() = "chandra:host/display@0.1.0" "close"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array8
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_loadf64(offset : Int) -> Double =
|
||||
#|(func (param i32) (result f64) local.get 0 f64.load)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
@@ -59,3 +39,26 @@ extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array8
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
@@ -30,6 +30,11 @@ fn wasmImportSetCursorShape(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportSetPower(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportTakeInput(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
|
||||
@@ -16,6 +16,8 @@ pub fn present_frame() -> Unit
|
||||
|
||||
pub fn set_cursor_shape(UInt32) -> Unit
|
||||
|
||||
pub fn set_power(Bool) -> Unit
|
||||
|
||||
pub fn take_input() -> Array[SeatEvent]
|
||||
|
||||
// Errors
|
||||
|
||||
@@ -95,6 +95,14 @@ pub fn set_cursor_shape(shape : UInt) -> Unit {
|
||||
|
||||
wasmImportSetCursorShape((shape).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// Turn the screen on or off (DPMS). While it is off no frame is shown (`frame-ready` is false);
|
||||
/// turning it on shows the last frame again.
|
||||
pub fn set_power(on : Bool) -> Unit {
|
||||
|
||||
wasmImportSetPower((if on { 1 } else { 0 }));
|
||||
|
||||
}
|
||||
///|
|
||||
/// Input queued since the last call.
|
||||
|
||||
@@ -36,6 +36,9 @@ fn wasmImportPublishWallpaper(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publi
|
||||
///|
|
||||
fn wasmImportPublishSessionSettings(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-session-settings"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishPower(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "publish-power"
|
||||
|
||||
///|
|
||||
fn wasmImportPublishScreenshot(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-screenshot"
|
||||
|
||||
@@ -60,38 +63,22 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start
|
||||
///|
|
||||
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
@@ -101,14 +88,30 @@ extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
#owned(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
@@ -60,6 +60,11 @@ fn wasmImportPublishSessionSettings(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishPower(p0 : Int, p1 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
}
|
||||
|
||||
///|
|
||||
fn wasmImportPublishScreenshot(p0 : Int) -> Unit {
|
||||
abort("wasm-only host import")
|
||||
|
||||
@@ -23,6 +23,8 @@ pub fn picker_start() -> Bool
|
||||
|
||||
pub fn popup(UInt32) -> PopupSurface?
|
||||
|
||||
pub fn publish_power(UInt32, UInt32) -> Unit
|
||||
|
||||
pub fn publish_screenshot(UInt32) -> Unit
|
||||
|
||||
pub fn publish_session_settings(UInt32) -> Unit
|
||||
@@ -90,6 +92,9 @@ pub(all) enum Request {
|
||||
SetWallpaper(Int32)
|
||||
SetSessionSetting(SettingChange)
|
||||
Screenshot(Int32)
|
||||
SetScreenOff(Int32)
|
||||
SetSuspendAfter(Int32)
|
||||
PowerAction(Int32)
|
||||
}
|
||||
|
||||
pub(all) struct SettingChange {
|
||||
|
||||
@@ -42,6 +42,9 @@ pub(all) enum Request {
|
||||
SetWallpaper(Int)
|
||||
SetSessionSetting(SettingChange)
|
||||
Screenshot(Int)
|
||||
SetScreenOff(Int)
|
||||
SetSuspendAfter(Int)
|
||||
PowerAction(Int)
|
||||
}
|
||||
///|
|
||||
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
|
||||
@@ -401,6 +404,13 @@ pub fn publish_session_settings(on : UInt) -> Unit {
|
||||
|
||||
wasmImportPublishSessionSettings((on).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// The power timeouts, in minutes (0: never).
|
||||
pub fn publish_power(screen_off : UInt, suspend : UInt) -> Unit {
|
||||
|
||||
wasmImportPublishPower((screen_off).reinterpret_as_int(), (suspend).reinterpret_as_int());
|
||||
|
||||
}
|
||||
///|
|
||||
/// Screenshot state: bit 0 a recording is running, bit 1 recordings show the pointer.
|
||||
@@ -505,6 +515,18 @@ pub fn next_request() -> Request? {
|
||||
|
||||
Request::Screenshot(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
11 => {
|
||||
|
||||
Request::SetScreenOff(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
12 => {
|
||||
|
||||
Request::SetSuspendAfter(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
13 => {
|
||||
|
||||
Request::PowerAction(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user