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

+14 -1
View File
@@ -139,6 +139,7 @@ pub fn run(args : Array[String]) -> Int {
Some(comp) => {
comp.shell.persist = true // remember which modules are loaded in the panel
comp.sync_system_theme = drm // the login session sets apps' dark/light preference
comp.login_session = drm // and power actions (suspend, power off) act on the machine
comp.restore_state() // and the layout mode and recent apps from the last session
comp.shell.screen_w = width
// Screenshots and recordings read the host's framebuffer (it draws the desktop).
@@ -203,6 +204,16 @@ pub fn run(args : Array[String]) -> Int {
for ev in input {
comp.handle_input(ev, now_ms)
}
// Idle timeouts (power.mbt): screen off / on, suspend.
match comp.power_tick(@sys.monotonic_ms()) {
ScreenOff => k.set_power(false)
ScreenOn => {
k.set_power(true)
need_present = true
}
Suspend => comp.system_power(0)
NoChange => ()
}
comp.step()
let f1 = @sys.monotonic_ms()
k.set_cursor_shape(comp.desired_cursor())
@@ -237,7 +248,9 @@ pub fn run(args : Array[String]) -> Int {
comp.prof_raster_ms = 0UL
}
}
if input.length() == 0 && !changed && !need_present && !comp.has_timed_work() {
// With the screen off nothing can be shown, so a waiting frame doesn't keep the loop busy.
let waiting = need_present && !comp.screen_off
if input.length() == 0 && !changed && !waiting && !comp.has_timed_work() {
// Idle: sleep until a client, the seat or the clock has something.
let fds = comp.server.wait_fds()
fds.append(k.wait_fds())
+13
View File
@@ -44,6 +44,13 @@ pub(all) struct ChandraCompositor {
/// Also set the system-wide dark/light preference for apps (system_theme.mbt). The login
/// session turns it on; nested windows and tests leave it off.
mut sync_system_theme : Bool
/// Running as the login session (--drm): power actions act on the machine (power.mbt).
mut login_session : Bool
/// Power (power.mbt): when input last came (monotonic ms), whether the screen is off for being
/// idle, and whether this idle spell already suspended.
mut last_input_ms : UInt64
mut screen_off : Bool
mut idle_suspended : Bool
mut output_w : Int
mut output_h : Int
mut work_area : @wm.Rect
@@ -149,6 +156,10 @@ pub fn ChandraCompositor::new(
theme,
dark_theme: theme,
sync_system_theme: false,
login_session: false,
last_input_ms: @sys.monotonic_ms(),
screen_off: false,
idle_suspended: false,
output_w,
output_h,
work_area,
@@ -1122,6 +1133,7 @@ fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit {
@shell.ShellAction::Logout => self.quit_requested = true
@shell.ShellAction::ThemeChanged => self.apply_theme()
@shell.ShellAction::Screenshot(code) => self.screenshot_request(code)
@shell.ShellAction::SystemPower(a) => self.system_power(a)
@shell.ShellAction::SetLayout(m) =>
match m {
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
@@ -1204,6 +1216,7 @@ pub fn ChandraCompositor::handle_input(
ev : @nested.InputEvent,
time_ms : UInt,
) -> Unit {
self.note_activity(@sys.monotonic_ms())
if self.screenshot_input(ev, time_ms) {
return
}
+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"))
}
}
+84
View File
@@ -0,0 +1,84 @@
///| Power in the login session: the screen goes off and the computer suspends after the minutes
/// without input the settings module's Power tab set (shell.screen_off_min / suspend_min), and the
/// tab's Suspend / Restart / Power off buttons. Suspend, power off and restart go through logind
/// (`systemctl`, else `loginctl`), so its inhibitors and polkit rules apply.
///
/// The main loop calls `power_tick` every pass. An idle loop still wakes about once a second
/// (IdleClock in compositor/app), so the timeouts fire within a second. CLOCK_MONOTONIC stops
/// while the machine is suspended, so after a resume the idle time hasn't grown past the suspend
/// timeout and the machine doesn't suspend again until there has been input and a new idle spell.
///| What `power_tick` wants the display / system to do now.
pub(all) enum PowerChange {
NoChange
ScreenOff
ScreenOn
Suspend
} derive(Eq, Debug)
///| Note input: it restarts the idle time (and wakes a screen that is off at the next tick).
pub fn ChandraCompositor::note_activity(self : ChandraCompositor, now_ms : UInt64) -> Unit {
self.last_input_ms = now_ms
}
///| Check the idle timeouts at monotonic time `now_ms`.
pub fn ChandraCompositor::power_tick(self : ChandraCompositor, now_ms : UInt64) -> PowerChange {
let idle = if now_ms > self.last_input_ms { now_ms - self.last_input_ms } else { 0UL }
let minutes = fn(m : Int) { m.to_uint64() * 60000UL }
let off = self.shell.screen_off_min
let susp = self.shell.suspend_min
if susp > 0 && idle >= minutes(susp) {
if !self.idle_suspended {
self.idle_suspended = true
return Suspend
}
} else {
self.idle_suspended = false
}
if off > 0 && idle >= minutes(off) {
if !self.screen_off {
self.screen_off = true
return ScreenOff
}
} else if self.screen_off {
self.screen_off = false
self.damage.mark_full()
return ScreenOn
}
NoChange
}
///| The command for a power action: 0 suspend, 1 power off, 2 restart.
pub fn power_command(action : Int) -> String? {
let verb = match action {
0 => "suspend"
1 => "poweroff"
2 => "reboot"
_ => return None
}
Some("systemctl " + verb + " || loginctl " + verb)
}
///| Suspend, power off or restart now. Only the login session does it: in a nested window (or a
/// test) a notice says so instead, since it would act on the machine the outer desktop runs on.
pub fn ChandraCompositor::system_power(self : ChandraCompositor, action : Int) -> Unit {
match power_command(action) {
None => ()
Some(cmd) =>
if self.login_session {
if !@sys.spawn(cmd, self.shell.display) {
self.shell.say("Could not run " + cmd)
}
} else {
self.shell.say("Suspend, restart and power off work in the login session only")
}
}
}
///|
test "power commands go through logind" {
assert_eq(power_command(0), Some("systemctl suspend || loginctl suspend"))
assert_eq(power_command(1), Some("systemctl poweroff || loginctl poweroff"))
assert_eq(power_command(2), Some("systemctl reboot || loginctl reboot"))
assert_eq(power_command(3), None)
}
+9
View File
@@ -46,6 +46,15 @@ extern "C" fn c_close() = "mp_kms_close"
///|
extern "C" fn c_fd(i : Int) -> Int = "mp_kms_fd"
///|
extern "C" fn c_set_power(on : Int) = "mp_kms_set_power"
///| Turn the screen on or off (DPMS). While it is off no frame is shown (`frame_ready` is
/// false); on shows the last frame again.
pub fn Kms::set_power(_self : Kms, on : Bool) -> Unit {
c_set_power(if on { 1 } else { 0 })
}
///|
pub(all) struct Kms {
width : Int
+36 -2
View File
@@ -123,6 +123,7 @@ static int g_front; /* index currently scanned out */
static int g_flip_pending;
static int g_need_modeset;
static int g_width, g_height;
static int g_blank; /* screen turned off (DPMS) by mp_kms_set_power */
static int fb_create(struct fbuf *b, int w, int h) {
struct drm_mode_create_dumb c = { .width = (uint32_t)w, .height = (uint32_t)h, .bpp = 32 };
@@ -339,8 +340,40 @@ static void do_modeset(void) {
cursor_apply();
}
/* Legacy DPMS on the output's connector (the modeset path here is legacy too). */
static void set_dpms(int on) {
drmModeObjectProperties *props = drmModeObjectGetProperties(g_drm, g_conn, DRM_MODE_OBJECT_CONNECTOR);
if (!props) return;
for (uint32_t i = 0; i < props->count_props; i++) {
drmModePropertyRes *p = drmModeGetProperty(g_drm, props->props[i]);
if (!p) continue;
if (!strcmp(p->name, "DPMS")) {
if (drmModeConnectorSetProperty(g_drm, g_conn, p->prop_id, on ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF) < 0)
fprintf(stderr, "kms: DPMS %s failed: %s\n", on ? "on" : "off", strerror(errno));
}
drmModeFreeProperty(p);
}
drmModeFreeObjectProperties(props);
}
/* ---- exported API -------------------------------------------------------- */
/* Turn the screen off (0) or on (1). While off, no frame is presented; on redoes the modeset so
* the last frame shows again. */
MOONBIT_FFI_EXPORT
void mp_kms_set_power(int32_t on) {
if (!g_seat || (on ? !g_blank : g_blank)) return;
g_blank = !on;
if (!g_seat_enabled || g_suspended) return; /* applied when the VT comes back */
if (on) {
set_dpms(1);
do_modeset();
} else {
set_dpms(0);
}
}
/* Open seat, DRM output and input. Returns 0 on success, negative step code on failure. */
MOONBIT_FFI_EXPORT
int32_t mp_kms_open(void) {
@@ -429,6 +462,7 @@ int32_t mp_kms_poll(void) {
drmSetMaster(g_drm);
if (g_li) libinput_resume(g_li);
do_modeset();
if (g_blank) set_dpms(0);
}
if (g_li) dispatch_input();
return g_seat_enabled;
@@ -450,13 +484,13 @@ int32_t mp_kms_fd(int32_t i) {
/* True when a new frame may be presented (seat active, no flip in flight). */
MOONBIT_FFI_EXPORT
int32_t mp_kms_frame_ready(void) {
return g_seat_enabled && !g_flip_pending;
return g_seat_enabled && !g_flip_pending && !g_blank;
}
/* Present an RGBA8888 frame of w x h (must match the mode). */
MOONBIT_FFI_EXPORT
int32_t mp_kms_present(moonbit_bytes_t pixels, int32_t w, int32_t h) {
if (!g_seat_enabled || g_flip_pending) return 0;
if (!g_seat_enabled || g_flip_pending || g_blank) return 0;
int back = 1 - g_front;
struct fbuf *b = &g_fb[back];
int cw = w < g_width ? w : g_width;
+6
View File
@@ -47,6 +47,12 @@ pub fn Kms::present_frame(_self : Kms) -> Unit {
@hostdisplay.present_frame()
}
///| Turn the screen on or off (DPMS). While it is off no frame is shown (`frame_ready` is
/// false); on shows the last frame again.
pub fn Kms::set_power(_self : Kms, on : Bool) -> Unit {
@hostdisplay.set_power(on)
}
///| Show the cursor for a wp_cursor_shape_v1 value.
pub fn Kms::set_cursor_shape(_self : Kms, shape : UInt) -> Unit {
@hostdisplay.set_cursor_shape(shape)
+8
View File
@@ -145,6 +145,8 @@ pub(all) enum ShellAction {
/// The screenshot module asked for a screenshot or recording (code: see the compositor's
/// screenshot_request).
Screenshot(Int)
/// The settings module's Power tab asked to suspend (0), power off (1) or restart (2) now.
SystemPower(Int)
} derive(Eq, Debug)
///| One wasm module loaded into the panel.
@@ -236,6 +238,10 @@ pub(all) struct DesktopShell {
mut remember_windows : Bool
/// Dark mode (the configured theme) or light (Moon Day); saved as `:theme :light` when off.
mut dark_mode : Bool
/// Power: minutes without input before the login session turns the screen off / suspends
/// (0: never). Saved in state.edn as :power {:screen-off 10 :suspend 0} when not the defaults.
mut screen_off_min : Int
mut suspend_min : Int
mut desk_set : Bool
mut desk_x : Int
mut desk_y : Int
@@ -336,6 +342,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
screenshot_state: 2,
remember_windows: true,
dark_mode: true,
screen_off_min: default_screen_off_min,
suspend_min: default_suspend_min,
desk_set: false,
desk_x: 0,
desk_y: 0,
+32 -1
View File
@@ -7,6 +7,8 @@
/// :desktop-card {:x 900 :y 24} ; where the desktop card was dragged to (absent: default spot)
/// :wallpaper :aurora ; the settings module's wallpaper (absent: :plasma-glow)
/// :theme :light ; the settings module's Dark mode switch is off (absent: dark)
/// :power {:screen-off 5 :suspend 30} ; minutes without input before the screen goes off /
/// ; the computer suspends, 0 never (absent: 10 and 0)
/// :session [{:app "foot"} {:app "org.gnome.Nautilus" :minimized true}]
/// ; the windows open when the last session ended, reopened at
/// ; the next start (see session.mbt in compositor/host)
@@ -34,6 +36,8 @@ pub(all) struct SavedState {
remember_windows : Bool?
/// From `:theme`: true for :dark, false for :light.
dark_mode : Bool?
/// From `:power`: (screen-off, suspend) minutes; a missing one keeps its default.
power : (Int?, Int?)
}
///|
@@ -47,7 +51,7 @@ let layout_names : Array[String] = ["tiling", "monocle", "floating"]
///| The keys this build owns; everything else in the file is kept as it is.
let owned_keys : Array[String] = [
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
"theme",
"theme", "power",
]
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
@@ -92,6 +96,7 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
restore_session: None,
remember_windows: None,
dark_mode: None,
power: (None, None),
}
}
let entries = read_state_file()
@@ -191,6 +196,18 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
wallpaper,
restore_session: flag("restore-session"),
remember_windows: flag("remember-windows"),
power: match lookup_key(entries, "power") {
Some(Mapping(m)) => {
let f = fn(k : String) -> Int? {
match lookup_key(m, k) {
Some(Integer(v)) => parse_int_str(v)
_ => None
}
}
(f("screen-off"), f("suspend"))
}
_ => (None, None)
},
dark_mode: match lookup_key(entries, "theme") {
Some(Keyword("light")) => Some(false)
Some(Keyword("dark")) => Some(true)
@@ -220,6 +237,14 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
Some(b) => self.dark_mode = b
None => ()
}
match st.power.0 {
Some(m) if m >= 0 => self.screen_off_min = m
_ => ()
}
match st.power.1 {
Some(m) if m >= 0 => self.suspend_min = m
_ => ()
}
match st.desk {
Some((x, y)) => {
self.desk_set = true
@@ -292,6 +317,12 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
entries.insert(2, (@edn.Value::Keyword("wallpaper"), @edn.Value::Keyword(wallpaper_keys[self.wallpaper_sel])))
}
// Session settings are written only when off: absent means on, as for a hand-written file.
if self.screen_off_min != default_screen_off_min || self.suspend_min != default_suspend_min {
entries.insert(2, (@edn.Value::Keyword("power"), @edn.Value::Mapping([
(@edn.Value::Keyword("screen-off"), @edn.Value::Integer(self.screen_off_min.to_string())),
(@edn.Value::Keyword("suspend"), @edn.Value::Integer(self.suspend_min.to_string())),
])))
}
if !self.dark_mode {
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
}
+27 -2
View File
@@ -163,7 +163,7 @@ fn DesktopShell::panel_fits(self : DesktopShell) -> Bool {
}
///| Show a short message above the panel for a few seconds.
fn DesktopShell::say(self : DesktopShell, msg : String) -> Unit {
pub fn DesktopShell::say(self : DesktopShell, msg : String) -> Unit {
self.notice = msg
self.notice_frames = 1
self.notice_start = wall_secs()
@@ -430,6 +430,9 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
@wasm.publish(SessionSettings, st)
@wasm.publish_session_settings(self.session_settings_bits())
}
if self.widgets.iter().any(w => w.has_cap("power")) {
@wasm.publish_power(self.screen_off_min, self.suspend_min)
}
if self.widgets.iter().any(w => w.has_cap("screenshot")) {
@wasm.publish_screenshot(self.screenshot_state)
}
@@ -505,6 +508,22 @@ pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool
self.save_state()
}
///| Default power timeouts, in minutes (0: never): the screen goes off after 10 minutes without
/// input; the computer doesn't suspend on its own.
let default_screen_off_min : Int = 10
///|
let default_suspend_min : Int = 0
///| Set the power timeouts (minutes, 0: never; clamped to a day) and remember them.
pub fn DesktopShell::set_power_timeouts(self : DesktopShell, screen_off : Int, suspend : Int) -> Unit {
let clamp = fn(m : Int) { if m < 0 { 0 } else if m > 1440 { 1440 } else { m } }
self.screen_off_min = clamp(screen_off)
self.suspend_min = clamp(suspend)
@wasm.publish_power(self.screen_off_min, self.suspend_min)
self.save_state()
}
///| Carry out what modules asked of the host during their last calls.
fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
while true {
@@ -528,6 +547,9 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(SetWallpaper(i)) => self.set_wallpaper(i)
Some(SetSessionSetting(i, on)) => self.set_session_setting(i, on)
Some(Screenshot(code)) => self.actions.push(Screenshot(code))
Some(SetScreenOff(m)) => self.set_power_timeouts(m, self.suspend_min)
Some(SetSuspendAfter(m)) => self.set_power_timeouts(self.screen_off_min, m)
Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
Some(SetInspector(on)) => self.set_inspecting(on)
Some(LoadModule(path)) => {
match self.load_path(path) {
@@ -604,6 +626,8 @@ pub(all) enum SettingsTab {
Desktop
/// The panel's modules: remove, add, browse.
Panel
/// Battery, idle timeouts, suspend / restart / power off.
Power
} derive(Eq, Debug)
///| Open the settings module ("System settings") on `tab`, loading it into the panel first if it
@@ -632,11 +656,12 @@ pub fn DesktopShell::open_settings(self : DesktopShell, tab : SettingsTab) -> Bo
if w.popup_rect.w == 0 {
ignore(self.deliver(w, false, PointerDown(0, 0)))
}
// The module's keys 1, 2, 3 pick its tabs.
// The module's keys 1-4 pick its tabs.
let key = match tab {
Session => "1"
Desktop => "2"
Panel => "3"
Power => "4"
}
ignore(self.deliver(w, true, KeyDown(key)))
self.save_panel_config()
+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;