Kiosk mode: --kiosk CMD runs one fullscreen app, locked down, restarted when it exits
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:
Claude committed 2026-11-26 02:22:03 +00:00
1 parent 4920f505e5
commit d521d0d840
11 files changed
+635 -16

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ interface** with **deny-by-default capabilities**:
Design: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) (Plasma to component mapping, permissions,
versioning) and [docs/compositor-design.md](docs/compositor-design.md) (the compositor and its
hosts). Toolchain notes: [docs/TOOLCHAIN.md](docs/TOOLCHAIN.md). Dark mode and the portal: [docs/dark-mode.md](docs/dark-mode.md). Running as root and run0:
[docs/run0.md](docs/run0.md). Picking up a new build without logging out (`just reload`, `chandra-ctl reload`): [docs/reloading.md](docs/reloading.md). Chandra as the kiosk shell of the gamerig streaming rigs (feasibility, gaps, plan): [docs/kiosk-gamerig.md](docs/kiosk-gamerig.md).
[docs/run0.md](docs/run0.md). Kiosk mode (`--kiosk CMD`, one fullscreen app, locked down): [docs/kiosk.md](docs/kiosk.md). Picking up a new build without logging out (`just reload`, `chandra-ctl reload`): [docs/reloading.md](docs/reloading.md). Chandra as the kiosk shell of the gamerig streaming rigs (feasibility, gaps, plan): [docs/kiosk-gamerig.md](docs/kiosk-gamerig.md).
## How it runs
+25 -3
View File
@@ -10,6 +10,10 @@
/// --drm runs as a login session: the host takes the display (DRM/KMS) and input (libinput).
/// With --gfx-out alone one frame is written and the program exits; add --serve to keep running
/// and rewrite the PNG about twice a second (for looking at a live compositor without a display).
/// --kiosk CMD: kiosk mode (docs/kiosk.md): no panel, no shortcuts or desktop menus, every window
/// fullscreen, CMD started and started again when its window goes ("" starts nothing);
/// Ctrl+Alt+Shift+Escape unlocks it for admin work. --app-id NAME: the X11 WM_CLASS / Wayland app
/// id of Chandra's own window (--x11, --window), so a window manager or wmctrl can find it.
///| Parse a decimal integer; None unless every character is a digit.
fn parse_dec(s : String) -> Int? {
@@ -57,6 +61,8 @@ pub fn run(args : Array[String]) -> Int {
let mut fullscreen = false
let mut login = false
let mut restore = true
let mut kiosk : String? = None
let mut app_id = "chandra"
let mut width = 1280
let mut height = 720
@@ -87,6 +93,13 @@ pub fn run(args : Array[String]) -> Int {
} else if a == "--no-restore" {
restore = false // don't reopen the apps of the last session
i = i + 1
} else if a == "--kiosk" && i + 1 < args.length() {
kiosk = Some(args[i + 1]) // one fullscreen app, locked down
restore = false
i = i + 2
} else if a == "--app-id" && i + 1 < args.length() {
app_id = args[i + 1]
i = i + 2
} else if a == "--profile" {
profile = true
i = i + 1
@@ -148,7 +161,7 @@ pub fn run(args : Array[String]) -> Int {
"" => ":0"
d => d
}
match @x11.X11Window::open(display, "Chandra", "chandra", width, height, fullscreen) {
match @x11.X11Window::open(display, "Chandra", app_id, width, height, fullscreen) {
Some(x) => {
width = x.width
height = x.height
@@ -217,7 +230,7 @@ pub fn run(args : Array[String]) -> Int {
"" => "/tmp"
d => d
}
match @nested.NestedWindow::open(display, rt, "chandra", "chandra", width, height) {
match @nested.NestedWindow::open(display, rt, "chandra", app_id, width, height) {
Some(n) => Some(n)
None => {
@sys.log("failed to open a window on the host Wayland display")
@@ -235,6 +248,13 @@ pub fn run(args : Array[String]) -> Int {
@sys.log("chandra compositor listening on " + socket_path)
// chandra-ctl's socket (reload panel modules from a script); SIGUSR1 reloads too.
ignore(comp.start_control(@host.control_socket_path(@sys.getenv("XDG_RUNTIME_DIR"), socket_path)))
match kiosk {
Some(cmd) => {
@sys.log("kiosk mode" + (if cmd.length() > 0 { ": " + cmd } else { "" }))
comp.start_kiosk(cmd)
}
None => ()
}
if login {
comp.start_auth_agent() // polkit's password prompts (run0, pkexec): Chandra's dialog
}
@@ -459,7 +479,9 @@ pub fn run(args : Array[String]) -> Int {
ignore(@sys.wait_readable(wait_fds, comp.wake_timeout(idle.timeout())))
}
}
comp.save_session() // what is open now is reopened at the next start
if kiosk is None {
comp.save_session() // what is open now is reopened at the next start
}
match kms {
Some(k) => k.close()
None => ()
+17 -2
View File
@@ -12,6 +12,8 @@ fn main {
let mut x11 = false
let mut fullscreen = false
let mut restore = true
let mut kiosk : String? = None
let mut app_id = "chandra"
let mut width = 1280
let mut height = 720
@@ -36,6 +38,13 @@ fn main {
} else if a == "--fullscreen" {
fullscreen = true
i = i + 1
} else if a == "--kiosk" && i + 1 < args.length() {
kiosk = Some(args[i + 1]) // one fullscreen app, locked down (docs/kiosk.md)
restore = false
i = i + 2
} else if a == "--app-id" && i + 1 < args.length() {
app_id = args[i + 1] // WM_CLASS of the X11 window
i = i + 2
} else if a == "--no-restore" {
restore = false // don't reopen the apps of the last session
i = i + 1
@@ -85,7 +94,7 @@ fn main {
Some(d) => d
None => ":0"
}
match @x11.X11Window::open(display, "Chandra", "chandra", width, height, fullscreen) {
match @x11.X11Window::open(display, "Chandra", app_id, width, height, fullscreen) {
Some(x) => {
width = x.width
height = x.height
@@ -152,6 +161,10 @@ fn main {
println("chandra compositor listening on " + socket_path + " (wasi-gfx surface active)")
// chandra-ctl's socket (reload panel modules from a script); SIGUSR1 reloads too.
ignore(comp.start_control(@host.control_socket_path(@sys.getenv("XDG_RUNTIME_DIR"), socket_path)))
match kiosk {
Some(cmd) => comp.start_kiosk(cmd)
None => ()
}
if drm {
comp.login_session = true
comp.start_auth_agent() // polkit's password prompts (run0, pkexec): Chandra's dialog
@@ -235,7 +248,9 @@ fn main {
}
@sys.sleep_ms(16)
}
comp.save_session() // what is open now is reopened at the next start
if kiosk is None {
comp.save_session() // what is open now is reopened at the next start
}
match kms {
Some(k) => k.close()
None => ()
+22 -8
View File
@@ -184,6 +184,8 @@ pub(all) struct ChandraCompositor {
mut rec_pointer : Bool
mut rec_press : Bool
mut last_recording : String
/// `--kiosk`: one fullscreen app, locked down (kiosk.mbt). None: a normal desktop.
mut kiosk : Kiosk?
/// Chandra's polkit agent (auth.mbt), while it is registered; the system bus socket it uses
/// ("" finds it); the dialog while it is up; key releases it swallows; how to reach polkit's
/// helper (empty: the usual routes; tests set their own); the keymap typing goes through.
@@ -306,6 +308,7 @@ pub fn ChandraCompositor::new(
rec_pointer: true,
rec_press: false,
last_recording: "",
kiosk: None,
}
// Client popups (menus) are placed to stay on screen: the server asks for the output's
// rectangle relative to the parent's content origin when it applies constraint adjustment.
@@ -317,7 +320,11 @@ pub fn ChandraCompositor::new(
}
///| The part of a `w` x `h` output windows are laid out in.
fn work_area_for(w : Int, h : Int, theme : @scene.ThemeTokens) -> @wm.Rect {
fn work_area_for(w : Int, h : Int, theme : @scene.ThemeTokens, kiosk~ : Bool = false) -> @wm.Rect {
if kiosk {
// A locked kiosk has no panel and its windows are fullscreen: the whole output.
return { x: 0, y: 0, w, h }
}
@wm.compute_work_area(
{ x: 0, y: 0, w, h },
excl_top=32, // room for the server-side title bar drawn above each client
@@ -333,7 +340,7 @@ pub fn ChandraCompositor::resize(self : ChandraCompositor, w : Int, h : Int) ->
}
self.output_w = w
self.output_h = h
self.work_area = work_area_for(w, h, self.theme)
self.work_area = work_area_for(w, h, self.theme, kiosk=self.kiosk_locked())
self.close_overlay() // its frozen frame is the old size
self.stop_recording()
self.server.set_output_size(w, h)
@@ -468,6 +475,7 @@ fn ChandraCompositor::configure_window(self : ChandraCompositor, win : HostWindo
///|
pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
self.flush_configures()
self.kiosk_tick()
self.portal_tick()
self.auth_tick()
self.control_tick()
@@ -704,7 +712,8 @@ pub fn ChandraCompositor::has_timed_work(self : ChandraCompositor) -> Bool {
self.thumbs_pending() ||
self.overview_animating() ||
self.shell.animating() ||
self.shell.face_busy()
self.shell.face_busy() ||
self.kiosk_waiting()
}
///| How long an idle main loop may sleep: `idle_ms` (until the wall clock's next second), or
@@ -1713,12 +1722,12 @@ pub fn ChandraCompositor::handle_input(
return
}
// Right button over a swappable panel widget opens its alternatives menu.
if button == 273U && pressed && self.shell.right_click(xi, yi) {
if button == 273U && pressed && !self.kiosk_locked() && self.shell.right_click(xi, yi) {
return
}
// Right button on the empty desktop: the desktop menu (module settings, system settings).
if button == 273U && pressed && self.window_at(xi, yi) is None && !self.shell.hit(xi, yi) &&
self.shell.desktop_menu(xi, yi) {
if button == 273U && pressed && !self.kiosk_locked() && self.window_at(xi, yi) is None &&
!self.shell.hit(xi, yi) && self.shell.desktop_menu(xi, yi) {
return
}
if pressed {
@@ -1792,9 +1801,14 @@ pub fn ChandraCompositor::handle_input(
}
}
Key(code, pressed) =>
if self.switcher_key(code, pressed, time_ms) {
if self.kiosk_key(code, pressed) {
self.super_solo = false
} else if self.shortcut_key(code, pressed) {
} else if self.switcher_key(code, pressed, time_ms) {
self.super_solo = false
} else if !self.kiosk_locked() && self.shortcut_key(code, pressed) {
self.super_solo = false
} else if self.kiosk_locked() && (code == 125U || code == 126U) {
// A locked kiosk: Super opens nothing and isn't passed on either.
self.super_solo = false
} else if code == 125U || code == 126U {
// Super (left/right): a bare tap runs the shortcut bound to "Super" (the launcher by
+18
View File
@@ -209,6 +209,7 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
"ping check the compositor answers", "list loaded panel modules: slot, module, path",
"reload load every panel module again from disk", "reload NAME only the modules whose name, slot or path is NAME",
"shortcut ID do what shortcut ID does (launcher, overview, show-desktop, ...)",
"kiosk [lock|unlock|status] kiosk mode (--kiosk): lock it down or unlock it for admin work",
"ok",
],
true,
@@ -254,6 +255,23 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
}
(["error no shortcut '" + words[1] + "'"], false)
}
"kiosk" => {
let arg = if words.length() >= 2 { words[1] } else { "status" }
match (self.kiosk, arg) {
(None, _) => (["error not in kiosk mode (start with --kiosk)"], false)
(Some(k), "status") =>
(["ok " + (if k.locked { "locked" } else { "unlocked" }) + " starts=" + k.starts.to_string() + " cmd=" + k.cmd], true)
(Some(_), "lock") => {
ignore(self.set_kiosk_locked(true))
(["ok locked"], true)
}
(Some(_), "unlock") => {
ignore(self.set_kiosk_locked(false))
(["ok unlocked"], true)
}
_ => (["error usage: kiosk [lock|unlock|status]"], false)
}
}
other => (["error unknown command '" + other + "' (try: help)"], false)
}
}
+251
View File
@@ -0,0 +1,251 @@
///| Kiosk mode (`--kiosk CMD`): one app, fullscreen, nothing else to click.
///
/// While the kiosk is locked: no panel (and no room kept for it), no compositor shortcuts (the
/// launcher, Super+D, screenshots, recordings, Super+1..9), no desktop or panel right-click
/// menus, and every top-level window without a parent is made fullscreen (dialogs, which name
/// a parent, stay centred floating windows). Alt+Tab still switches between the app's windows.
///
/// CMD (may be empty) is started with WAYLAND_DISPLAY set and started again whenever no
/// window is left: right away once its window has gone, or after `kiosk_start_grace_ms` if it
/// never showed one. An app that keeps dying soon after it starts is started with a growing
/// delay (1 s, 2 s, 4 s ... up to 30 s).
///
/// The admin escape Ctrl+Alt+Shift+Escape unlocks the kiosk (the panel, shortcuts and menus come
/// back, windows can leave fullscreen) and locks it again. `chandra-ctl kiosk lock|unlock|status`
/// does the same from a script.
///| How long a started app may take to show its first window before it is started again.
pub let kiosk_start_grace_ms : UInt64 = 20000UL
///| An app that dies within this long after it started counts as a failed start (backoff).
pub let kiosk_quick_exit_ms : UInt64 = 10000UL
///| The kiosk's state. `cmd` is what it runs; the rest is the respawn bookkeeping.
pub(all) struct Kiosk {
cmd : String
mut locked : Bool
/// When the app was last started (0: never).
mut started_at : UInt64
/// A window was seen since the last start.
mut seen_window : Bool
/// When the last window went away (0: a window is up, or none was seen yet).
mut gone_at : UInt64
/// Failed starts in a row (for the backoff).
mut fails : Int
/// Starts so far.
mut starts : Int
}
///|
pub fn Kiosk::new(cmd : String) -> Kiosk {
{ cmd, locked: true, started_at: 0UL, seen_window: false, gone_at: 0UL, fails: 0, starts: 0 }
}
///| Delay before starting again after `fails` failed starts in a row.
pub fn kiosk_backoff_ms(fails : Int) -> UInt64 {
if fails <= 0 {
return 0UL
}
let mut d = 1000UL
for i = 1; i < fails && d < 30000UL; i = i + 1 {
d = d * 2UL
}
if d > 30000UL {
30000UL
} else {
d
}
}
///| Whether the app should be started now, given whether any window is up. Also keeps the
/// bookkeeping: call it on every step with the current monotonic time.
pub fn Kiosk::should_start(self : Kiosk, now : UInt64, has_window : Bool) -> Bool {
if self.cmd.length() == 0 {
return false
}
if self.started_at == 0UL {
return true // first start
}
if has_window {
if !self.seen_window {
self.seen_window = true
}
self.gone_at = 0UL
return false
}
if self.seen_window {
// Its window went away (the app quit or crashed).
if self.gone_at == 0UL {
self.gone_at = now
if now - self.started_at < kiosk_quick_exit_ms {
self.fails = self.fails + 1
} else {
self.fails = 0
}
}
return now - self.gone_at >= kiosk_backoff_ms(self.fails)
}
// Started, but no window yet: give it time, then try again.
if now - self.started_at >= kiosk_start_grace_ms + kiosk_backoff_ms(self.fails) {
self.fails = self.fails + 1
return true
}
false
}
///| Record a start at `now`.
pub fn Kiosk::started(self : Kiosk, now : UInt64) -> Unit {
self.started_at = now
self.seen_window = false
self.gone_at = 0UL
self.starts = self.starts + 1
}
///| Whether a start is waiting for its time (the idle loop must wake for it).
pub fn Kiosk::waiting(self : Kiosk, has_window : Bool) -> Bool {
self.cmd.length() > 0 && !has_window
}
///| Turn kiosk mode on: lock the shell down and start `cmd` (if any) on the next step.
pub fn ChandraCompositor::start_kiosk(self : ChandraCompositor, cmd : String) -> Unit {
self.kiosk = Some(Kiosk::new(cmd))
self.apply_kiosk_lock()
}
///| Whether the kiosk is on and locked.
pub fn ChandraCompositor::kiosk_locked(self : ChandraCompositor) -> Bool {
match self.kiosk {
Some(k) => k.locked
None => false
}
}
///| Lock (true) or unlock (false) the kiosk. False when there is no kiosk.
pub fn ChandraCompositor::set_kiosk_locked(self : ChandraCompositor, locked : Bool) -> Bool {
match self.kiosk {
Some(k) => {
if k.locked != locked {
k.locked = locked
@sys.log("kiosk: " + (if locked { "locked" } else { "unlocked (admin)" }))
self.apply_kiosk_lock()
}
true
}
None => false
}
}
///| Make the shell and the layout follow the lock: panel shown or not, work area with or
/// without the panel's and title bars' room.
fn ChandraCompositor::apply_kiosk_lock(self : ChandraCompositor) -> Unit {
let locked = self.kiosk_locked()
self.shell.hide_panel = locked
if locked {
self.shell.close_launcher()
if self.switcher_on {
self.switcher_on = false
}
}
self.work_area = work_area_for(self.output_w, self.output_h, self.theme, kiosk=locked)
if !locked {
// Give the windows the kiosk made fullscreen back to the normal layout.
let ids : Array[UInt64] = []
for wid, win in self.windows {
if win.fullscreen {
ids.push(wid)
}
}
for wid in ids {
self.apply_actions(self.wm.handle_request(wid, @wm.WindowRequest::Fullscreen(false), self.work_area))
}
}
self.apply_actions(self.wm.fit_work_area(self.work_area))
self.last_frame = None
self.last_sig = None
self.frame_changed = true
self.damage.mark_full()
}
///| The admin escape: Ctrl+Alt+Shift+Escape toggles the lock. True when the key was taken.
fn ChandraCompositor::kiosk_key(self : ChandraCompositor, code : UInt, pressed : Bool) -> Bool {
if self.kiosk is None {
return false
}
let mods = self.held_mods()
if code == 1U && (mods & (@shell.mod_ctrl | @shell.mod_alt | @shell.mod_shift)) ==
(@shell.mod_ctrl | @shell.mod_alt | @shell.mod_shift) {
if pressed {
ignore(self.set_kiosk_locked(!self.kiosk_locked()))
}
return true
}
false
}
///| Once per step: start (or restart) the kiosk app, and keep its windows fullscreen.
fn ChandraCompositor::kiosk_tick(self : ChandraCompositor) -> Unit {
match self.kiosk {
None => ()
Some(k) => {
let now = @sys.monotonic_ms()
if k.should_start(now, self.windows.size() > 0) {
k.started(now)
@sys.log("kiosk: starting '" + k.cmd + "' (start " + k.starts.to_string() + ")")
if !@sys.spawn(k.cmd, self.shell.display) {
@sys.log("kiosk: could not start '" + k.cmd + "'")
}
}
if k.locked {
self.kiosk_fullscreen_all()
}
}
}
}
///| A locked kiosk's rule: the focused top-level window fills the screen (fullscreen, no frame);
/// the others wait behind it, and a dialog (a window with a parent) floats over it. Switching
/// windows (Alt+Tab, or the app activating another) moves the fullscreen to the new one.
fn ChandraCompositor::kiosk_fullscreen_all(self : ChandraCompositor) -> Unit {
let mut target : UInt64? = None
for wid, win in self.windows {
if win.focused && !self.server.toplevel_has_parent(wid) {
target = Some(wid)
}
}
if target is None {
// Nothing focused (a dialog has the keyboard, say): keep the one already fullscreen, else
// take any window without a parent.
for wid, win in self.windows {
if target is None && !self.server.toplevel_has_parent(wid) {
target = Some(wid)
}
if win.fullscreen && !self.server.toplevel_has_parent(wid) {
target = Some(wid)
}
}
}
let changed : Array[(UInt64, Bool)] = []
for wid, win in self.windows {
let want = target == Some(wid)
if win.fullscreen != want {
changed.push((wid, want))
}
}
// Leave fullscreen first, so the workspace's one fullscreen slot is free for the new window.
changed.sort_by((a, b) => if a.1 == b.1 { 0 } else if a.1 { 1 } else { -1 })
for c in changed {
self.apply_actions(self.wm.handle_request(c.0, @wm.WindowRequest::Fullscreen(c.1), self.work_area))
match self.windows.get(c.0) {
Some(win) => self.configure_window(win)
None => ()
}
}
}
///| Whether the kiosk has a start to make later (keeps an idle main loop waking).
pub fn ChandraCompositor::kiosk_waiting(self : ChandraCompositor) -> Bool {
match self.kiosk {
Some(k) => k.waiting(self.windows.size() > 0)
None => false
}
}
+171
View File
@@ -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()
}
+9 -1
View File
@@ -258,6 +258,8 @@ pub(all) struct DesktopShell {
mut booted : Bool
/// Read and write panel.edn (the compositor binary turns this on; tests leave it off).
mut persist : Bool
/// Kiosk mode (locked): no panel, no panel menus; the desktop module and popups stay.
mut hide_panel : Bool
/// Last floating position and size (x, y, w, h) of each app's window, by app id (persisted).
win_geoms : Map[String, (Int, Int, Int, Int)]
mut tokens : @theme.Tokens
@@ -444,6 +446,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
catalog_named: false,
booted: false,
persist: false,
hide_panel: false,
win_geoms: {},
tokens: conv_theme(@scene.ThemeTokens::moon_night()),
screen_w: 0,
@@ -1086,7 +1089,12 @@ pub fn DesktopShell::render(
let panel_ops : Array[@scene.DrawOp] = []
self.comps.clear()
self.panel_rect = { x: 0, y: 0, w: 0, h: 0 }
match @panel.layout(w, h, theme.panel_height, 4, tokens.spacing.reinterpret_as_int(), self.panel_slots()) {
let layout = if self.hide_panel {
Err("kiosk: no panel")
} else {
@panel.layout(w, h, theme.panel_height, 4, tokens.spacing.reinterpret_as_int(), self.panel_slots())
}
match layout {
Err(_) => ()
Ok(pl) => {
self.panel_rect = { x: pl.x, y: pl.y, w: pl.w, h: pl.h }
+35
View File
@@ -0,0 +1,35 @@
# Kiosk mode
`--kiosk CMD` turns Chandra into a single-app shell: a game-streaming rig's home screen, a
terminal on a stand, a wall display.
```
build/wasmhost build/compositor.wasm --socket "$XDG_RUNTIME_DIR/wayland-kiosk" --kiosk "foot"
build/wasmhost build/compositor.wasm --x11 --fullscreen --app-id gamerig-desktop --kiosk "my-launcher"
```
While the kiosk is **locked** (it starts locked):
* no panel, and no room kept for it;
* no compositor shortcuts: the Super tap, Super+D, Super+W, screenshots and recordings,
Super+1..9 all do nothing, and Super isn't passed to the app;
* no desktop or panel right-click menus;
* the focused window fills the screen (fullscreen, no frame); other windows wait behind it,
Alt+Tab brings them forward; dialogs (windows with a parent) float over it;
* `CMD` is started with `WAYLAND_DISPLAY` set (as every app Chandra starts), and started again
when no window is left: at once when its window goes, after 20 s if it never showed one, with a
growing delay (1 s, 2 s, 4 s ... 30 s) if it keeps dying within 10 s of starting. `""` starts
nothing.
**Admin escape:** Ctrl+Alt+Shift+Escape unlocks the kiosk (panel, shortcuts and menus come back,
windows leave fullscreen) and locks it again. From a script: `chandra-ctl kiosk unlock`,
`chandra-ctl kiosk lock`, `chandra-ctl kiosk status`.
A kiosk doesn't reopen the last session's windows and doesn't save its own.
`--app-id NAME` sets the X11 `WM_CLASS` (with `--x11`) or the Wayland app id (with `--window`) of
Chandra's own window, so a window manager rule or `wmctrl -xa NAME` can find it.
On a gamerig rig: `scripts/gamerig-kiosk.sh`, see [kiosk-gamerig.md](kiosk-gamerig.md).
Code: `compositor/host/kiosk.mbt`, tests in `compositor/host/kiosk_test.mbt`.
+84
View File
@@ -0,0 +1,84 @@
#!/bin/sh
# Run Chandra as the home screen of a gamerig rig (docs/kiosk-gamerig.md).
#
# On a rig, gamerig's onstart.sh brings up headless NVIDIA Xorg, Openbox, the library daemon
# (server.py on 127.0.0.1:8091) and Selkies, which streams the X screen. This script puts Chandra
# on that X screen in place of gamerig's own library window (shell_window.py, an X11 GTK window):
#
# * Chandra is one X client: a fullscreen window under Openbox whose WM_CLASS is gamerig-desktop,
# so gamerig's Openbox rules, Ctrl+Alt+L / Super+Space ("back to the library", wmctrl -xa) and
# server.py's focus calls find it exactly as they found the old window.
# * Inside it, Chandra runs in kiosk mode: no panel, no shortcuts, the library app fullscreen and
# restarted when it exits. Until there is a native launcher module the library app is the same
# shell_window.py, now a Wayland client of Chandra (GTK + WebKit on wl_shm).
# * Games and Steam don't go through Chandra: server.py starts them on Xorg with the NVIDIA
# driver, Openbox stacks them above Chandra, Selkies captures and injects input (XTest) as before.
#
# Usage (as root on the rig, after onstart.sh is up):
# gamerig-kiosk.sh replace the running library window with Chandra, and keep it running
# gamerig-kiosk.sh --check only print what it would use
#
# Environment: CHANDRA_DIR (default /opt/chandra: wasmhost, compositor.wasm, components/, wit/,
# config/, assets/, lib/), GAMERIG_DESKTOP_DIR (default /opt/gamerig-desktop), GAMERIG_DESKTOP_PORT
# (8091), DISPLAY (default: the first X socket), CHANDRA_KIOSK_APP (the app run in the kiosk;
# default gamerig's library window).
set -u
CHANDRA_DIR=${CHANDRA_DIR:-/opt/chandra}
GAMERIG_DESKTOP_DIR=${GAMERIG_DESKTOP_DIR:-/opt/gamerig-desktop}
PORT=${GAMERIG_DESKTOP_PORT:-8091}
LOG=${CHANDRA_KIOSK_LOG:-/var/log/chandra-kiosk.log}
if [ -z "${DISPLAY:-}" ]; then
for s in /tmp/.X11-unix/X*; do
[ -e "$s" ] || continue
DISPLAY=":${s##*/X}"
break
done
fi
export DISPLAY
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/runtime-chandra}
mkdir -p "$XDG_RUNTIME_DIR" && chmod 700 "$XDG_RUNTIME_DIR"
# The library app inside the kiosk. Chandra starts it with WAYLAND_DISPLAY set and DISPLAY unset,
# so GTK picks Wayland. WebKit gets no DMA-BUF renderer and no sandbox in a container (as onstart.sh).
APP=${CHANDRA_KIOSK_APP:-"env WEBKIT_DISABLE_DMABUF_RENDERER=1 WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1 NO_AT_BRIDGE=1 python3 $GAMERIG_DESKTOP_DIR/shell_window.py --url http://127.0.0.1:$PORT/"}
echo "chandra: $CHANDRA_DIR DISPLAY=$DISPLAY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
echo "kiosk app: $APP"
[ "${1:-}" = "--check" ] && exit 0
if [ ! -x "$CHANDRA_DIR/wasmhost" ] || [ ! -f "$CHANDRA_DIR/compositor.wasm" ]; then
echo "gamerig-kiosk: no Chandra build in $CHANDRA_DIR (wasmhost, compositor.wasm)" >&2
exit 1
fi
# Stop gamerig's own library window: first its supervisor (onstart.sh's run_library_window_supervisor,
# a bash subshell that is the window's parent), then the window, so it isn't reopened.
for pid in $(pgrep -f "$GAMERIG_DESKTOP_DIR/shell_window.py" 2>/dev/null); do
ppid=$(awk '{print $4}' "/proc/$pid/stat" 2>/dev/null)
# run_with_dbus may sit between them: walk up to the supervising bash.
while [ -n "$ppid" ] && [ "$ppid" -gt 1 ]; do
case "$(cat "/proc/$ppid/comm" 2>/dev/null)" in
bash|onstart.sh) kill "$ppid" 2>/dev/null; break ;;
esac
ppid=$(awk '{print $4}' "/proc/$ppid/stat" 2>/dev/null)
done
kill "$pid" 2>/dev/null
done
# Keep Chandra running: started again (after a second, then backing off to 30 s) if it exits.
cd "$CHANDRA_DIR" || exit 1
export LD_LIBRARY_PATH="$CHANDRA_DIR/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
delay=1
while true; do
start=$(date +%s)
echo "$(date -u +%FT%TZ) starting chandra (kiosk)" >>"$LOG"
./wasmhost compositor.wasm --x11 --fullscreen --app-id gamerig-desktop \
--socket "$XDG_RUNTIME_DIR/wayland-chandra" --kiosk "$APP" >>"$LOG" 2>&1
rc=$?
[ $(( $(date +%s) - start )) -ge 30 ] && delay=1
echo "$(date -u +%FT%TZ) chandra exited ($rc); again in ${delay}s" >>"$LOG"
sleep "$delay"
delay=$(( delay * 2 > 30 ? 30 : delay * 2 ))
done
+2 -1
View File
@@ -6,6 +6,7 @@
chandra-ctl list the loaded panel modules: slot, module, path
chandra-ctl ping check the compositor answers
chandra-ctl shortcut ID do what a keyboard shortcut does (overview, launcher, show-desktop...)
chandra-ctl kiosk [lock|unlock|status] kiosk mode (--kiosk, docs/kiosk.md)
The socket is $XDG_RUNTIME_DIR/chandra/<wayland socket name>.sock (the session's is
wayland-moon-0.sock). It is found in this order: --socket PATH, $CHANDRA_CONTROL, the one for
@@ -18,7 +19,7 @@ import os
import socket
import sys
USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | help}"
USAGE = "usage: chandra-ctl [--socket PATH] [--quiet] {reload [NAME] | list | ping | shortcut ID | kiosk [lock|unlock|status] | help}"
def runtime_dir():