diff --git a/compositor/app/app.mbt b/compositor/app/app.mbt index 6a5cbcc..ae53bde 100644 --- a/compositor/app/app.mbt +++ b/compositor/app/app.mbt @@ -62,6 +62,7 @@ pub fn run(args : Array[String]) -> Int { let mut login = false let mut restore = true let mut kiosk : String? = None + let mut kiosk_hybrid = false let mut app_id = "chandra" let mut width = 1280 let mut height = 720 @@ -97,6 +98,13 @@ pub fn run(args : Array[String]) -> Int { kiosk = Some(args[i + 1]) // one fullscreen app, locked down restore = false i = i + 2 + } else if a == "--kiosk-hybrid" { + kiosk_hybrid = true // with --kiosk: keep the panel and the desktop, lock only leaving + if kiosk is None { + kiosk = Some("") + } + restore = false + i = i + 1 } else if a == "--app-id" && i + 1 < args.length() { app_id = args[i + 1] i = i + 2 @@ -251,7 +259,7 @@ pub fn run(args : Array[String]) -> Int { match kiosk { Some(cmd) => { @sys.log("kiosk mode" + (if cmd.length() > 0 { ": " + cmd } else { "" })) - comp.start_kiosk(cmd) + comp.start_kiosk(cmd, hybrid=kiosk_hybrid) } None => () } diff --git a/compositor/bin/main.mbt b/compositor/bin/main.mbt index ccbc955..6f696e6 100644 --- a/compositor/bin/main.mbt +++ b/compositor/bin/main.mbt @@ -13,6 +13,7 @@ fn main { let mut fullscreen = false let mut restore = true let mut kiosk : String? = None + let mut kiosk_hybrid = false let mut app_id = "chandra" let mut width = 1280 let mut height = 720 @@ -42,6 +43,13 @@ fn main { kiosk = Some(args[i + 1]) // one fullscreen app, locked down (docs/kiosk.md) restore = false i = i + 2 + } else if a == "--kiosk-hybrid" { + kiosk_hybrid = true // with --kiosk: keep the panel and the desktop, lock only leaving + if kiosk is None { + kiosk = Some("") + } + restore = false + i = i + 1 } else if a == "--app-id" && i + 1 < args.length() { app_id = args[i + 1] // WM_CLASS of the X11 window i = i + 2 @@ -162,7 +170,7 @@ fn main { // 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) + Some(cmd) => comp.start_kiosk(cmd, hybrid=kiosk_hybrid) None => () } if drm { diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index 4b79712..4382256 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -346,7 +346,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, kiosk=self.kiosk_locked()) + self.work_area = work_area_for(w, h, self.theme, kiosk=self.kiosk_strict()) self.close_overlay() // its frozen frame is the old size self.stop_recording() self.server.set_output_size(w, h) @@ -1397,6 +1397,9 @@ pub fn ChandraCompositor::apply_theme(self : ChandraCompositor) -> Unit { ///| Carry out what panel modules asked for: focus a window, switch layout. fn ChandraCompositor::run_shell_actions(self : ChandraCompositor) -> Unit { for a in self.shell.take_actions() { + if self.kiosk_refuses(a) { + continue + } match a { @shell.ShellAction::FocusWindow(wid) => self.activate_task(wid) @shell.ShellAction::Logout => self.quit_requested = true @@ -1734,11 +1737,11 @@ pub fn ChandraCompositor::handle_input( return } // Right button over a swappable panel widget opens its alternatives menu. - if button == 273U && pressed && !self.kiosk_locked() && self.shell.right_click(xi, yi) { + if button == 273U && pressed && !self.kiosk_strict() && 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.kiosk_locked() && self.window_at(xi, yi) is None && + if button == 273U && pressed && !self.kiosk_strict() && self.window_at(xi, yi) is None && !self.shell.hit(xi, yi) && self.shell.desktop_menu(xi, yi) { return } @@ -1817,9 +1820,9 @@ pub fn ChandraCompositor::handle_input( self.super_solo = false } else if self.switcher_key(code, pressed, time_ms) { self.super_solo = false - } else if !self.kiosk_locked() && self.shortcut_key(code, pressed) { + } else if !self.kiosk_strict() && self.shortcut_key(code, pressed) { self.super_solo = false - } else if self.kiosk_locked() && (code == 125U || code == 126U) { + } else if self.kiosk_strict() && (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 { diff --git a/compositor/host/control.mbt b/compositor/host/control.mbt index 967ac80..82be04b 100644 --- a/compositor/host/control.mbt +++ b/compositor/host/control.mbt @@ -260,7 +260,7 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin 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) + (["ok " + (if k.locked { "locked" } else { "unlocked" }) + (if k.hybrid { " hybrid" } else { "" }) + " starts=" + k.starts.to_string() + " cmd=" + k.cmd], true) (Some(_), "lock") => { ignore(self.set_kiosk_locked(true)) (["ok locked"], true) diff --git a/compositor/host/kiosk.mbt b/compositor/host/kiosk.mbt index 9a45718..852d769 100644 --- a/compositor/host/kiosk.mbt +++ b/compositor/host/kiosk.mbt @@ -10,6 +10,11 @@ /// 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). /// +/// **Hybrid** (`--kiosk-hybrid`): a full desktop that can't be left. The panel, the launcher, the +/// dock, the desktop module (an icon desktop, a game library) and the shortcuts all work and +/// windows are laid out as usual; only leaving is locked: Log out and the power actions (suspend, +/// restart, power off) are refused with a notice. CMD is still started and restarted. +/// /// 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. @@ -23,6 +28,8 @@ 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 + /// Hybrid: the desktop stays (panel, desktop module, shortcuts); only leaving it is locked. + hybrid : Bool mut locked : Bool /// When the app was last started (0: never). mut started_at : UInt64 @@ -37,8 +44,8 @@ pub(all) struct Kiosk { } ///| -pub fn Kiosk::new(cmd : String) -> Kiosk { - { cmd, locked: true, started_at: 0UL, seen_window: false, gone_at: 0UL, fails: 0, starts: 0 } +pub fn Kiosk::new(cmd : String, hybrid? : Bool = false) -> Kiosk { + { cmd, hybrid, 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. @@ -107,12 +114,12 @@ pub fn Kiosk::waiting(self : Kiosk, has_window : Bool) -> Bool { } ///| 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)) +pub fn ChandraCompositor::start_kiosk(self : ChandraCompositor, cmd : String, hybrid? : Bool = false) -> Unit { + self.kiosk = Some(Kiosk::new(cmd, hybrid~)) self.apply_kiosk_lock() } -///| Whether the kiosk is on and locked. +///| Whether the kiosk is on and locked (either kind: leaving the session is refused). pub fn ChandraCompositor::kiosk_locked(self : ChandraCompositor) -> Bool { match self.kiosk { Some(k) => k.locked @@ -120,6 +127,30 @@ pub fn ChandraCompositor::kiosk_locked(self : ChandraCompositor) -> Bool { } } +///| Whether a single-app kiosk is locked: no panel, no shortcuts or menus, windows fullscreen. +/// False for a hybrid kiosk, which keeps the desktop. +pub fn ChandraCompositor::kiosk_strict(self : ChandraCompositor) -> Bool { + match self.kiosk { + Some(k) => k.locked && !k.hybrid + None => false + } +} + +///| A locked kiosk refuses to end the session: Log out and suspend / restart / power off. +/// True when `action` was refused (a notice says so). +fn ChandraCompositor::kiosk_refuses(self : ChandraCompositor, action : @shell.ShellAction) -> Bool { + if !self.kiosk_locked() { + return false + } + match action { + Logout | SystemPower(_) => { + self.shell.say("Not available in kiosk mode") + true + } + _ => 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 { @@ -138,7 +169,7 @@ pub fn ChandraCompositor::set_kiosk_locked(self : ChandraCompositor, locked : Bo ///| 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() + let locked = self.kiosk_strict() self.shell.hide_panel = locked if locked { self.shell.close_launcher() @@ -195,7 +226,7 @@ fn ChandraCompositor::kiosk_tick(self : ChandraCompositor) -> Unit { @sys.log("kiosk: could not start '" + k.cmd + "'") } } - if k.locked { + if k.locked && !k.hybrid { self.kiosk_fullscreen_all() } } diff --git a/compositor/host/kiosk_test.mbt b/compositor/host/kiosk_test.mbt index 43c17fc..888554c 100644 --- a/compositor/host/kiosk_test.mbt +++ b/compositor/host/kiosk_test.mbt @@ -169,3 +169,41 @@ test "chandra-ctl kiosk: status, unlock, lock; an error outside kiosk mode" { assert_eq(ask(comp, path, "kiosk bogus"), ["error usage: kiosk [lock|unlock|status]"]) comp.close() } + +///| +test "a hybrid kiosk keeps the panel, the shortcuts and the layout; only leaving is refused" { + let socket_path = "/tmp/wayland-moon-kioskh-" + @sys.getpid().to_string() + ".sock" + let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() + ignore(comp.compose_frame()) + comp.start_kiosk("", hybrid=true) + assert_true(comp.kiosk_locked()) + assert_false(comp.kiosk_strict()) + let clients = open_windows(comp, socket_path, 2) + for _i = 0; _i < 5; _i = _i + 1 { + comp.step() + } + ignore(comp.compose_scene()) + // The panel is there and windows are tiled as usual, not fullscreen. + assert_true(comp.shell.panel_rect.h > 0) + for _, win in comp.windows { + assert_false(win.fullscreen) + assert_true(win.geometry.w < 1280) + } + // The launcher opens with the Super tap. + kiosk_press(comp, [125U], 10U) + assert_true(comp.shell.launcher_open()) + kiosk_press(comp, [1U], 12U) + // Log out is refused while locked, and works once the admin unlocked it. + comp.shell.actions.push(@shell.ShellAction::Logout) + comp.damage.mark_full() + ignore(comp.compose_scene()) + assert_false(comp.quit_requested) + kiosk_escape(comp, 20U) + assert_false(comp.kiosk_locked()) + comp.shell.actions.push(@shell.ShellAction::Logout) + comp.damage.mark_full() + ignore(comp.compose_scene()) + assert_true(comp.quit_requested) + ignore(clients) + comp.close() +} diff --git a/docs/kiosk.md b/docs/kiosk.md index 358b684..438b4c5 100644 --- a/docs/kiosk.md +++ b/docs/kiosk.md @@ -21,6 +21,18 @@ While the kiosk is **locked** (it starts locked): growing delay (1 s, 2 s, 4 s ... 30 s) if it keeps dying within 10 s of starting. `""` starts nothing. +## Hybrid kiosk + +`--kiosk-hybrid` (alone, or with `--kiosk CMD`) keeps the whole desktop and locks only the way +out: the panel, the launcher, the dock, the desktop module (Icon Desktop, a game library), the +shortcuts and the usual window layout all work, while Log out and suspend / restart / power off +are refused with a notice. `CMD`, if given, is started and restarted as above (when no window at +all is left). + +``` +build/wasmhost build/compositor.wasm --x11 --fullscreen --app-id gamerig-desktop --kiosk-hybrid +``` + **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`.