Gamerig Library: gamerig's game library as a Chandra desktop module
CI / test (push) Successful in 2m25s

- New desktop module gamerig-library (components/gamerig-library, logic in lib/gamelib): the
  layout of gamerig's web library (desktop/ui) in draw ops. Top bar with the Gamerig mark, app
  count and search; sidebar with categories and counts, running apps (switch to, stop) and rig
  status (GPU, display, audio); card grid with featured games two columns wide, icon tiles,
  category and status badges, description, install hint, Launch / Big Picture / Switch to / Stop.
  Typing filters, arrows + Enter launch, the wheel scrolls. Colours: follow desktop, dark, light.
- New game-library capability: tables 26-28 (status, games, launch modes), request 45, in the
  wasmer/wasmtime stub, the MoonBit wasmhost and the Rust host-wasm.
- compositor/shell/gamelib.mbt polls GET $GAMERIG_DESKTOP_API/api/state (default
  http://127.0.0.1:8091) every 2 s with curl on a socket and POSTs launch/stop/focus; a file://
  base reads a state file (tests).
- --desktop NAME picks what fills the desktop at start. scripts/gamerig-kiosk.sh now runs a
  hybrid kiosk with the library as the desktop (CHANDRA_KIOSK_MODE=strict for the old one).
- Tests: lib/gamelib, compositor/host/gamelib_test.mbt, a host-wasm test; docs/gamerig-library.md
  with a screenshot.

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:57:07 +00:00
1 parent fa932f9ac0
commit f556df2f4b
57 files changed
+3551 -29

No files matched your search

+7
View File
@@ -63,6 +63,7 @@ pub fn run(args : Array[String]) -> Int {
let mut restore = true
let mut kiosk : String? = None
let mut kiosk_hybrid = false
let mut desktop = ""
let mut app_id = "chandra"
let mut width = 1280
let mut height = 720
@@ -98,6 +99,9 @@ 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 == "--desktop" && i + 1 < args.length() {
desktop = args[i + 1] // what fills the desktop: a desktop module's id, "wallpaper" or "clock-card"
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 {
@@ -263,6 +267,9 @@ pub fn run(args : Array[String]) -> Int {
}
None => ()
}
if desktop != "" && !comp.shell.set_desktop(desktop) {
@sys.log("--desktop " + desktop + ": no such desktop module")
}
if login {
comp.start_auth_agent() // polkit's password prompts (run0, pkexec): Chandra's dialog
}
+7
View File
@@ -14,6 +14,7 @@ fn main {
let mut restore = true
let mut kiosk : String? = None
let mut kiosk_hybrid = false
let mut desktop = ""
let mut app_id = "chandra"
let mut width = 1280
let mut height = 720
@@ -43,6 +44,9 @@ fn main {
kiosk = Some(args[i + 1]) // one fullscreen app, locked down (docs/kiosk.md)
restore = false
i = i + 2
} else if a == "--desktop" && i + 1 < args.length() {
desktop = args[i + 1] // what fills the desktop: a desktop module's id, "wallpaper" or "clock-card"
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 {
@@ -173,6 +177,9 @@ fn main {
Some(cmd) => comp.start_kiosk(cmd, hybrid=kiosk_hybrid)
None => ()
}
if desktop != "" && !comp.shell.set_desktop(desktop) {
@sys.log("--desktop " + desktop + ": no such desktop module")
}
if drm {
comp.login_session = true
comp.start_auth_agent() // polkit's password prompts (run0, pkexec): Chandra's dialog
+5 -1
View File
@@ -720,13 +720,17 @@ pub fn ChandraCompositor::has_timed_work(self : ChandraCompositor) -> Bool {
self.overview_animating() ||
self.shell.animating() ||
self.shell.face_busy() ||
self.shell.gamelib_busy() ||
self.kiosk_waiting()
}
///| How long an idle main loop may sleep: `idle_ms` (until the wall clock's next second), or
/// less when a desktop module's next animation frame is due sooner.
pub fn ChandraCompositor::wake_timeout(self : ChandraCompositor, idle_ms : Int) -> Int {
let d = self.shell.desktop_wake_ms(@sys.monotonic_ms())
let now = @sys.monotonic_ms()
let d = self.shell.desktop_wake_ms(now)
let g = self.shell.gamelib_wake_ms(now)
let d = if g >= 0 && (d < 0 || g < d) { g } else { d }
if d >= 0 && d < idle_ms {
d
} else {
+112
View File
@@ -0,0 +1,112 @@
///| The Gamerig Library desktop module and the `game-library` capability (compositor/shell/
/// gamelib.mbt), against a state file standing in for gamerig's library daemon. Needs the module
/// built: scripts/build-modules.sh.
///|
let gamelib_state_idle : String =
#|{"system": {"gpu": "NVIDIA GeForce GTX 1650", "resolution": "1280x720", "display": ":0",
#| "audio": "PulseAudio", "audio_ok": true, "hostname": "rig"},
#| "apps": [
#| {"id": "steam", "name": "Steam", "category": "games", "featured": true, "icon": "Play",
#| "description": "Your Steam library.", "installed": true, "running": false,
#| "modes": [{"id": "default", "label": "Launch"}, {"id": "bigpicture", "label": "Big Picture"}]},
#| {"id": "terminal", "name": "Terminal", "category": "tools", "icon": "Terminal",
#| "description": "Interactive shell inside the rig.", "installed": true}
#| ]}
///|
fn gamelib_file(tag : String, body : String) -> String {
let path = "/tmp/chandra-gamelib-" + tag + "-" + @sys.getpid().to_string() + ".json"
ignore(@sys.write_file_bytes(path, @sys.str_to_utf8_bytes(body)))
path
}
///| The desktop module's texts and where each is drawn.
fn gamelib_texts(comp : @host.ChandraCompositor) -> Array[(String, Int, Int)] {
let out : Array[(String, Int, Int)] = []
for op in comp.shell.slot_ops("desktop") {
if op is Text(t) {
out.push((t.text, t.origin.x, t.origin.y))
}
}
out
}
///|
fn gamelib_has(comp : @host.ChandraCompositor, s : String) -> Bool {
gamelib_texts(comp).iter().any(t => t.0 == s)
}
///| Click the first text `label` the module drew.
fn gamelib_click(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit {
for tx in gamelib_texts(comp) {
if tx.0 == label {
comp.handle_input(@nested.InputEvent::PointerMove((tx.1 + 4).to_double(), tx.2.to_double()), t)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t + 1U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 2U)
ignore(comp.compose_frame())
return
}
}
abort("no " + label)
}
///|
test "the Gamerig Library shows the daemon's games and rig, and sends launch / stop / focus" {
let comp = desk_comp("gamelib")
let path = gamelib_file("a", gamelib_state_idle)
comp.shell.set_gamelib_base("file://" + path)
assert_true(comp.shell.desktop_modules().contains(("gamerig-library", "Gamerig Library")))
assert_true(comp.shell.set_desktop("gamerig-library"))
ignore(comp.compose_frame())
ignore(comp.compose_frame())
for want in ["Gamerig", "Steam", "Terminal", "Big Picture", "Rig Status", "Games", "Running Apps"] {
assert_true(gamelib_has(comp, want), msg="missing " + want)
}
// Launch Big Picture, then plain Launch on the first card (Steam, featured).
gamelib_click(comp, "Big Picture", 100U)
gamelib_click(comp, "Launch", 110U)
ignore(comp.compose_frame())
assert_eq(comp.shell.gamelib.sent, ["launch steam bigpicture", "launch steam default"])
// The daemon says it runs now: the card offers Switch to and Stop, the sidebar lists it.
ignore(@sys.write_file_bytes(path, @sys.str_to_utf8_bytes(gamelib_state_idle.replace(old="\"running\": false", new="\"running\": true"))))
comp.shell.gamelib.next_poll = 0UL
ignore(comp.compose_frame())
ignore(comp.compose_frame())
assert_true(gamelib_has(comp, "Switch to"))
gamelib_click(comp, "Stop", 120U)
gamelib_click(comp, "Switch to", 130U)
ignore(comp.compose_frame())
assert_eq(comp.shell.gamelib.sent[2:].to_owned(), ["stop steam default", "focus steam default"])
// The daemon goes away: the library says so.
@sys.unlink(path)
comp.shell.gamelib.next_poll = 0UL
ignore(comp.compose_frame())
ignore(comp.compose_frame())
assert_true(gamelib_texts(comp).iter().any(t => t.0.has_prefix("Library daemon not reachable")))
}
///|
test "typing on the focused library filters its cards" {
let comp = desk_comp("gamelib-type")
let path = gamelib_file("b", gamelib_state_idle)
comp.shell.set_gamelib_base("file://" + path)
assert_true(comp.shell.set_desktop("gamerig-library"))
ignore(comp.compose_frame())
ignore(comp.compose_frame())
// A click on the empty grid gives the desktop the keyboard.
comp.handle_input(@nested.InputEvent::PointerMove(900.0, 600.0), 10U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 12U)
ignore(comp.compose_frame())
for k in [20U, 18U, 19U, 50U] { // t e r m (evdev codes)
comp.handle_input(@nested.InputEvent::Key(k, true), 20U)
comp.handle_input(@nested.InputEvent::Key(k, false), 21U)
}
ignore(comp.compose_frame())
assert_true(gamelib_has(comp, "term"))
assert_true(gamelib_has(comp, "Terminal"))
assert_false(gamelib_has(comp, "Steam"))
@sys.unlink(path)
}
+3 -3
View File
@@ -1689,9 +1689,9 @@ test "open_settings opens the settings module on the tab asked for" {
assert_true(comp.shell.open_settings(Desktop))
ignore(comp.compose_frame())
let pr = comp.shell.slot_popup_rect(slot)
// "On the desktop" and its choices (wallpaper only, clock card, the two desktop modules), then
// the Wallpaper heading and the five wallpapers.
assert_eq(pr.h, 40 + (1 + 4 + 6) * 28 + 6)
// "On the desktop" and its choices (wallpaper only, clock card, the three desktop modules),
// then the Wallpaper heading and the five wallpapers.
assert_eq(pr.h, 40 + (1 + 5 + 6) * 28 + 6)
assert_true(comp.shell.open_settings(Session))
ignore(comp.compose_frame())
// The five settings, then Face unlock (a heading; chandra-face isn't installed in tests).
+341
View File
@@ -0,0 +1,341 @@
///| The `game-library` capability (docs/gamerig-library.md): what the Gamerig Library desktop
/// module shows. The shell polls gamerig's library daemon (server.py, `GET /api/state` on
/// 127.0.0.1:8091; GAMERIG_DESKTOP_API sets another base URL) about every two seconds while a
/// module with the capability is loaded, and sends the module's launch / stop / focus back as
/// `POST /api/apps/<id>/<action>`. Both run curl on a socket (`spawn_socket`), so the compositor
/// never waits on the daemon. A `file://` base reads a state file instead (tests, demos) and only
/// records the actions.
///| How often the daemon is asked, and how soon after an action.
let gamelib_poll_ms : UInt64 = 2000UL
///|
let gamelib_after_action_ms : UInt64 = 250UL
///| An action's error stays in the status this long.
let gamelib_error_ms : UInt64 = 8000UL
///| A curl run in progress: our end of its socket and what it has said.
pub(all) struct CurlRun {
fd : Int
buf : Array[Byte]
}
///| What the shell knows of the library, and the daemon calls in flight.
pub(all) struct GameLib {
/// Base URL without a trailing slash ("http://127.0.0.1:8091" or "file:///path/state.json").
mut base : String
/// curl's path ("" when there is none: every poll fails with a message).
curl : String
mut state : @gamelib.State
mut get : CurlRun?
mut post : CurlRun?
/// Actions waiting for the one in flight: (verb, game, mode).
queue : Array[(String, String, String)]
/// Actions done against a file:// base, as "verb game mode" (tests read them).
sent : Array[String]
mut next_poll : UInt64
/// What the last action said went wrong, until `error_until`.
mut action_error : String
mut error_until : UInt64
mut dirty : Bool
}
///| curl, where the rig's image has it.
fn find_curl() -> String {
let env = @sys.getenv("GAMERIG_CURL")
if env != "" {
return env
}
for p in ["/usr/bin/curl", "/bin/curl", "/usr/local/bin/curl"] {
if @sys.has_exe(p) {
return p
}
}
""
}
///|
pub fn GameLib::new() -> GameLib {
let env = @sys.getenv("GAMERIG_DESKTOP_API")
let base = if env != "" { env } else { "http://127.0.0.1:8091" }
{
base: trim_slash(base),
curl: find_curl(),
state: { rig: @gamelib.Rig::unknown(), games: [], modes: [] },
get: None,
post: None,
queue: [],
sent: [],
next_poll: 0UL,
action_error: "",
error_until: 0UL,
dirty: true,
}
}
///|
fn trim_slash(s : String) -> String {
if s.has_suffix("/") {
s[:s.length() - 1].to_string()
} else {
s
}
}
///| Point the library at another daemon (or a state file) and poll it now.
pub fn DesktopShell::set_gamelib_base(self : DesktopShell, base : String) -> Unit {
self.gamelib.base = trim_slash(base)
self.gamelib.next_poll = 0UL
self.gamelib.sent.clear()
}
///| A module asked for something (`game-library` launch / stop / focus / refresh).
pub fn GameLib::request(self : GameLib, code : Int, game : String, mode : String) -> Unit {
let verb = match code {
0 => "launch"
1 => "stop"
2 => "focus"
_ => {
self.next_poll = 0UL
return
}
}
if game == "" || game.contains("/") || game.contains("\n") || mode.contains("\n") {
return
}
self.queue.push((verb, game, if mode == "" { "default" } else { mode }))
}
///| Start curl with `args`; None when it can't run.
fn GameLib::curl_run(self : GameLib, args : Array[String]) -> CurlRun? {
if self.curl == "" {
return None
}
// argv goes to the child one per line, so the -w newline is curl's own "\n" escape; the daemon
// is local, so no proxy. At most 15 arguments (spawn_socket).
let argv = [self.curl, "-sS", "--noproxy", "*", "-m5", "-w", "\\n%{http_code}"]
argv.append(args)
let fd = @sys.spawn_socket(argv)
if fd < 0 {
None
} else {
Some({ fd, buf: [] })
}
}
///| Read what `run` has said, without waiting. Some((body, http status)) once it is done.
fn read_run(run : CurlRun) -> (String, Int)? {
let chunk : FixedArray[Byte] = FixedArray::make(8192, b'\x00')
let mut eof = false
while @sys.poll_read(run.fd, 0) > 0 {
let (n, extra) = @sys.recvmsg_fd(run.fd, chunk, chunk.length())
if extra >= 0 {
@sys.close_fd(extra)
}
if n == -1 {
break
}
if n <= 0 {
eof = true
break
}
for i = 0; i < n; i = i + 1 {
run.buf.push(chunk[i])
}
if run.buf.length() > 4 * 1024 * 1024 {
eof = true // a runaway answer: stop reading
break
}
}
if !eof {
return None
}
@sys.close_fd(run.fd)
let text = @utf8.decode_lossy(Bytes::from_array(run.buf))
// curl -w appended "\n<status>"; 000 when it couldn't connect.
match text.rev_find("\n") {
Some(i) => {
let code = @gamelib.parse_int(text[i + 1:].to_string())
Some((text[:i].to_string(), code))
}
None => Some((text, 0))
}
}
///| Take a new state (or say why there is none).
fn GameLib::take(self : GameLib, body : String, code : Int, now : UInt64) -> Unit {
let err = if code == 200 {
match @gamelib.parse_state(body) {
Ok(s) => {
self.state = s
""
}
Err(e) => e
}
} else if code == 0 {
"Library daemon not reachable at " + self.base
} else {
"Library daemon answered HTTP " + code.to_string() + ": " + @gamelib.error_message(body)
}
let rig = self.state.rig
let rig = if err != "" {
{ ..rig, connected: false, error: err }
} else if now < self.error_until {
{ ..rig, connected: true, error: self.action_error }
} else {
{ ..rig, connected: true, error: "" }
}
if rig != self.state.rig || err == "" {
self.state = { ..self.state, rig, }
self.dirty = true
}
}
///| One step: collect answers, start the next poll or action when due. Call it before modules
/// read the tables.
pub fn GameLib::poll(self : GameLib, now : UInt64) -> Unit {
let before = self.state
// The poll in flight.
match self.get {
Some(run) =>
match read_run(run) {
Some((body, code)) => {
self.get = None
self.take(body, code, now)
self.next_poll = now + gamelib_poll_ms
}
None => ()
}
None => ()
}
// The action in flight.
match self.post {
Some(run) =>
match read_run(run) {
Some((body, code)) => {
self.post = None
if code < 200 || code >= 300 {
self.action_error = if code == 0 {
"Library daemon not reachable at " + self.base
} else {
@gamelib.error_message(body)
}
self.error_until = now + gamelib_error_ms
}
self.next_poll = now + gamelib_after_action_ms
}
None => ()
}
None => ()
}
// Next action.
if self.post is None && self.queue.length() > 0 {
let (verb, game, mode) = self.queue.remove(0)
if self.base.has_prefix("file://") {
self.sent.push(verb + " " + game + " " + mode)
self.next_poll = 0UL
} else {
let url = self.base + "/api/apps/" + game + "/" + verb
let body = if verb == "launch" { "{\"mode\":\"" + mode.replace_all(old="\"", new="") + "\"}" } else { "{}" }
match self.curl_run(["-H", "Content-Type: application/json", "--data-binary", body, url]) {
Some(run) => self.post = Some(run)
None => {
self.action_error = "curl is not installed: can't reach the library daemon"
self.error_until = now + gamelib_error_ms
}
}
}
}
// Next poll.
if self.get is None && now >= self.next_poll {
self.next_poll = now + gamelib_poll_ms
if self.base.has_prefix("file://") {
let path = self.base[7:].to_string()
let bytes = @sys.read_file_bytes(path)
if bytes.length() == 0 {
self.take("", 0, now)
} else {
self.take(@utf8.decode_lossy(bytes), 200, now)
}
} else {
match self.curl_run([self.base + "/api/state"]) {
Some(run) => self.get = Some(run)
None => self.take("", 0, now)
}
}
}
if self.state != before {
self.dirty = true
}
}
///| A daemon call is in flight (the main loop keeps its pace so the answer shows soon).
pub fn GameLib::busy(self : GameLib) -> Bool {
self.get is Some(_) || self.post is Some(_) || self.queue.length() > 0
}
///| Milliseconds until the next poll is due, -1 when no module uses the library.
pub fn DesktopShell::gamelib_wake_ms(self : DesktopShell, now : UInt64) -> Int {
if !self.any_cap("game-library") {
return -1
}
if self.gamelib.next_poll <= now {
0
} else {
(self.gamelib.next_poll - now).to_int()
}
}
///| Whether a library daemon call is in flight.
pub fn DesktopShell::gamelib_busy(self : DesktopShell) -> Bool {
self.any_cap("game-library") && self.gamelib.busy()
}
///| Publish tables 26-28 for modules with the capability (and redraw the desktop on news).
fn DesktopShell::publish_gamelib(self : DesktopShell) -> Unit {
if !self.any_cap("game-library") {
return
}
let g = self.gamelib
g.poll(@sys.monotonic_ms())
if !g.dirty {
return
}
g.dirty = false
let r = g.state.rig
let st = @wasm.Table::new()
st.str(r.error)
st.str(r.gpu)
st.str(r.resolution)
st.str(r.display)
st.str(r.audio)
st.str(r.hostname)
st.int(if r.connected { 1 } else { 0 })
st.int(if r.audio_ok { 1 } else { 0 })
st.end_row()
@wasm.publish(GameStatus, st)
let gt = @wasm.Table::new()
for x in g.state.games {
gt.str(x.id)
gt.str(x.name)
gt.str(x.category)
gt.str(x.description)
gt.str(x.icon)
gt.str(x.install_hint)
gt.int(if x.featured { 1 } else { 0 })
gt.int(if x.installed { 1 } else { 0 })
gt.int(if x.running { 1 } else { 0 })
gt.end_row()
}
@wasm.publish(Games, gt)
let mt = @wasm.Table::new()
for m in g.state.modes {
mt.str(m.game)
mt.str(m.id)
mt.str(m.label)
mt.end_row()
}
@wasm.publish(GameModes, mt)
self.desk_dirty = true
}
+1
View File
@@ -11,6 +11,7 @@ import {
"chandra/desktop/lib/timefmt" @timefmt,
"chandra/desktop/lib/launcher" @launcher,
"chandra/desktop/lib/dock" @dock,
"chandra/desktop/lib/gamelib" @gamelib,
"chandra/desktop/compositor/scene" @scene,
"jqlssg/moonedn" @edn,
"chandra/desktop/compositor/sys" @sys,
+3
View File
@@ -311,6 +311,8 @@ pub(all) struct DesktopShell {
mut default_apps_dirty : Bool
/// Face unlock (face.mbt): what `chandra-face` said, for Settings > Session.
face : FaceUnlock
/// The game library (gamelib.mbt): gamerig's library daemon, for the `game-library` capability.
gamelib : GameLib
/// The terminal chosen in the Apps tab (desktop id; "" for none), saved as state.edn :terminal.
mut terminal : String
/// Desktop ids of Terminal=true apps, started inside the terminal.
@@ -473,6 +475,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
default_apps: [],
default_apps_dirty: true,
face: FaceUnlock::new(),
gamelib: GameLib::new(),
terminal: "",
terminal_apps,
desk_set: false,
+2
View File
@@ -701,6 +701,7 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
self.publish_default_apps()
}
self.publish_face_unlock()
self.publish_gamelib()
if self.any_cap("screenshot") {
@wasm.publish_screenshot(self.screenshot_state)
}
@@ -854,6 +855,7 @@ fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
Some(Shortcut(code)) => self.shortcut_request(code)
Some(DefaultApp(code)) => self.default_app_request(code)
Some(FaceUnlock(code)) => self.face.request(code)
Some(GameLibrary(code, game, mode)) => self.gamelib.request(code, game, mode)
Some(PowerAction(a)) => if a >= 0 && a <= 2 { self.actions.push(SystemPower(a)) }
Some(Network(code, ssid, password)) => self.network_request(code, ssid, password)
Some(SetInspector(on)) => self.set_inspecting(on)
+13
View File
@@ -335,6 +335,13 @@ pub(all) enum HostTable {
FaceStatus
/// Enrolled faces (ss: label added).
Faces
/// Game library status (ssssssii: error gpu resolution display audio hostname connected
/// audio-ok; one row), served by `game-library.status`.
GameStatus
/// Games (ssssssiii: id name category description icon install-hint featured installed running).
Games
/// Extra launch modes (sss: game id label).
GameModes
}
///|
@@ -365,6 +372,9 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Desktops => 20U
FaceStatus => 24U
Faces => 25U
GameStatus => 26U
Games => 27U
GameModes => 28U
}
// Most tables are republished every frame unchanged: skip the copy into the host then.
let slot = id.reinterpret_as_int()
@@ -455,6 +465,8 @@ pub(all) enum HostRequest {
/// The face-unlock capability: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
/// start using it for the password dialog and sudo.
FaceUnlock(Int)
/// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh.
GameLibrary(Int, String, String)
} derive(Eq, Debug)
///|
@@ -482,6 +494,7 @@ pub fn next_request() -> HostRequest? {
Some(ReloadSession) => Some(ReloadSession)
Some(SetDesktop(i)) => Some(SetDesktop(i))
Some(FaceUnlock(i)) => Some(FaceUnlock(i))
Some(GameLibrary(r)) => Some(GameLibrary(r.action, r.game, r.mode))
}
}
+20
View File
@@ -743,6 +743,13 @@ pub(all) enum HostTable {
FaceStatus
/// Enrolled faces (ss: label added).
Faces
/// Game library status (ssssssii: error gpu resolution display audio hostname connected
/// audio-ok; one row), served by `game-library.status`.
GameStatus
/// Games (ssssssiii: id name category description icon install-hint featured installed running).
Games
/// Extra launch modes (sss: game id label).
GameModes
}
///| Publish `t` as the data behind `which` for every module's next call.
@@ -764,6 +771,9 @@ pub fn publish(which : HostTable, t : Table) -> Unit {
Desktops => 20
FaceStatus => 24
Faces => 25
GameStatus => 26
Games => 27
GameModes => 28
}
let out : Array[Byte] = []
for k = 0; k < 4; k = k + 1 {
@@ -853,6 +863,8 @@ pub(all) enum HostRequest {
/// The face-unlock capability: a face index removes it; -1 refresh, -2 enroll, -3 / -4 stop /
/// start using it for the password dialog and sudo.
FaceUnlock(Int)
/// The game-library capability: 0 launch (game, mode), 1 stop, 2 focus (game), 3 refresh.
GameLibrary(Int, String, String)
} derive(Eq, Debug)
///|
@@ -896,6 +908,14 @@ pub fn next_request() -> HostRequest? {
19 => Some(DefaultApp(c_host_req_int()))
40 => Some(SetDesktop(c_host_req_int()))
44 => Some(FaceUnlock(c_host_req_int()))
45 => {
let code = c_host_req_int()
let s = req_str()
match s.find("\u{1f}") {
Some(i) => Some(GameLibrary(code, s[:i].to_string(), s[i + 1:].to_string()))
None => Some(GameLibrary(code, s, ""))
}
}
_ => None
}
}
+34 -2
View File
@@ -67,7 +67,8 @@ enum {
K_SC_LIST, K_SC_CAPTURE, K_SC_CANCEL, K_SC_RESET, K_SC_RESET_ALL,
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_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
};
typedef struct Env { Inst *inst; int kind; } Env;
@@ -76,7 +77,8 @@ typedef struct Env { Inst *inst; int kind; } Env;
enum { T_APPS, T_WINDOWS, T_LAYOUTS, T_MODULES, T_INSTANCES, T_WALLPAPERS, T_SESSION_SETTINGS, T_ICONS,
T_NET_STATUS, T_NET_NETWORKS, T_SHORTCUTS, T_APP_CATS, T_APP_CHOICES,
/* fixed numbers from here (wit/host/plasmoids.wit publish-table) */
T_DESKTOPS = 20, T_FACE_STATUS = 24, T_FACES = 25, T_N = 32 };
T_DESKTOPS = 20, T_FACE_STATUS = 24, T_FACES = 25,
T_GL_STATUS = 26, T_GL_GAMES = 27, T_GL_MODES = 28, T_N = 32 };
typedef struct { uint8_t *data; size_t len; } Blob;
static Blob tables[T_N];
static int32_t host_ints[24] = {[7] = -1}; /* 0 layout mode, 1 inspector on, 2 current wallpaper, 3 session settings on (bit i: row i),
@@ -397,6 +399,29 @@ static wasm_trap_t *host_import(void *env, const wasm_val_vec_t *args, wasm_val_
case K_FU_REMOVE: if (a0 >= 0 && a0 < 1000) push_req(44, a0, NULL); break;
case K_FU_SET_IN_USE: push_req(44, a0 ? -4 : -3, NULL); break;
case K_FU_REFRESH: push_req(44, -1, NULL); break;
/* Game library: status from table 26 (error gpu resolution display audio hostname connected
* audio-ok), games from 27 (id name category description icon install-hint featured installed
* running), launch modes from 28 (game id label); request 45 is 0 launch / 1 stop / 2 focus /
* 3 refresh, with "game\x1fmode". */
case K_GL_STATUS: build_record(in, T_GL_STATUS, "ssssssbb", a0); break;
case K_GL_GAMES: build_list(in, T_GL_GAMES, "ssssssbbb", a0); break;
case K_GL_MODES: build_list(in, T_GL_MODES, "sss", a0); break;
case K_GL_REFRESH: push_req(45, 3, NULL); break;
case K_GL_LAUNCH:
case K_GL_STOP:
case K_GL_FOCUS: {
int32_t a3 = args->size >= 4 ? args->data[3].of.i32 : 0;
char *game = guest_str(in, a0, a1);
char *mode = e->kind == K_GL_LAUNCH ? guest_str(in, a2, a3) : strdup("");
size_t lg = strlen(game), lm = strlen(mode);
char *both = (char *)malloc(lg + lm + 2);
memcpy(both, game, lg);
both[lg] = 0x1f;
memcpy(both + lg + 1, mode, lm + 1);
push_req(45, e->kind == K_GL_LAUNCH ? 0 : e->kind == K_GL_STOP ? 1 : 2, both);
free(game); free(mode); free(both);
break;
}
case K_SESSION_SET: push_req(a1 ? 11 : 10, a0, NULL); break; /* 10 off, 11 on */
/* Request 12 carries the screenshot code: 0-3 take, 10-12 record, 20 stop, 30/31 pointer. */
case K_SHOT_TAKE: if (a0 >= 0 && a0 <= 3) push_req(12, a0, NULL); break;
@@ -620,6 +645,13 @@ static int classify_import(const wasm_name_t *m, const wasm_name_t *f) {
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "remove")) return K_FU_REMOVE;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "set-in-use")) return K_FU_SET_IN_USE;
if (!strcmp(iface, "face-unlock") && !strcmp(fn, "refresh")) return K_FU_REFRESH;
if (!strcmp(iface, "game-library") && !strcmp(fn, "status")) return K_GL_STATUS;
if (!strcmp(iface, "game-library") && !strcmp(fn, "games")) return K_GL_GAMES;
if (!strcmp(iface, "game-library") && !strcmp(fn, "launch-modes")) return K_GL_MODES;
if (!strcmp(iface, "game-library") && !strcmp(fn, "launch")) return K_GL_LAUNCH;
if (!strcmp(iface, "game-library") && !strcmp(fn, "stop")) return K_GL_STOP;
if (!strcmp(iface, "game-library") && !strcmp(fn, "focus")) return K_GL_FOCUS;
if (!strcmp(iface, "game-library") && !strcmp(fn, "refresh")) return K_GL_REFRESH;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "settings")) return K_SESSION_SETTINGS;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "is-on")) return K_SESSION_IS_ON;
if (!strcmp(iface, "session-settings") && !strcmp(fn, "set-setting")) return K_SESSION_SET;