Gamerig Library: gamerig's game library as a Chandra desktop module
CI / test (push) Successful in 2m25s
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:
57 files changed
+3551
-29
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in new issue
Block a user