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
110 lines
3.7 KiB
Rust
110 lines
3.7 KiB
Rust
//! The login-session display backend: calls into compositor/kms/kms_stub.c (built by build.rs),
|
|
//! the same shim the native compositor uses. One display, one seat, global state.
|
|
|
|
use crate::chandra::host::display::{KeyState, Modifiers, Output, PointerPos, ScrollDelta, SeatEvent};
|
|
|
|
extern "C" {
|
|
fn mp_kms_open() -> i32;
|
|
fn mp_kms_width() -> i32;
|
|
fn mp_kms_height() -> i32;
|
|
fn mp_kms_quit_requested() -> i32;
|
|
fn mp_kms_poll() -> i32;
|
|
fn mp_kms_frame_ready() -> i32;
|
|
fn mp_kms_set_cursor_shape(shape: i32);
|
|
fn mp_kms_next_event() -> i32;
|
|
fn mp_kms_arg(i: i32) -> i32;
|
|
fn mp_kms_keymap_len() -> i32;
|
|
fn mp_kms_close();
|
|
fn mp_kms_fd(i: i32) -> i32;
|
|
fn mp_kms_set_power(on: i32);
|
|
fn hw_kms_present(pixels: *mut u8, w: i32, h: i32) -> i32;
|
|
fn hw_kms_keymap_copy(out: *mut u8, cap: i32) -> i32;
|
|
}
|
|
|
|
/// Open the seat, the first connected output and libinput. None (the shim has said why on stderr)
|
|
/// when this is not an active login VT.
|
|
pub fn open() -> Option<Output> {
|
|
unsafe {
|
|
if mp_kms_open() != 0 {
|
|
mp_kms_close();
|
|
return None;
|
|
}
|
|
let n = mp_kms_keymap_len();
|
|
let mut keymap = vec![0u8; n.max(0) as usize];
|
|
let got = if n > 0 { hw_kms_keymap_copy(keymap.as_mut_ptr(), n) } else { 0 };
|
|
keymap.truncate(got.max(0) as usize);
|
|
Some(Output { width: mp_kms_width() as u32, height: mp_kms_height() as u32, keymap })
|
|
}
|
|
}
|
|
|
|
/// Service the seat, DRM and input fds. False once Ctrl+Alt+Backspace was pressed.
|
|
pub fn poll() -> bool {
|
|
unsafe {
|
|
mp_kms_poll();
|
|
mp_kms_quit_requested() == 0
|
|
}
|
|
}
|
|
|
|
/// The seat, DRM and input fds while the display is open (empty otherwise), for an idle wait.
|
|
pub fn fds() -> Vec<i32> {
|
|
(0..3).map(|i| unsafe { mp_kms_fd(i) }).filter(|&fd| fd >= 0).collect()
|
|
}
|
|
|
|
pub fn frame_ready() -> bool {
|
|
unsafe { mp_kms_frame_ready() != 0 }
|
|
}
|
|
|
|
/// Present an RGBA8888 frame; ignored if the buffer is smaller than the stated size.
|
|
pub fn present(pixels: &[u8], width: u32, height: u32) {
|
|
if pixels.len() < (width as usize) * (height as usize) * 4 {
|
|
return;
|
|
}
|
|
// The shim only reads the pixels; it takes a non-const pointer for the MoonBit byte type.
|
|
unsafe { hw_kms_present(pixels.as_ptr() as *mut u8, width as i32, height as i32) };
|
|
}
|
|
|
|
/// Turn the screen on or off (DPMS).
|
|
pub fn set_power(on: bool) {
|
|
unsafe { mp_kms_set_power(on as i32) };
|
|
}
|
|
|
|
pub fn set_cursor_shape(shape: u32) {
|
|
unsafe { mp_kms_set_cursor_shape(shape as i32) };
|
|
}
|
|
|
|
/// Input queued since the last call.
|
|
pub fn take_input() -> Vec<SeatEvent> {
|
|
let mut out = Vec::new();
|
|
unsafe {
|
|
loop {
|
|
let t = mp_kms_next_event();
|
|
if t == 0 {
|
|
break;
|
|
}
|
|
let (a, b) = (mp_kms_arg(1), mp_kms_arg(2));
|
|
match t {
|
|
1 => out.push(SeatEvent::PointerMove(PointerPos { x: a as f64, y: b as f64 })),
|
|
2 => out.push(SeatEvent::PointerButton(KeyState { code: a as u32, pressed: b != 0 })),
|
|
3 => out.push(SeatEvent::Key(KeyState { code: a as u32, pressed: b != 0 })),
|
|
4 => out.push(SeatEvent::Modifiers(Modifiers {
|
|
depressed: a as u32,
|
|
latched: b as u32,
|
|
locked: mp_kms_arg(3) as u32,
|
|
group: mp_kms_arg(4) as u32,
|
|
})),
|
|
5 => out.push(SeatEvent::Scroll(ScrollDelta {
|
|
axis: a as u32,
|
|
value: b as f64 / 256.0,
|
|
discrete: mp_kms_arg(3),
|
|
})),
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
pub fn close() {
|
|
unsafe { mp_kms_close() };
|
|
}
|