Lock: add session lock from power button and chandra-ctl lock
CI / test (push) Failing after 52s

- Lock the session from the power button or `chandra-ctl lock`
- Unlock with a face or the password; the password always works
- Add compositor lock module with tests, and a polkit unlock policy (org.chandra.unlock)
- Document the lock flow in docs/lock.md and link it from the README
- Add generated interface bindings for the compositor and widget components
This commit is contained in:
nandi committed 2026-11-29 03:24:46 -08:00
1 parent 7501fc3ad9
commit c790f96e58
131 files changed
+4693 -274

No files matched your search

+16
View File
@@ -417,6 +417,16 @@ pub fn publish_screenshot(state : Int) -> Unit {
@hostpl.publish_screenshot(state.reinterpret_as_uint())
}
///| Publish whether the built-in on-screen keyboard is currently visible.
pub fn publish_osk(visible : Bool) -> Unit {
@hostpl.publish_osk(visible)
}
///| Publish the current display rotation (0=0, 1=90 CW, 2=180, 3=270 CW).
pub fn publish_rotation(rot : Int) -> Unit {
@hostpl.publish_rotation(rot.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())
@@ -473,6 +483,10 @@ pub(all) enum HostRequest {
FaceUnlock(Int)
/// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh.
GameLibrary(Int, String, String)
/// The osk capability: show (true) or hide (false) the on-screen keyboard.
SetOskVisible(Bool)
/// The rotation capability: set display orientation (0..3).
SetRotation(Int)
} derive(Eq, Debug)
///|
@@ -502,6 +516,8 @@ pub fn next_request() -> HostRequest? {
Some(SetDesktop(i)) => Some(SetDesktop(i))
Some(FaceUnlock(i)) => Some(FaceUnlock(i))
Some(GameLibrary(r)) => Some(GameLibrary(r.action, r.game, r.mode))
Some(SetOskVisible(v)) => Some(SetOskVisible(v))
Some(SetRotation(r)) => Some(SetRotation(r))
}
}
+16
View File
@@ -831,6 +831,16 @@ pub fn publish_screenshot(state : Int) -> Unit {
c_host_set_int(4, state)
}
///| Publish whether the built-in on-screen keyboard is currently visible.
pub fn publish_osk(visible : Bool) -> Unit {
c_host_set_int(11, if visible { 1 } else { 0 })
}
///| Publish the current display rotation (0=0, 1=90 CW, 2=180, 3=270 CW).
pub fn publish_rotation(rot : Int) -> Unit {
c_host_set_int(12, rot)
}
///| 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)
@@ -891,6 +901,10 @@ pub(all) enum HostRequest {
FaceUnlock(Int)
/// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh.
GameLibrary(Int, String, String)
/// The osk capability: show (true) or hide (false) the on-screen keyboard.
SetOskVisible(Bool)
/// The rotation capability: set display orientation (0..3).
SetRotation(Int)
} derive(Eq, Debug)
///|
@@ -933,6 +947,8 @@ pub fn next_request() -> HostRequest? {
18 => Some(Shortcut(c_host_req_int()))
19 => Some(DefaultApp(c_host_req_int()))
20 => Some(SetBrightness(c_host_req_int()))
21 => Some(SetOskVisible(c_host_req_int() != 0))
22 => Some(SetRotation(c_host_req_int()))
40 => Some(SetDesktop(c_host_req_int()))
44 => Some(FaceUnlock(c_host_req_int()))
45 => {
+16 -2
View File
@@ -68,7 +68,8 @@ enum {
K_DA_CATS, K_DA_APPS, K_DA_SET, K_DA_REFRESH,
K_DESKTOPS, K_DESKTOP_CUR, K_SET_DESKTOP,
K_FU_STATUS, K_FU_FACES, K_FU_ENROLL, K_FU_REMOVE, K_FU_SET_IN_USE, K_FU_REFRESH,
K_GL_STATUS, K_GL_GAMES, K_GL_MODES, K_GL_LAUNCH, K_GL_STOP, K_GL_FOCUS, K_GL_REFRESH
K_GL_STATUS, K_GL_GAMES, K_GL_MODES, K_GL_LAUNCH, K_GL_STOP, K_GL_FOCUS, K_GL_REFRESH,
K_OSK_IS_VISIBLE, K_OSK_SET_VISIBLE, K_ROT_CURRENT, K_ROT_SET
};
typedef struct Env { Inst *inst; int kind; } Env;
@@ -85,7 +86,8 @@ static int32_t host_ints[24] = {[7] = -1, [10] = -1}; /* 0 layout mode, 1 inspec
4 screenshot state (bit 0 recording, bit 1 pointer in recordings),
5 screen-off minutes, 6 suspend minutes (0: never),
7 battery percent (-1: none), 8 battery charge-state, 9 battery seconds left,
10 backlight brightness percent (-1: none) */
10 backlight brightness percent (-1: none), 11 osk visible (0/1),
12 display rotation (0..3) */
/* ---- 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;
@@ -493,6 +495,14 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL((host_ints[4] >> 1) & 1);
break;
case K_INSPECT_SET: push_req(4, a0, NULL); break;
case K_OSK_IS_VISIBLE:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[11] != 0);
break;
case K_OSK_SET_VISIBLE: push_req(21, a0 != 0, NULL); break;
case K_ROT_CURRENT:
if (results->size >= 1) results->data[0] = (wasm_val_t)WASM_I32_VAL(host_ints[12]);
break;
case K_ROT_SET: push_req(22, a0, NULL); break;
case K_MOD_BROWSE: push_req(7, 0, NULL); break;
case K_MOD_LOAD: { char *s = guest_str(in, a0, a1); push_req(5, 0, s); free(s); break; }
case K_MOD_UNLOAD: { char *s = guest_str(in, a0, a1); push_req(6, 0, s); free(s); break; }
@@ -702,6 +712,10 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "layout-control") && !strcmp(fn, "set-layout")) return K_SET_LAYOUT;
if (!strcmp(iface, "inspector") && !strcmp(fn, "is-on")) return K_INSPECT_IS_ON;
if (!strcmp(iface, "inspector") && !strcmp(fn, "set-on")) return K_INSPECT_SET;
if (!strcmp(iface, "osk") && !strcmp(fn, "is-visible")) return K_OSK_IS_VISIBLE;
if (!strcmp(iface, "osk") && !strcmp(fn, "set-visible")) return K_OSK_SET_VISIBLE;
if (!strcmp(iface, "rotation") && !strcmp(fn, "current")) return K_ROT_CURRENT;
if (!strcmp(iface, "rotation") && !strcmp(fn, "set-rotation")) return K_ROT_SET;
if (!strcmp(iface, "modules") && !strcmp(fn, "available")) return K_MOD_AVAILABLE;
if (!strcmp(iface, "modules") && !strcmp(fn, "loaded")) return K_MOD_LOADED;
if (!strcmp(iface, "modules") && !strcmp(fn, "load-module")) return K_MOD_LOAD;
+30
View File
@@ -278,3 +278,33 @@ test "moon and digital clock modules render from the clock capability" {
assert_true(ts[0].has_suffix("AM") || ts[0].has_suffix("PM")) // 12-hour by default
c.unload()
}
///|
test "osk module toggles through the osk capability" {
let p = load_module("osk")
assert_true(p.imports().contains("osk"))
publish_osk(false)
assert_true(texts_of(p.render(44, 34, test_tokens())).contains("KB"))
assert_true(p.popup() is None)
assert_true(p.on_event(false, PointerDown(5, 5)))
assert_eq(drain(), [SetOskVisible(true)])
publish_osk(true)
assert_true(p.on_event(false, PointerDown(5, 5)))
assert_eq(drain(), [SetOskVisible(false)])
p.unload()
}
///|
test "rotate module cycles orientation through the rotation capability" {
let p = load_module("rotate")
assert_true(p.imports().contains("rotation"))
publish_rotation(0)
assert_true(texts_of(p.render(44, 34, test_tokens())).contains("Rot"))
assert_true(p.popup() is None)
assert_true(p.on_event(false, PointerDown(5, 5)))
assert_eq(drain(), [SetRotation(1)])
publish_rotation(3)
assert_true(p.on_event(false, PointerDown(5, 5)))
assert_eq(drain(), [SetRotation(0)])
p.unload()
}