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

@@ -0,0 +1,19 @@
Optional export that turns a module into a desktop module: instead of a box in the panel it
owns the desktop itself, the whole output behind the windows (see docs/desktop-modules.md).
A desktop module is still a plasmoid (it exports `plasmoid` as well, and may export
`module-config` and import any capability a panel module can), so the same sandbox, draw ops
and capability grants apply. What changes is how the shell drives it:
- `plasmoid.render` is called with the output's full size (and again with the new size when
the output is resized), in desktop coordinates: (0, 0) is the output's top-left corner.
The panel and windows are drawn on top; the module draws the whole area.
- `plasmoid.on-event` gets the pointer (move, press, release, leave) only where no window,
panel, popup or menu covers the desktop, and keys only while the desktop has keyboard focus
(after a click on it, until a window is focused: it then gets `focus-lost`). A right-click
on the empty desktop always opens the shell's desktop menu (module settings, system
settings), never reaches the module.
- `plasmoid.popup` and `plasmoid.info`'s size fields are not used.
- Hidden settings (a `module-config` item with an empty label) are saved by the shell in
state.edn whenever their value changes after an event, and handed back at the next load:
that is how a desktop module keeps state such as icon positions.
@@ -0,0 +1,32 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportBackdrop() -> Int {
let (result) : (WallpaperMode) = backdrop();
let ret = result.ordinal()
return ret
}
///|
#doc(hidden)
pub fn wasmExportOnScroll(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let (result) : (Bool) = on_scroll(@types.Point::{x : p0, y : p1}, p2, p3);
let ret = (if result { 1 } else { 0 })
return ret
}
///|
#doc(hidden)
pub fn wasmExportTick(p0 : Int) -> Int {
let (result) : (UInt) = tick((p0).reinterpret_as_uint());
let ret = (result).reinterpret_as_int()
return ret
}
@@ -0,0 +1,6 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
"chandra/desktop/lib/gamelib" @logic,
}
warnings = "-44"
@@ -0,0 +1,17 @@
///| The library replaces the wallpaper (gamerig's own background) and only redraws on events and
/// when the shell has new data from the daemon: it never animates.
///|
pub fn backdrop() -> WallpaperMode {
REPLACE_WALLPAPER
}
///|
pub fn on_scroll(_at : @types.Point, _dx : Int, dy : Int) -> Bool {
@logic.state.scroll_by(dy)
}
///|
pub fn tick(_now_ms : UInt) -> UInt {
0
}
@@ -0,0 +1,41 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// What happens to the wallpaper under the module.
pub(all) enum WallpaperMode {
OVER_WALLPAPER; REPLACE_WALLPAPER
} derive()
///|
pub fn WallpaperMode::ordinal(self : WallpaperMode) -> Int {
match self {
OVER_WALLPAPER => 0
REPLACE_WALLPAPER => 1
}
}
///|
pub fn WallpaperMode::from(self : Int) -> WallpaperMode {
match self {
0 => OVER_WALLPAPER
1 => REPLACE_WALLPAPER
_ => panic()
}
}
///|
/// Read once, right after loading.
declare pub fn backdrop() -> WallpaperMode
///|
/// Wheel or touchpad scroll over the empty desktop at `at`: `dx` / `dy` in pixels (positive:
/// right / down; one wheel notch is about 10). True when the module wants a redraw.
declare pub fn on_scroll(at : @types.Point, dx : Int, dy : Int) -> Bool
///|
/// The animation clock. `now-ms` counts milliseconds from when the module was loaded. It is
/// called once after loading, after every event the module handled, and again when the delay it
/// last returned has passed. The module is redrawn after each timed call (an animation frame)
/// and after events that returned true; a call that follows an event only reschedules the
/// clock and does not redraw by itself. Return how many ms until the
/// next frame (16 for about 60 frames a second, 33 for 30), or 0 to sleep until the next event:
/// an idle desktop module costs nothing, so return 0 whenever nothing moves. Frames are paused
/// (no calls) while a window covers the whole desktop.
declare pub fn tick(now_ms : UInt) -> UInt
@@ -0,0 +1,5 @@
Optional: a module's own settings. A module that exports this gets a "Module settings" entry in
its right-click menu, listing the items below; the shell draws the menu (the same for every
module), remembers each choice per module in state.edn (`:module-config`), and hands the saved
values back through `set-config` right after the module is loaded. A module without it simply
has no settings: the export is looked up by name, so older modules keep loading.
@@ -0,0 +1,114 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportConfigItems() -> Int {
let (result) : (Array[ConfigItem]) = config_items();
let return_area = mbt_ffi_malloc(8)
let address3 = mbt_ffi_malloc((result).length() * 32);
for index4 = 0; index4 < (result).length(); index4 = index4 + 1 {
let iter_elem : ConfigItem = (result)[(index4)]
let iter_base = address3 + (index4 * 32);
let ptr = mbt_ffi_str2ptr((iter_elem).key)
mbt_ffi_store32((iter_base) + 4, (iter_elem).key.length())
mbt_ffi_store32((iter_base) + 0, ptr)
let ptr0 = mbt_ffi_str2ptr((iter_elem).label)
mbt_ffi_store32((iter_base) + 12, (iter_elem).label.length())
mbt_ffi_store32((iter_base) + 8, ptr0)
let address = mbt_ffi_malloc(((iter_elem).choices).length() * 8);
for index = 0; index < ((iter_elem).choices).length(); index = index + 1 {
let iter_elem : String = ((iter_elem).choices)[(index)]
let iter_base = address + (index * 8);
let ptr1 = mbt_ffi_str2ptr(iter_elem)
mbt_ffi_store32((iter_base) + 4, iter_elem.length())
mbt_ffi_store32((iter_base) + 0, ptr1)
}
mbt_ffi_store32((iter_base) + 20, ((iter_elem).choices).length())
mbt_ffi_store32((iter_base) + 16, address)
let ptr2 = mbt_ffi_str2ptr((iter_elem).value)
mbt_ffi_store32((iter_base) + 28, (iter_elem).value.length())
mbt_ffi_store32((iter_base) + 24, ptr2)
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address3)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportConfigItemsPostReturn(p0 : Int) -> Unit {
for index0 = 0; index0 < (mbt_ffi_load32((p0) + 4)); index0 = index0 + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index0 * 32)
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
mbt_ffi_free(mbt_ffi_load32((iter_base) + 8))
for index = 0; index < (mbt_ffi_load32((iter_base) + 20)); index = index + 1 {
let iter_base = (mbt_ffi_load32((iter_base) + 16)) + (index * 8)
mbt_ffi_free(mbt_ffi_load32((iter_base) + 0))
}
mbt_ffi_free(mbt_ffi_load32((iter_base) + 16))
mbt_ffi_free(mbt_ffi_load32((iter_base) + 24))
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportSetConfig(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let result = mbt_ffi_ptr2str(p0, p1)
let result0 = mbt_ffi_ptr2str(p2, p3)
let (result1) : (Bool) = set_config(result, result0);
let ret = (if result1 { 1 } else { 0 })
return ret
}
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
@@ -0,0 +1,5 @@
import {
"chandra/desktop/lib/icondesk" @logic,
}
warnings = "-44"
@@ -0,0 +1,11 @@
///| The library's right-click settings (colours: gamerig dark or light, or follow the desktop).
///|
pub fn config_items() -> Array[ConfigItem] {
@logic.state.config_items().map(e => { key: e.key, label: e.label, choices: e.choices, value: e.value })
}
///|
pub fn set_config(key : String, value : String) -> Bool {
@logic.state.set_config(key, value)
}
@@ -0,0 +1,11 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct ConfigItem {
key : String; label : String; choices : Array[String]; value : String
}
///|
declare pub fn config_items() -> Array[ConfigItem]
///|
/// Set `key` to `value` (unknown keys and values are ignored). True when the widget should redraw.
declare pub fn set_config(key : String, value : String) -> Bool
@@ -0,0 +1 @@
The widget (plasmoid) contract.
@@ -0,0 +1,431 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
#doc(hidden)
pub fn wasmExportInfo() -> Int {
let (result) : (PlasmoidInfo) = info();
let return_area = mbt_ffi_malloc(32)
let ptr = mbt_ffi_str2ptr((result).id)
mbt_ffi_store32((return_area) + 4, (result).id.length())
mbt_ffi_store32((return_area) + 0, ptr)
let ptr0 = mbt_ffi_str2ptr((result).name)
mbt_ffi_store32((return_area) + 12, (result).name.length())
mbt_ffi_store32((return_area) + 8, ptr0)
mbt_ffi_store32((return_area) + 16, (((result).preferred).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 20, (((result).preferred).h).reinterpret_as_int())
mbt_ffi_store32((return_area) + 24, ((result).min_width).reinterpret_as_int())
mbt_ffi_store8((return_area) + 28, (if (result).stretch { 1 } else { 0 }))
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportInfoPostReturn(p0 : Int) -> Unit {
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
mbt_ffi_free(mbt_ffi_load32((p0) + 8))
}
///|
#doc(hidden)
pub fn wasmExportRender(p0 : Int, p1 : Int) -> Int {
let (result) : (Array[@types.DrawOp]) = render(@types.Size::{w : (p0).reinterpret_as_uint(), h : (p1).reinterpret_as_uint()});
let return_area = mbt_ffi_malloc(8)
let address = mbt_ffi_malloc((result).length() * 32);
for index = 0; index < (result).length(); index = index + 1 {
let iter_elem : @types.DrawOp = (result)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload).radius).reinterpret_as_int())
()
}
StrokeRect(payload0) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload0).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload0).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload0).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload0).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload0).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload0).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload0).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload0).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload0).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload0).radius).reinterpret_as_int())
()
}
Line(payload1) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload1).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload1).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).width).reinterpret_as_int())
()
}
Circle(payload2) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload2).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload2).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload2).filled { 1 } else { 0 }))
()
}
Text(payload3) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload3).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).origin).y)
let ptr = mbt_ffi_str2ptr((payload3).text)
mbt_ffi_store32((iter_base) + 16, (payload3).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload3).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload3).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload3).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload3).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload3).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload3).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload3).style).bold { 1 } else { 0 }))
()
}
PushClip(payload4) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload4).x)
mbt_ffi_store32((iter_base) + 8, (payload4).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload4).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
Image(payload6) => {
mbt_ffi_store8((iter_base) + 0, (7))
mbt_ffi_store32((iter_base) + 4, ((payload6).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload6).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload6).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload6).rect).h).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 20, ((payload6).image).reinterpret_as_int())
()
}
}
}
mbt_ffi_store32((return_area) + 4, (result).length())
mbt_ffi_store32((return_area) + 0, address)
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportRenderPostReturn(p0 : Int) -> Unit {
for index = 0; index < (mbt_ffi_load32((p0) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 0)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
7 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 0))
}
///|
#doc(hidden)
pub fn wasmExportPopup() -> Int {
let (result) : (PopupSurface?) = popup();
let return_area = mbt_ffi_malloc(20)
match (result) {
None => {
mbt_ffi_store8((return_area) + 0, (0))
()
}
Some(payload0) => {
mbt_ffi_store8((return_area) + 0, (1))
mbt_ffi_store32((return_area) + 4, (((payload0).size).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 8, (((payload0).size).h).reinterpret_as_int())
let address = mbt_ffi_malloc(((payload0).ops).length() * 32);
for index = 0; index < ((payload0).ops).length(); index = index + 1 {
let iter_elem : @types.DrawOp = ((payload0).ops)[(index)]
let iter_base = address + (index * 32);
match iter_elem {
FillRect(payload1) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload1).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload1).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload1).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload1).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload1).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload1).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload1).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload1).radius).reinterpret_as_int())
()
}
StrokeRect(payload2) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload2).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload2).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload2).rect).h).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 20, (((payload2).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload2).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload2).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload2).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload2).width).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 28, ((payload2).radius).reinterpret_as_int())
()
}
Line(payload3) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, ((payload3).start).x)
mbt_ffi_store32((iter_base) + 8, ((payload3).start).y)
mbt_ffi_store32((iter_base) + 12, ((payload3).end).x)
mbt_ffi_store32((iter_base) + 16, ((payload3).end).y)
mbt_ffi_store8((iter_base) + 20, (((payload3).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload3).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload3).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload3).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, ((payload3).width).reinterpret_as_int())
()
}
Circle(payload4) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, ((payload4).center).x)
mbt_ffi_store32((iter_base) + 8, ((payload4).center).y)
mbt_ffi_store32((iter_base) + 12, ((payload4).radius).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 16, (((payload4).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload4).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload4).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload4).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload4).filled { 1 } else { 0 }))
()
}
Text(payload5) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, ((payload5).origin).x)
mbt_ffi_store32((iter_base) + 8, ((payload5).origin).y)
let ptr = mbt_ffi_str2ptr((payload5).text)
mbt_ffi_store32((iter_base) + 16, (payload5).text.length())
mbt_ffi_store32((iter_base) + 12, ptr)
mbt_ffi_store32((iter_base) + 20, (((payload5).style).size).reinterpret_as_int())
mbt_ffi_store8((iter_base) + 24, ((((payload5).style).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, ((((payload5).style).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, ((((payload5).style).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, ((((payload5).style).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload5).style).align.ordinal())
mbt_ffi_store8((iter_base) + 29, (if ((payload5).style).bold { 1 } else { 0 }))
()
}
PushClip(payload6) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload6).x)
mbt_ffi_store32((iter_base) + 8, (payload6).y)
mbt_ffi_store32((iter_base) + 12, ((payload6).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, ((payload6).h).reinterpret_as_int())
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
Image(payload8) => {
mbt_ffi_store8((iter_base) + 0, (7))
mbt_ffi_store32((iter_base) + 4, ((payload8).rect).x)
mbt_ffi_store32((iter_base) + 8, ((payload8).rect).y)
mbt_ffi_store32((iter_base) + 12, (((payload8).rect).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 16, (((payload8).rect).h).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 20, ((payload8).image).reinterpret_as_int())
()
}
}
}
mbt_ffi_store32((return_area) + 16, ((payload0).ops).length())
mbt_ffi_store32((return_area) + 12, address)
()
}
}
let ret = return_area
return ret
}
///|
#doc(hidden)
pub fn wasmExportPopupPostReturn(p0 : Int) -> Unit {
match (mbt_ffi_load8_u((p0) + 0)) {
0 => ()
1 => {
for index = 0; index < (mbt_ffi_load32((p0) + 16)); index = index + 1 {
let iter_base = (mbt_ffi_load32((p0) + 12)) + (index * 32)
match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => ()
1 => ()
2 => ()
3 => ()
4 => {
mbt_ffi_free(mbt_ffi_load32((iter_base) + 12))
}
5 => ()
6 => ()
7 => ()
_ => panic()
}
}
mbt_ffi_free(mbt_ffi_load32((p0) + 12))
}
_ => panic()
}
}
///|
#doc(hidden)
pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
let lifted = match (p1) {
0 => {
@types.InputEvent::PointerMove(@types.Point::{x : p2, y : p3})
}
1 => {
@types.InputEvent::PointerDown(@types.Point::{x : p2, y : p3})
}
2 => {
@types.InputEvent::PointerUp(@types.Point::{x : p2, y : p3})
}
3 => {
@types.InputEvent::PointerLeave
}
4 => {
@types.InputEvent::FocusLost
}
5 => {
let result = mbt_ffi_ptr2str(p2, p3)
@types.InputEvent::KeyDown(result)
}
_ => panic()
}
let (result0) : (Bool) = on_event(Surface::from(p0), lifted);
let ret = (if result0 { 1 } else { 0 })
return ret
}
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
#| local.tee 1 i32.const 0 call $moonbit.init_array8
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
@@ -0,0 +1,8 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
"chandra/desktop/interface/chandra/desktop/theme" @theme,
"chandra/desktop/interface/chandra/desktop/game-library" @game_library,
"chandra/desktop/lib/gamelib" @logic,
}
warnings = "-44"
@@ -0,0 +1,66 @@
///| The Gamerig Library's `plasmoid` export: a desktop module (it also exports desktop-module), so
/// `render` gets the whole output. The data comes from the `game-library` capability (the shell
/// polls gamerig's library daemon); all logic lives in lib/gamelib.
///|
pub fn info() -> PlasmoidInfo {
{ id: "org.chandra.gamerig-library", name: "Gamerig Library", preferred: { w: 0, h: 0 }, min_width: 0, stretch: false }
}
///|
fn games() -> Array[@logic.Game] {
@game_library.games().map(g => {
id: g.id,
name: g.name,
category: g.category,
description: g.description,
icon: g.icon,
install_hint: g.install_hint,
featured: g.featured,
installed: g.installed,
running: g.running,
})
}
///|
fn modes() -> Array[@logic.Mode] {
@game_library.launch_modes().map(m => { game: m.game, id: m.id, label: m.label })
}
///|
fn rig() -> @logic.Rig {
let s = @game_library.status()
{
connected: s.connected,
error: s.error,
gpu: s.gpu,
resolution: s.resolution,
display: s.display,
audio: s.audio,
audio_ok: s.audio_ok,
hostname: s.hostname,
}
}
///|
pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
@logic.state.render(games(), modes(), rig(), size, @theme.get_tokens())
}
///| Desktop modules have no popup.
pub fn popup() -> PopupSurface? {
None
}
///|
pub fn on_event(_target : Surface, event : @types.InputEvent) -> Bool {
let (redraw, action) = @logic.state.handle(event)
match action {
Launch(id, mode) => @game_library.launch(id, mode)
Stop(id) => @game_library.stop(id)
Focus(id) => @game_library.focus(id)
Refresh => @game_library.refresh()
NoAction => ()
}
redraw
}
@@ -0,0 +1,42 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct PlasmoidInfo {
id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool
}
///|
pub(all) struct PopupSurface {
size : @types.Size; ops : Array[@types.DrawOp]
}
///|
pub(all) enum Surface {
WIDGET; POPUP
} derive()
///|
pub fn Surface::ordinal(self : Surface) -> Int {
match self {
WIDGET => 0
POPUP => 1
}
}
///|
pub fn Surface::from(self : Int) -> Surface {
match self {
0 => WIDGET
1 => POPUP
_ => panic()
}
}
///|
declare pub fn info() -> PlasmoidInfo
///|
/// Draw the widget into a `size` box (local coordinates).
declare pub fn render(size : @types.Size) -> Array[@types.DrawOp]
///|
/// Present when the widget wants a popup surface (e.g. a launcher menu).
declare pub fn popup() -> PopupSurface?
///|
/// Returns true when the widget's visuals changed and a redraw is needed.
declare pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool