Kiosk mode: --kiosk CMD runs one fullscreen app, locked down, restarted when it exits
CI / test (push) Successful in 4m10s
CI / test (push) Successful in 4m10s
No panel, no compositor shortcuts or desktop menus, the focused window fullscreen (dialogs float), CMD restarted with backoff. Ctrl+Alt+Shift+Escape or chandra-ctl kiosk lock|unlock|status for admin work. --app-id sets the X11 WM_CLASS / Wayland app id of Chandra's own window. scripts/gamerig-kiosk.sh runs Chandra as a gamerig rig's library window on its NVIDIA Xorg. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgvjzw8hHirxRsXSsE
This commit is contained in:
11 files changed
+635
-16
No files matched your search
@@ -0,0 +1,171 @@
|
||||
///| Kiosk mode (kiosk.mbt): the restart rules, the lockdown, the admin escape and chandra-ctl.
|
||||
|
||||
///|
|
||||
test "kiosk restarts: first start, grace for the first window, quick restart, backoff" {
|
||||
let k = @host.Kiosk::new("app")
|
||||
let t0 = 1000000UL
|
||||
// Nothing started yet: start now.
|
||||
assert_true(k.should_start(t0, false))
|
||||
k.started(t0)
|
||||
// No window yet, within the grace: wait.
|
||||
assert_false(k.should_start(t0 + 5000UL, false))
|
||||
// The window shows, runs a while, then goes: started again right away.
|
||||
assert_false(k.should_start(t0 + 6000UL, true))
|
||||
assert_false(k.should_start(t0 + 60000UL, true))
|
||||
assert_true(k.should_start(t0 + 61000UL, false))
|
||||
assert_eq(k.fails, 0)
|
||||
k.started(t0 + 61000UL)
|
||||
// It dies within seconds, several times: 1 s, 2 s, 4 s between starts.
|
||||
let mut t = t0 + 61000UL
|
||||
for want in [1000UL, 2000UL, 4000UL] {
|
||||
assert_false(k.should_start(t + 500UL, true))
|
||||
assert_false(k.should_start(t + 1000UL, false)) // gone; the backoff starts here
|
||||
assert_false(k.should_start(t + 1000UL + want - 1UL, false))
|
||||
assert_true(k.should_start(t + 1000UL + want, false))
|
||||
t = t + 1000UL + want
|
||||
k.started(t)
|
||||
}
|
||||
assert_eq(k.starts, 5)
|
||||
// Never shows a window: tried again after the grace (plus the backoff).
|
||||
let k2 = @host.Kiosk::new("app")
|
||||
assert_true(k2.should_start(t0, false))
|
||||
k2.started(t0)
|
||||
assert_false(k2.should_start(t0 + @host.kiosk_start_grace_ms - 1UL, false))
|
||||
assert_true(k2.should_start(t0 + @host.kiosk_start_grace_ms, false))
|
||||
// No command: never starts anything.
|
||||
let k3 = @host.Kiosk::new("")
|
||||
assert_false(k3.should_start(t0, false))
|
||||
assert_eq(@host.kiosk_backoff_ms(0), 0UL)
|
||||
assert_eq(@host.kiosk_backoff_ms(20), 30000UL)
|
||||
}
|
||||
|
||||
///|
|
||||
fn kiosk_press(comp : @host.ChandraCompositor, codes : Array[UInt], t : UInt) -> Unit {
|
||||
for c in codes {
|
||||
comp.handle_input(@nested.InputEvent::Key(c, true), t)
|
||||
}
|
||||
for i = codes.length() - 1; i >= 0; i = i - 1 {
|
||||
comp.handle_input(@nested.InputEvent::Key(codes[i], false), t + 1U)
|
||||
}
|
||||
}
|
||||
|
||||
///| Ctrl+Alt+Shift+Escape, with the modifier state a backend reports alongside the keys.
|
||||
fn kiosk_escape(comp : @host.ChandraCompositor, t : UInt) -> Unit {
|
||||
for c in [29U, 56U, 42U] {
|
||||
comp.handle_input(@nested.InputEvent::Key(c, true), t)
|
||||
}
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(1U | 4U | 8U, 0U, 0U, 0U), t)
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, true), t)
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, false), t + 1U)
|
||||
for c in [42U, 56U, 29U] {
|
||||
comp.handle_input(@nested.InputEvent::Key(c, false), t + 1U)
|
||||
}
|
||||
comp.handle_input(@nested.InputEvent::Modifiers(0U, 0U, 0U, 0U), t + 1U)
|
||||
}
|
||||
|
||||
///|
|
||||
test "a locked kiosk: no panel, fullscreen windows, no shortcuts; the admin escape unlocks it" {
|
||||
let socket_path = "/tmp/wayland-moon-kiosk-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
ignore(comp.compose_frame())
|
||||
assert_true(comp.shell.panel_rect.h > 0) // a normal desktop has its panel
|
||||
comp.start_kiosk("")
|
||||
assert_true(comp.kiosk_locked())
|
||||
let clients = open_windows(comp, socket_path, 2)
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
}
|
||||
ignore(comp.compose_scene())
|
||||
// No panel, and the focused window covers the whole screen, undecorated; the other waits behind.
|
||||
assert_eq(comp.shell.panel_rect.h, 0)
|
||||
assert_eq(comp.windows.size(), 2)
|
||||
let full = fn() raise {
|
||||
let out = []
|
||||
for id, win in comp.windows {
|
||||
if win.fullscreen {
|
||||
assert_true(win.focused)
|
||||
assert_eq((win.geometry.x, win.geometry.y, win.geometry.w, win.geometry.h), (0, 0, 1280, 720))
|
||||
out.push(id)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
let first = full()
|
||||
assert_eq(first.length(), 1)
|
||||
// Alt+Tab: the other window becomes the fullscreen one.
|
||||
kiosk_press(comp, [56U, 15U], 5U)
|
||||
comp.step()
|
||||
let second = full()
|
||||
assert_eq(second.length(), 1)
|
||||
assert_true(second[0] != first[0])
|
||||
// Super tap, Super+D, Print: nothing happens.
|
||||
kiosk_press(comp, [125U], 10U)
|
||||
assert_false(comp.shell.launcher_open())
|
||||
assert_false(comp.overview_open())
|
||||
kiosk_press(comp, [125U, 17U], 20U) // Super+W
|
||||
assert_false(comp.overview_open())
|
||||
// Ctrl+Alt+Shift+Escape: unlocked, the panel and the launcher are back, windows leave fullscreen.
|
||||
kiosk_escape(comp, 30U)
|
||||
assert_false(comp.kiosk_locked())
|
||||
ignore(comp.compose_scene())
|
||||
assert_true(comp.shell.panel_rect.h > 0)
|
||||
comp.step()
|
||||
for _, win in comp.windows {
|
||||
assert_false(win.fullscreen)
|
||||
}
|
||||
kiosk_press(comp, [125U], 40U)
|
||||
assert_true(comp.shell.launcher_open())
|
||||
kiosk_press(comp, [1U], 50U) // Escape closes it
|
||||
// And locked again.
|
||||
kiosk_escape(comp, 60U)
|
||||
assert_true(comp.kiosk_locked())
|
||||
for _i = 0; _i < 3; _i = _i + 1 {
|
||||
comp.step()
|
||||
}
|
||||
ignore(comp.compose_scene())
|
||||
assert_eq(comp.shell.panel_rect.h, 0)
|
||||
assert_false(comp.shell.launcher_open())
|
||||
assert_eq(full().length(), 1)
|
||||
ignore(clients)
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "the kiosk starts its app, and again when its window is gone" {
|
||||
let socket_path = "/tmp/wayland-moon-kiosk2-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let out = "/tmp/chandra-kiosk-spawn-" + @sys.getpid().to_string()
|
||||
comp.start_kiosk("sh -c 'echo started >> " + out + "'")
|
||||
assert_true(comp.kiosk_waiting())
|
||||
comp.step()
|
||||
let mut text = ""
|
||||
for _i = 0; _i < 100 && text.length() == 0; _i = _i + 1 {
|
||||
@sys.sleep_ms(20)
|
||||
text = @utf8.decode_lossy(@sys.read_file_bytes(out))
|
||||
}
|
||||
assert_eq(text, "started\n")
|
||||
// It showed no window, but the grace isn't over: no second start.
|
||||
comp.step()
|
||||
@sys.sleep_ms(100)
|
||||
assert_eq(@utf8.decode_lossy(@sys.read_file_bytes(out)), "started\n")
|
||||
match comp.kiosk {
|
||||
Some(k) => assert_eq(k.starts, 1)
|
||||
None => fail("no kiosk")
|
||||
}
|
||||
ignore(@sys.spawn("rm -f " + out, ""))
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "chandra-ctl kiosk: status, unlock, lock; an error outside kiosk mode" {
|
||||
let (comp, path) = control_comp("kiosk")
|
||||
assert_eq(ask(comp, path, "kiosk"), ["error not in kiosk mode (start with --kiosk)"])
|
||||
comp.start_kiosk("")
|
||||
assert_eq(ask(comp, path, "kiosk status"), ["ok locked starts=0 cmd="])
|
||||
assert_eq(ask(comp, path, "kiosk unlock"), ["ok unlocked"])
|
||||
assert_false(comp.kiosk_locked())
|
||||
assert_eq(ask(comp, path, "kiosk lock"), ["ok locked"])
|
||||
assert_true(comp.kiosk_locked())
|
||||
assert_eq(ask(comp, path, "kiosk bogus"), ["error usage: kiosk [lock|unlock|status]"])
|
||||
comp.close()
|
||||
}
|
||||
Reference in new issue
Block a user