Rename the project to Chandra
CI / test (push) Failing after 16s

moon-plasma / moonplasma / MoonPlasma / Moon Plasma become chandra / Chandra
everywhere: the WIT package (chandra:desktop, chandra:host, chandra:wm), the
MoonBit module (chandra/desktop) and generated bindings, the Rust host,
identifiers (ChandraCompositor), the session script (chandra-session) and
desktop entry (chandra.desktop), config and data paths
($XDG_CONFIG_HOME/chandra, share/chandra/modules), env vars (CHANDRA_*),
UI strings, docs and tests. The test fixture components are rebuilt against
the renamed WIT.

Saved panel.edn and state.edn are still read from the old
$XDG_CONFIG_HOME/moon-plasma until the first save writes the new copy.

The remote repository keeps its experiments/moon-plasma name for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hi3L9oVBoRd373Qr4n
This commit is contained in:
VandClaude Opus 5.5 committed 2026-11-25 17:12:57 +00:00
1 parent 5dfe34027b
commit af774d76fe
323 files changed
+1055 -1013

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportOpen(p0 : Int) = "chandra:host/display@0.1.0" "open"
///|
fn wasmImportPoll() -> Int = "chandra:host/display@0.1.0" "poll"
///|
fn wasmImportFrameReady() -> Int = "chandra:host/display@0.1.0" "frame-ready"
///|
fn wasmImportPresent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "chandra:host/display@0.1.0" "present"
///|
fn wasmImportPresentFrame() = "chandra:host/display@0.1.0" "present-frame"
///|
fn wasmImportSetCursorShape(p0 : Int) = "chandra:host/display@0.1.0" "set-cursor-shape"
///|
fn wasmImportTakeInput(p0 : Int) = "chandra:host/display@0.1.0" "take-input"
///|
fn wasmImportClose() = "chandra:host/display@0.1.0" "close"
///|
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_loadf64(offset : Int) -> Double =
#|(func (param i32) (result f64) local.get 0 f64.load)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) 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_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
+9
View File
@@ -0,0 +1,9 @@
warnings = "-44"
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
@@ -0,0 +1,76 @@
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
///|
fn wasmImportOpen(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPoll() -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportFrameReady() -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportPresent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPresentFrame() -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportSetCursorShape(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportTakeInput(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportClose() -> Unit {
abort("wasm-only host import")
}
///|
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
///|
fn mbt_ffi_loadf64(offset : Int) -> Double {
abort("wasm-only")
}
///|
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load8_u(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
@@ -0,0 +1,63 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/host/display"
// Values
pub fn close() -> Unit
pub fn frame_ready() -> Bool
pub fn open() -> Output?
pub fn poll() -> Bool
pub fn present(FixedArray[Byte], UInt32, UInt32) -> Unit
pub fn present_frame() -> Unit
pub fn set_cursor_shape(UInt32) -> Unit
pub fn take_input() -> Array[SeatEvent]
// Errors
// Types and methods
pub(all) struct KeyState {
code : UInt32
pressed : Bool
}
pub(all) struct Modifiers {
depressed : UInt32
latched : UInt32
locked : UInt32
group : UInt32
}
pub(all) struct Output {
width : UInt32
height : UInt32
keymap : FixedArray[Byte]
}
pub(all) struct PointerPos {
x : Double
y : Double
}
pub(all) struct ScrollDelta {
axis : UInt32
value : Double
discrete : Int32
}
pub(all) enum SeatEvent {
PointerMove(PointerPos)
PointerButton(KeyState)
Key(KeyState)
Modifiers(Modifiers)
Scroll(ScrollDelta)
}
// Type aliases
// Traits
+149
View File
@@ -0,0 +1,149 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Output {
width : UInt; height : UInt; keymap : FixedArray[Byte]
}
///|
pub(all) struct PointerPos {
x : Double; y : Double
}
///|
/// A button or key as an evdev code, pressed or released.
pub(all) struct KeyState {
code : UInt; pressed : Bool
}
///|
pub(all) struct Modifiers {
depressed : UInt; latched : UInt; locked : UInt; group : UInt
}
///|
/// Wheel/touchpad scroll: axis (0 vertical, 1 horizontal), distance in pixels (positive =
/// down/right), wheel notches (0 when not from a wheel).
pub(all) struct ScrollDelta {
axis : UInt; value : Double; discrete : Int
}
///|
pub(all) enum SeatEvent {
PointerMove(PointerPos)
PointerButton(KeyState)
Key(KeyState)
Modifiers(Modifiers)
Scroll(ScrollDelta)
}
///|
/// Take over the first connected output and the seat's input. None, with the reason on the
/// host's stderr, when this is not an active login VT.
pub fn open() -> Output? {
let return_area = mbt_ffi_malloc(20)
wasmImportOpen(return_area);
let lifted : Output? = match mbt_ffi_load8_u((return_area) + 0) {
0 => Option::None
1 => {
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16))
Option::Some(Output::{width : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), height : (mbt_ffi_load32((return_area) + 8)).reinterpret_as_uint(), keymap : result})
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(return_area)
return ret
}
///|
/// Service the seat, DRM and input fds without blocking. False once the user asked to quit
/// (Ctrl+Alt+Backspace).
pub fn poll() -> Bool {
let result : Int = wasmImportPoll();
let ret = (result != 0)
return ret
}
///|
/// True when a new frame can be presented (seat active, no page flip in flight).
pub fn frame_ready() -> Bool {
let result : Int = wasmImportFrameReady();
let ret = (result != 0)
return ret
}
///|
/// Show an RGBA8888 frame of `width` x `height` (it must match the output mode).
pub fn present(pixels : FixedArray[Byte], width : UInt, height : UInt) -> Unit {
let ptr = mbt_ffi_bytes2ptr(pixels)
wasmImportPresent(ptr, pixels.length(), (width).reinterpret_as_int(), (height).reinterpret_as_int());
mbt_ffi_free(ptr)
}
///|
/// Show the host framebuffer (what `raster.submit` drew) on the output.
pub fn present_frame() -> Unit {
wasmImportPresentFrame();
}
///|
/// Show the cursor for a wp_cursor_shape_v1 value.
pub fn set_cursor_shape(shape : UInt) -> Unit {
wasmImportSetCursorShape((shape).reinterpret_as_int());
}
///|
/// Input queued since the last call.
pub fn take_input() -> Array[SeatEvent] {
let return_area = mbt_ffi_malloc(8)
wasmImportTakeInput(return_area);
let array : Array[SeatEvent] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
SeatEvent::PointerMove(PointerPos::{x : mbt_ffi_loadf64((iter_base) + 8), y : mbt_ffi_loadf64((iter_base) + 16)})
}
1 => {
SeatEvent::PointerButton(KeyState::{code : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), pressed : (mbt_ffi_load8_u((iter_base) + 12) != 0)})
}
2 => {
SeatEvent::Key(KeyState::{code : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), pressed : (mbt_ffi_load8_u((iter_base) + 12) != 0)})
}
3 => {
SeatEvent::Modifiers(Modifiers::{depressed : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), latched : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), locked : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint(), group : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint()})
}
4 => {
SeatEvent::Scroll(ScrollDelta::{axis : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), value : mbt_ffi_loadf64((iter_base) + 16), discrete : mbt_ffi_load32((iter_base) + 24)})
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Restore the previous video mode and release the seat.
pub fn close() -> Unit {
wasmImportClose();
}
+2
View File
@@ -0,0 +1,2 @@
Glyph rasterisation. The component has no C rasteriser, so the host draws glyphs from TTF files
it loads (mirrors compositor/font's native backend: sizes are em sizes in pixels).
+35
View File
@@ -0,0 +1,35 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Int = "chandra:host/font@0.1.0" "load"
///|
fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "chandra:host/font@0.1.0" "rasterise"
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) 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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
+9
View File
@@ -0,0 +1,9 @@
warnings = "-44"
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
@@ -0,0 +1,36 @@
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
///|
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportRasterise(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
+31
View File
@@ -0,0 +1,31 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// One rendered glyph: an 8-bit coverage bitmap `width` x `height`, whose top-left sits at
/// (`xoff`, `yoff`) from the pen on the baseline (y grows downward), and the pen advance.
pub(all) struct Glyph {
width : Int; height : Int; xoff : Int; yoff : Int; advance : Int; coverage : FixedArray[Byte]
}
///|
/// Load the TTF file at `path` into `slot` (0..3). False when it can't be read or parsed.
pub fn load(slot : UInt, path : String) -> Bool {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportLoad((slot).reinterpret_as_int(), ptr, path.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
return ret
}
///|
pub fn rasterise(slot : UInt, codepoint : UInt, size : UInt) -> Glyph {
let return_area = mbt_ffi_malloc(28)
wasmImportRasterise((slot).reinterpret_as_int(), (codepoint).reinterpret_as_int(), (size).reinterpret_as_int(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 20), mbt_ffi_load32((return_area) + 24))
let ret = Glyph::{width : mbt_ffi_load32((return_area) + 0), height : mbt_ffi_load32((return_area) + 4), xoff : mbt_ffi_load32((return_area) + 8), yoff : mbt_ffi_load32((return_area) + 12), advance : mbt_ffi_load32((return_area) + 16), coverage : result}
mbt_ffi_free(return_area)
return ret
}
+102
View File
@@ -0,0 +1,102 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasmoids@0.1.0" "load"
///|
fn wasmImportUnload(p0 : Int) = "chandra:host/plasmoids@0.1.0" "unload"
///|
fn wasmImportSetTokens(p0 : Int) = "chandra:host/plasmoids@0.1.0" "set-tokens"
///|
fn wasmImportRender(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "chandra:host/plasmoids@0.1.0" "render"
///|
fn wasmImportPopup(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "popup"
///|
fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int = "chandra:host/plasmoids@0.1.0" "on-event"
///|
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasmoids@0.1.0" "publish-table"
///|
fn wasmImportPublishState(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "publish-state"
///|
fn wasmImportPublishWallpaper(p0 : Int) = "chandra:host/plasmoids@0.1.0" "publish-wallpaper"
///|
fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) = "chandra:host/plasmoids@0.1.0" "publish-system"
///|
fn wasmImportPublishWindows(p0 : Int, p1 : Int) = "chandra:host/plasmoids@0.1.0" "publish-windows"
///|
fn wasmImportNextRequest(p0 : Int) = "chandra:host/plasmoids@0.1.0" "next-request"
///|
fn wasmImportTakeFocusRequest(p0 : Int) = "chandra:host/plasmoids@0.1.0" "take-focus-request"
///|
fn wasmImportListWasmFiles(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/plasmoids@0.1.0" "list-wasm-files"
///|
fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start"
///|
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
///|
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)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load)
///|
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)
///|
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_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_store64(offset : Int, value : Int64) =
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
+14
View File
@@ -0,0 +1,14 @@
import {
"chandra/desktop/interface/chandra/desktop/theme" @theme,
"chandra/desktop/interface/chandra/desktop/types" @types,
}
warnings = "-44"
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
@@ -0,0 +1,136 @@
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
///|
fn wasmImportLoad(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportUnload(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportSetTokens(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportRender(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPopup(p0 : Int, p1 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportPublishTable(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishState(p0 : Int, p1 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishWallpaper(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishSystem(p0 : Int, p1 : Int64, p2 : Int64, p3 : Int, p4 : Int, p5 : Int64, p6 : Int64, p7 : Int64, p8 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPublishWindows(p0 : Int, p1 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportNextRequest(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportTakeFocusRequest(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportListWasmFiles(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPickerStart() -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportPickerPoll(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_store8(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load64(offset : Int) -> Int64 {
abort("wasm-only")
}
///|
fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load8_u(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
abort("wasm-only")
}
///|
fn mbt_ffi_store64(offset : Int, value : Int64) -> Unit {
abort("wasm-only")
}
@@ -0,0 +1,99 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/host/plasmoids"
import {
"chandra/desktop/interface/chandra/desktop/theme",
"chandra/desktop/interface/chandra/desktop/types",
}
// Values
pub fn list_wasm_files(String) -> Array[String]
pub fn load(String) -> Result[Loaded, String]
pub fn next_request() -> Request?
pub fn on_event(UInt32, Bool, @types.InputEvent) -> Bool
pub fn picker_poll() -> PickerState
pub fn picker_start() -> Bool
pub fn popup(UInt32) -> PopupSurface?
pub fn publish_state(Int32, Bool) -> Unit
pub fn publish_system(SystemSnapshot) -> Unit
pub fn publish_table(UInt32, FixedArray[Byte]) -> Unit
pub fn publish_wallpaper(Int32) -> Unit
pub fn publish_windows(Array[WindowEntry]) -> Unit
pub fn render(UInt32, @types.Size) -> Array[@types.DrawOp]
pub fn set_tokens(@theme.Tokens) -> Unit
pub fn take_focus_request() -> UInt64?
pub fn unload(UInt32) -> Unit
// Errors
// Types and methods
pub(all) struct Loaded {
handle : UInt32
id : String
name : String
preferred : @types.Size
min_width : UInt32
stretch : Bool
imports : Array[String]
}
pub(all) enum PickerState {
Open
Cancelled
Chosen(String)
}
pub(all) struct PopupSurface {
box : @types.Size
ops : Array[@types.DrawOp]
}
pub(all) enum Request {
Launch(String)
FocusWindow(Int32)
SetLayout(Int32)
SetInspector(Bool)
LoadModule(String)
UnloadInstance(String)
Browse
Logout
SetWallpaper(Int32)
}
pub(all) struct SystemSnapshot {
cpu_permille : UInt32
mem_used_kib : UInt64
mem_total_kib : UInt64
battery_percent : Int32
charging : Bool
uptime_secs : UInt64
net_rx_bytes_per_sec : UInt64
net_tx_bytes_per_sec : UInt64
load_centi : UInt32
}
pub(all) struct WindowEntry {
id : UInt64
title : String
app_id : String
focused : Bool
}
// Type aliases
// Traits
+506
View File
@@ -0,0 +1,506 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// A loaded module. `imports` is its capability grant: the host interfaces its binary imports
/// (besides theme), e.g. ["clock"] or ["windows", "system"].
pub(all) struct Loaded {
handle : UInt; id : String; name : String; preferred : @types.Size; min_width : UInt; stretch : Bool; imports : Array[String]
}
///|
pub(all) struct PopupSurface {
box : @types.Size; ops : Array[@types.DrawOp]
}
///|
pub(all) struct SystemSnapshot {
cpu_permille : UInt; mem_used_kib : UInt64; mem_total_kib : UInt64; battery_percent : Int; charging : Bool; uptime_secs : UInt64; net_rx_bytes_per_sec : UInt64; net_tx_bytes_per_sec : UInt64; load_centi : UInt
}
///|
pub(all) struct WindowEntry {
id : UInt64; title : String; app_id : String; focused : Bool
}
///|
/// ---- what modules asked of the host ----
pub(all) enum Request {
Launch(String)
FocusWindow(Int)
SetLayout(Int)
SetInspector(Bool)
LoadModule(String)
UnloadInstance(String)
Browse
Logout
SetWallpaper(Int)
}
///|
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
pub(all) enum PickerState {
Open
Cancelled
Chosen(String)
}
///|
/// Load the plasmoid component at `path`. The error is a short reason.
pub fn load(path : String) -> Result[Loaded, String] {
let ptr = mbt_ffi_str2ptr(path)
let return_area = mbt_ffi_malloc(48)
wasmImportLoad(ptr, path.length(), return_area);
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
0 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 16), mbt_ffi_load32((return_area) + 20))
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 44)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 40)) + (index * 8)
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result1)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 40))
Result::Ok(Loaded::{handle : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), id : result, name : result0, preferred : @types.Size::{w : (mbt_ffi_load32((return_area) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((return_area) + 28)).reinterpret_as_uint()}, min_width : (mbt_ffi_load32((return_area) + 32)).reinterpret_as_uint(), stretch : (mbt_ffi_load8_u((return_area) + 36) != 0), imports : array})
}
1 => {
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
Result::Err(result2)
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn unload(handle : UInt) -> Unit {
wasmImportUnload((handle).reinterpret_as_int());
}
///|
/// The theme the modules see through `theme.get-tokens` (set before drawing so a swap shows at once).
pub fn set_tokens(t : @theme.Tokens) -> Unit {
let return_area = mbt_ffi_malloc(64)
let ptr = mbt_ffi_str2ptr((t).name)
mbt_ffi_store32((return_area) + 4, (t).name.length())
mbt_ffi_store32((return_area) + 0, ptr)
mbt_ffi_store8((return_area) + 8, ((((t).palette).desktop_top).r).to_int())
mbt_ffi_store8((return_area) + 9, ((((t).palette).desktop_top).g).to_int())
mbt_ffi_store8((return_area) + 10, ((((t).palette).desktop_top).b).to_int())
mbt_ffi_store8((return_area) + 11, ((((t).palette).desktop_top).a).to_int())
mbt_ffi_store8((return_area) + 12, ((((t).palette).desktop_bottom).r).to_int())
mbt_ffi_store8((return_area) + 13, ((((t).palette).desktop_bottom).g).to_int())
mbt_ffi_store8((return_area) + 14, ((((t).palette).desktop_bottom).b).to_int())
mbt_ffi_store8((return_area) + 15, ((((t).palette).desktop_bottom).a).to_int())
mbt_ffi_store8((return_area) + 16, ((((t).palette).surface).r).to_int())
mbt_ffi_store8((return_area) + 17, ((((t).palette).surface).g).to_int())
mbt_ffi_store8((return_area) + 18, ((((t).palette).surface).b).to_int())
mbt_ffi_store8((return_area) + 19, ((((t).palette).surface).a).to_int())
mbt_ffi_store8((return_area) + 20, ((((t).palette).surface_hover).r).to_int())
mbt_ffi_store8((return_area) + 21, ((((t).palette).surface_hover).g).to_int())
mbt_ffi_store8((return_area) + 22, ((((t).palette).surface_hover).b).to_int())
mbt_ffi_store8((return_area) + 23, ((((t).palette).surface_hover).a).to_int())
mbt_ffi_store8((return_area) + 24, ((((t).palette).surface_popup).r).to_int())
mbt_ffi_store8((return_area) + 25, ((((t).palette).surface_popup).g).to_int())
mbt_ffi_store8((return_area) + 26, ((((t).palette).surface_popup).b).to_int())
mbt_ffi_store8((return_area) + 27, ((((t).palette).surface_popup).a).to_int())
mbt_ffi_store8((return_area) + 28, ((((t).palette).foreground).r).to_int())
mbt_ffi_store8((return_area) + 29, ((((t).palette).foreground).g).to_int())
mbt_ffi_store8((return_area) + 30, ((((t).palette).foreground).b).to_int())
mbt_ffi_store8((return_area) + 31, ((((t).palette).foreground).a).to_int())
mbt_ffi_store8((return_area) + 32, ((((t).palette).foreground_muted).r).to_int())
mbt_ffi_store8((return_area) + 33, ((((t).palette).foreground_muted).g).to_int())
mbt_ffi_store8((return_area) + 34, ((((t).palette).foreground_muted).b).to_int())
mbt_ffi_store8((return_area) + 35, ((((t).palette).foreground_muted).a).to_int())
mbt_ffi_store8((return_area) + 36, ((((t).palette).accent).r).to_int())
mbt_ffi_store8((return_area) + 37, ((((t).palette).accent).g).to_int())
mbt_ffi_store8((return_area) + 38, ((((t).palette).accent).b).to_int())
mbt_ffi_store8((return_area) + 39, ((((t).palette).accent).a).to_int())
mbt_ffi_store8((return_area) + 40, ((((t).palette).accent_foreground).r).to_int())
mbt_ffi_store8((return_area) + 41, ((((t).palette).accent_foreground).g).to_int())
mbt_ffi_store8((return_area) + 42, ((((t).palette).accent_foreground).b).to_int())
mbt_ffi_store8((return_area) + 43, ((((t).palette).accent_foreground).a).to_int())
mbt_ffi_store8((return_area) + 44, ((((t).palette).border).r).to_int())
mbt_ffi_store8((return_area) + 45, ((((t).palette).border).g).to_int())
mbt_ffi_store8((return_area) + 46, ((((t).palette).border).b).to_int())
mbt_ffi_store8((return_area) + 47, ((((t).palette).border).a).to_int())
mbt_ffi_store32((return_area) + 48, ((t).font_size).reinterpret_as_int())
mbt_ffi_store32((return_area) + 52, ((t).radius).reinterpret_as_int())
mbt_ffi_store32((return_area) + 56, ((t).spacing).reinterpret_as_int())
mbt_ffi_store32((return_area) + 60, ((t).panel_height).reinterpret_as_int())
wasmImportSetTokens(return_area);
mbt_ffi_free(return_area)
mbt_ffi_free(ptr)
}
///|
pub fn render(handle : UInt, box : @types.Size) -> Array[@types.DrawOp] {
let return_area = mbt_ffi_malloc(8)
wasmImportRender((handle).reinterpret_as_int(), ((box).w).reinterpret_as_int(), ((box).h).reinterpret_as_int(), return_area);
let array : Array[@types.DrawOp] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
@types.DrawOp::FillRect(@types.FillRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, radius : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
}
1 => {
@types.DrawOp::StrokeRect(@types.StrokeRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), radius : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()})
}
2 => {
@types.DrawOp::Line(@types.LineOp::{start : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, end : @types.Point::{x : mbt_ffi_load32((iter_base) + 12), y : mbt_ffi_load32((iter_base) + 16)}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
}
3 => {
@types.DrawOp::Circle(@types.CircleOp::{center : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, radius : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 16)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 17)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 18)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 19)).to_byte()}, filled : (mbt_ffi_load8_u((iter_base) + 20) != 0)})
}
4 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16))
@types.DrawOp::Text(@types.TextOp::{origin : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, text : result, style : @types.TextStyle::{size : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 24)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 25)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 26)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 27)).to_byte()}, align : @types.TextAlign::from(mbt_ffi_load8_u((iter_base) + 28)), bold : (mbt_ffi_load8_u((iter_base) + 29) != 0)}})
}
5 => {
@types.DrawOp::PushClip(@types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()})
}
6 => {
@types.DrawOp::PopClip
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
pub fn popup(handle : UInt) -> PopupSurface? {
let return_area = mbt_ffi_malloc(20)
wasmImportPopup((handle).reinterpret_as_int(), return_area);
let lifted0 : PopupSurface? = match mbt_ffi_load8_u((return_area) + 0) {
0 => Option::None
1 => {
let array : Array[@types.DrawOp] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 16)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 12)) + (index * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
@types.DrawOp::FillRect(@types.FillRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, radius : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
}
1 => {
@types.DrawOp::StrokeRect(@types.StrokeRectOp::{rect : @types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), radius : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()})
}
2 => {
@types.DrawOp::Line(@types.LineOp::{start : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, end : @types.Point::{x : mbt_ffi_load32((iter_base) + 12), y : mbt_ffi_load32((iter_base) + 16)}, color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 20)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 21)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 22)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 23)).to_byte()}, width : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
}
3 => {
@types.DrawOp::Circle(@types.CircleOp::{center : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, radius : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 16)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 17)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 18)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 19)).to_byte()}, filled : (mbt_ffi_load8_u((iter_base) + 20) != 0)})
}
4 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 12), mbt_ffi_load32((iter_base) + 16))
@types.DrawOp::Text(@types.TextOp::{origin : @types.Point::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8)}, text : result, style : @types.TextStyle::{size : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint(), color : @types.Color::{r : (mbt_ffi_load8_u((iter_base) + 24)).to_byte(), g : (mbt_ffi_load8_u((iter_base) + 25)).to_byte(), b : (mbt_ffi_load8_u((iter_base) + 26)).to_byte(), a : (mbt_ffi_load8_u((iter_base) + 27)).to_byte()}, align : @types.TextAlign::from(mbt_ffi_load8_u((iter_base) + 28)), bold : (mbt_ffi_load8_u((iter_base) + 29) != 0)}})
}
5 => {
@types.DrawOp::PushClip(@types.Rect::{x : mbt_ffi_load32((iter_base) + 4), y : mbt_ffi_load32((iter_base) + 8), w : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()})
}
6 => {
@types.DrawOp::PopClip
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 12))
Option::Some(PopupSurface::{box : @types.Size::{w : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), h : (mbt_ffi_load32((return_area) + 8)).reinterpret_as_uint()}, ops : array})
}
_ => panic()
}
let ret = lifted0
mbt_ffi_free(return_area)
return ret
}
///|
/// Deliver an event to the module (`on-popup`: to its popup surface). True when it wants a redraw.
pub fn on_event(handle : UInt, on_popup : Bool, event : @types.InputEvent) -> Bool {
let cleanup_list : Array[Int] = []
let (lowered,lowered5,lowered6) = match event {
PointerMove(payload) => {
((0), (payload).x, (payload).y)
}
PointerDown(payload0) => {
((1), (payload0).x, (payload0).y)
}
PointerUp(payload1) => {
((2), (payload1).x, (payload1).y)
}
PointerLeave => {
((3), 0, 0)
}
FocusLost => {
((4), 0, 0)
}
KeyDown(payload4) => {
let ptr = mbt_ffi_str2ptr(payload4)
cleanup_list.push(ptr)
((5), ptr, payload4.length())
}
}
let result : Int = wasmImportOnEvent((handle).reinterpret_as_int(), (if on_popup { 1 } else { 0 }), lowered, lowered5, lowered6);
let ret = (result != 0)
cleanup_list.each(mbt_ffi_free)
return ret
}
///|
/// ---- host data modules read through their capabilities ----
/// Row tables, as built by compositor/wasm: a LE u32 row count, then per row each field as a LE
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s).
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
let ptr = mbt_ffi_bytes2ptr(rows)
wasmImportPublishTable((which).reinterpret_as_int(), ptr, rows.length());
mbt_ffi_free(ptr)
}
///|
/// Layout mode (0 tiling, 1 monocle, 2 floating) and whether the Interface Explorer is on.
pub fn publish_state(layout_mode : Int, inspector_on : Bool) -> Unit {
wasmImportPublishState(layout_mode, (if inspector_on { 1 } else { 0 }));
}
///|
/// The wallpaper on the desktop now (an index into the wallpapers table).
pub fn publish_wallpaper(current : Int) -> Unit {
wasmImportPublishWallpaper(current);
}
///|
pub fn publish_system(s : SystemSnapshot) -> Unit {
wasmImportPublishSystem(((s).cpu_permille).reinterpret_as_int(), ((s).mem_used_kib).reinterpret_as_int64(), ((s).mem_total_kib).reinterpret_as_int64(), (s).battery_percent, (if (s).charging { 1 } else { 0 }), ((s).uptime_secs).reinterpret_as_int64(), ((s).net_rx_bytes_per_sec).reinterpret_as_int64(), ((s).net_tx_bytes_per_sec).reinterpret_as_int64(), ((s).load_centi).reinterpret_as_int());
}
///|
pub fn publish_windows(wins : Array[WindowEntry]) -> Unit {
let cleanup_list : Array[Int] = []
let address = mbt_ffi_malloc((wins).length() * 32);
for index = 0; index < (wins).length(); index = index + 1 {
let iter_elem : WindowEntry = (wins)[(index)]
let iter_base = address + (index * 32);
mbt_ffi_store64((iter_base) + 0, ((iter_elem).id).reinterpret_as_int64())
let ptr = mbt_ffi_str2ptr((iter_elem).title)
mbt_ffi_store32((iter_base) + 12, (iter_elem).title.length())
mbt_ffi_store32((iter_base) + 8, ptr)
let ptr0 = mbt_ffi_str2ptr((iter_elem).app_id)
mbt_ffi_store32((iter_base) + 20, (iter_elem).app_id.length())
mbt_ffi_store32((iter_base) + 16, ptr0)
mbt_ffi_store8((iter_base) + 24, (if (iter_elem).focused { 1 } else { 0 }))
cleanup_list.push(ptr)
cleanup_list.push(ptr0)
}
wasmImportPublishWindows(address, (wins).length());
mbt_ffi_free(address)
cleanup_list.each(mbt_ffi_free)
}
///|
/// The next pending request, oldest first.
pub fn next_request() -> Request? {
let return_area = mbt_ffi_malloc(16)
wasmImportNextRequest(return_area);
let lifted2 : Request? = match mbt_ffi_load8_u((return_area) + 0) {
0 => Option::None
1 => {
let lifted = match (mbt_ffi_load8_u((return_area) + 4)) {
0 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
Request::Launch(result)
}
1 => {
Request::FocusWindow(mbt_ffi_load32((return_area) + 8))
}
2 => {
Request::SetLayout(mbt_ffi_load32((return_area) + 8))
}
3 => {
Request::SetInspector((mbt_ffi_load8_u((return_area) + 8) != 0))
}
4 => {
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
Request::LoadModule(result0)
}
5 => {
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
Request::UnloadInstance(result1)
}
6 => {
Request::Browse
}
7 => {
Request::Logout
}
8 => {
Request::SetWallpaper(mbt_ffi_load32((return_area) + 8))
}
_ => panic()
}
Option::Some(lifted)
}
_ => panic()
}
let ret = lifted2
mbt_ffi_free(return_area)
return ret
}
///|
/// A window a module asked to focus through `windows.focus` (64-bit id), since the last call.
pub fn take_focus_request() -> UInt64? {
let return_area = mbt_ffi_malloc(16)
wasmImportTakeFocusRequest(return_area);
let lifted : UInt64? = match mbt_ffi_load8_u((return_area) + 0) {
0 => Option::None
1 => {
Option::Some((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64())
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(return_area)
return ret
}
///|
/// Names of the `*.wasm` files directly in `dir`, sorted.
pub fn list_wasm_files(dir : String) -> Array[String] {
let ptr = mbt_ffi_str2ptr(dir)
let return_area = mbt_ffi_malloc(8)
wasmImportListWasmFiles(ptr, dir.length(), return_area);
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn picker_start() -> Bool {
let result : Int = wasmImportPickerStart();
let ret = (result != 0)
return ret
}
///|
pub fn picker_poll() -> PickerState {
let return_area = mbt_ffi_malloc(12)
wasmImportPickerPoll(return_area);
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
0 => {
PickerState::Open
}
1 => {
PickerState::Cancelled
}
2 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
PickerState::Chosen(result)
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(return_area)
return ret
}
+52
View File
@@ -0,0 +1,52 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportCapture(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int = "chandra:host/raster@0.1.0" "capture"
///|
fn wasmImportRelease(p0 : Int) = "chandra:host/raster@0.1.0" "release"
///|
fn wasmImportSubmit(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int, p12 : Int) = "chandra:host/raster@0.1.0" "submit"
///|
fn wasmImportReadFrame(p0 : Int) = "chandra:host/raster@0.1.0" "read-frame"
///|
fn wasmImportExportMemfd() -> Int = "chandra:host/raster@0.1.0" "export-memfd"
///|
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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
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)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
+9
View File
@@ -0,0 +1,9 @@
warnings = "-44"
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
@@ -0,0 +1,61 @@
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
///|
fn wasmImportCapture(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportRelease(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportSubmit(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int, p9 : Int, p10 : Int, p11 : Int, p12 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportReadFrame(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportExportMemfd() -> Int {
abort("wasm-only host import")
}
///|
fn mbt_ffi_store8(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
///|
fn mbt_ffi_store32(offset : Int, value : Int) -> Unit {
abort("wasm-only")
}
+550
View File
@@ -0,0 +1,550 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Rect {
x : Int; y : Int; w : Int; h : Int
}
///|
pub(all) struct Color {
r : Byte; g : Byte; b : Byte; a : Byte
}
///|
pub(all) struct Fill {
area : Rect; color : Color; radius : Int
}
///|
pub(all) struct Stroke {
area : Rect; color : Color; width : Int; radius : Int
}
///|
pub(all) struct Segment {
x0 : Int; y0 : Int; x1 : Int; y1 : Int; color : Color; width : Int
}
///|
pub(all) struct Disc {
cx : Int; cy : Int; radius : Int; color : Color; filled : Bool
}
///|
/// `align`: 0 left, 1 centre, 2 right of `x`; `y` is the text's vertical centre.
pub(all) struct Label {
x : Int; y : Int; text : String; size : Int; color : Color; align : Byte; bold : Bool; mono : Bool
}
///|
pub(all) enum Op {
FillRect(Fill)
StrokeRect(Stroke)
DrawLine(Segment)
DrawCircle(Disc)
DrawText(Label)
PushClip(Rect)
PopClip
}
///|
/// A toplevel: its decoration (drawn at `geometry` minus the insets), then its client surface.
pub(all) struct Window {
geometry : Rect; inset_top : Int; inset_right : Int; inset_bottom : Int; inset_left : Int; deco : Array[Op]; fullscreen : Bool; surface : UInt
}
///|
pub(all) struct Popup {
area : Rect; surface : UInt
}
///|
pub(all) struct Frame {
width : Int; height : Int; wallpaper : Array[Op]?; background : Array[Op]; windows : Array[Window]; panel : Array[Op]; popups : Array[Popup]
}
///|
/// Copy a client buffer (`stride * height` bytes at `offset` of the file behind `fd`) into a
/// host surface. `format` is the wl_shm format (0 ARGB8888, 1 XRGB8888). 0 on failure.
pub fn capture(fd : Int, offset : Int, stride : Int, width : Int, height : Int, format : Int) -> UInt {
let result : Int = wasmImportCapture(fd, offset, stride, width, height, format);
let ret = (result).reinterpret_as_uint()
return ret
}
///|
pub fn release(id : UInt) -> Unit {
wasmImportRelease((id).reinterpret_as_int());
}
///|
/// Draw a frame into the host framebuffer.
pub fn submit(f : Frame) -> Unit {
let cleanup_list : Array[Int] = []
let (lowered, lowered8, lowered9) = match ((f).wallpaper) {
None => {
((0), 0, 0)
}
Some(payload0) => {
let address = mbt_ffi_malloc((payload0).length() * 32);
for index = 0; index < (payload0).length(); index = index + 1 {
let iter_elem : Op = (payload0)[(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).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload1).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload1).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload1).area).h)
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)
()
}
StrokeRect(payload2) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload2).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload2).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload2).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload2).area).h)
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)
mbt_ffi_store32((iter_base) + 28, (payload2).radius)
()
}
DrawLine(payload3) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, (payload3).x0)
mbt_ffi_store32((iter_base) + 8, (payload3).y0)
mbt_ffi_store32((iter_base) + 12, (payload3).x1)
mbt_ffi_store32((iter_base) + 16, (payload3).y1)
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)
()
}
DrawCircle(payload4) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, (payload4).cx)
mbt_ffi_store32((iter_base) + 8, (payload4).cy)
mbt_ffi_store32((iter_base) + 12, (payload4).radius)
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 }))
()
}
DrawText(payload5) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, (payload5).x)
mbt_ffi_store32((iter_base) + 8, (payload5).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).size)
mbt_ffi_store8((iter_base) + 24, (((payload5).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, (((payload5).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, (((payload5).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, (((payload5).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload5).align).to_int())
mbt_ffi_store8((iter_base) + 29, (if (payload5).bold { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 30, (if (payload5).mono { 1 } else { 0 }))
cleanup_list.push(ptr)
()
}
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)
mbt_ffi_store32((iter_base) + 16, (payload6).h)
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
cleanup_list.push(address)
((1), address, (payload0).length())
}
}
let address18 = mbt_ffi_malloc(((f).background).length() * 32);
for index19 = 0; index19 < ((f).background).length(); index19 = index19 + 1 {
let iter_elem : Op = ((f).background)[(index19)]
let iter_base = address18 + (index19 * 32);
match iter_elem {
FillRect(payload10) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload10).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload10).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload10).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload10).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload10).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload10).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload10).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload10).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload10).radius)
()
}
StrokeRect(payload11) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload11).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload11).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload11).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload11).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload11).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload11).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload11).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload11).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload11).width)
mbt_ffi_store32((iter_base) + 28, (payload11).radius)
()
}
DrawLine(payload12) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, (payload12).x0)
mbt_ffi_store32((iter_base) + 8, (payload12).y0)
mbt_ffi_store32((iter_base) + 12, (payload12).x1)
mbt_ffi_store32((iter_base) + 16, (payload12).y1)
mbt_ffi_store8((iter_base) + 20, (((payload12).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload12).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload12).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload12).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload12).width)
()
}
DrawCircle(payload13) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, (payload13).cx)
mbt_ffi_store32((iter_base) + 8, (payload13).cy)
mbt_ffi_store32((iter_base) + 12, (payload13).radius)
mbt_ffi_store8((iter_base) + 16, (((payload13).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload13).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload13).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload13).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload13).filled { 1 } else { 0 }))
()
}
DrawText(payload14) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, (payload14).x)
mbt_ffi_store32((iter_base) + 8, (payload14).y)
let ptr15 = mbt_ffi_str2ptr((payload14).text)
mbt_ffi_store32((iter_base) + 16, (payload14).text.length())
mbt_ffi_store32((iter_base) + 12, ptr15)
mbt_ffi_store32((iter_base) + 20, (payload14).size)
mbt_ffi_store8((iter_base) + 24, (((payload14).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, (((payload14).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, (((payload14).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, (((payload14).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload14).align).to_int())
mbt_ffi_store8((iter_base) + 29, (if (payload14).bold { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 30, (if (payload14).mono { 1 } else { 0 }))
cleanup_list.push(ptr15)
()
}
PushClip(payload16) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload16).x)
mbt_ffi_store32((iter_base) + 8, (payload16).y)
mbt_ffi_store32((iter_base) + 12, (payload16).w)
mbt_ffi_store32((iter_base) + 16, (payload16).h)
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
let address30 = mbt_ffi_malloc(((f).windows).length() * 48);
for index31 = 0; index31 < ((f).windows).length(); index31 = index31 + 1 {
let iter_elem : Window = ((f).windows)[(index31)]
let iter_base = address30 + (index31 * 48);
mbt_ffi_store32((iter_base) + 0, ((iter_elem).geometry).x)
mbt_ffi_store32((iter_base) + 4, ((iter_elem).geometry).y)
mbt_ffi_store32((iter_base) + 8, ((iter_elem).geometry).w)
mbt_ffi_store32((iter_base) + 12, ((iter_elem).geometry).h)
mbt_ffi_store32((iter_base) + 16, (iter_elem).inset_top)
mbt_ffi_store32((iter_base) + 20, (iter_elem).inset_right)
mbt_ffi_store32((iter_base) + 24, (iter_elem).inset_bottom)
mbt_ffi_store32((iter_base) + 28, (iter_elem).inset_left)
let address28 = mbt_ffi_malloc(((iter_elem).deco).length() * 32);
for index29 = 0; index29 < ((iter_elem).deco).length(); index29 = index29 + 1 {
let iter_elem : Op = ((iter_elem).deco)[(index29)]
let iter_base = address28 + (index29 * 32);
match iter_elem {
FillRect(payload20) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload20).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload20).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload20).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload20).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload20).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload20).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload20).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload20).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload20).radius)
()
}
StrokeRect(payload21) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload21).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload21).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload21).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload21).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload21).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload21).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload21).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload21).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload21).width)
mbt_ffi_store32((iter_base) + 28, (payload21).radius)
()
}
DrawLine(payload22) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, (payload22).x0)
mbt_ffi_store32((iter_base) + 8, (payload22).y0)
mbt_ffi_store32((iter_base) + 12, (payload22).x1)
mbt_ffi_store32((iter_base) + 16, (payload22).y1)
mbt_ffi_store8((iter_base) + 20, (((payload22).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload22).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload22).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload22).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload22).width)
()
}
DrawCircle(payload23) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, (payload23).cx)
mbt_ffi_store32((iter_base) + 8, (payload23).cy)
mbt_ffi_store32((iter_base) + 12, (payload23).radius)
mbt_ffi_store8((iter_base) + 16, (((payload23).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload23).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload23).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload23).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload23).filled { 1 } else { 0 }))
()
}
DrawText(payload24) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, (payload24).x)
mbt_ffi_store32((iter_base) + 8, (payload24).y)
let ptr25 = mbt_ffi_str2ptr((payload24).text)
mbt_ffi_store32((iter_base) + 16, (payload24).text.length())
mbt_ffi_store32((iter_base) + 12, ptr25)
mbt_ffi_store32((iter_base) + 20, (payload24).size)
mbt_ffi_store8((iter_base) + 24, (((payload24).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, (((payload24).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, (((payload24).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, (((payload24).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload24).align).to_int())
mbt_ffi_store8((iter_base) + 29, (if (payload24).bold { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 30, (if (payload24).mono { 1 } else { 0 }))
cleanup_list.push(ptr25)
()
}
PushClip(payload26) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload26).x)
mbt_ffi_store32((iter_base) + 8, (payload26).y)
mbt_ffi_store32((iter_base) + 12, (payload26).w)
mbt_ffi_store32((iter_base) + 16, (payload26).h)
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
mbt_ffi_store32((iter_base) + 36, ((iter_elem).deco).length())
mbt_ffi_store32((iter_base) + 32, address28)
mbt_ffi_store8((iter_base) + 40, (if (iter_elem).fullscreen { 1 } else { 0 }))
mbt_ffi_store32((iter_base) + 44, ((iter_elem).surface).reinterpret_as_int())
cleanup_list.push(address28)
}
let address40 = mbt_ffi_malloc(((f).panel).length() * 32);
for index41 = 0; index41 < ((f).panel).length(); index41 = index41 + 1 {
let iter_elem : Op = ((f).panel)[(index41)]
let iter_base = address40 + (index41 * 32);
match iter_elem {
FillRect(payload32) => {
mbt_ffi_store8((iter_base) + 0, (0))
mbt_ffi_store32((iter_base) + 4, ((payload32).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload32).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload32).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload32).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload32).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload32).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload32).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload32).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload32).radius)
()
}
StrokeRect(payload33) => {
mbt_ffi_store8((iter_base) + 0, (1))
mbt_ffi_store32((iter_base) + 4, ((payload33).area).x)
mbt_ffi_store32((iter_base) + 8, ((payload33).area).y)
mbt_ffi_store32((iter_base) + 12, ((payload33).area).w)
mbt_ffi_store32((iter_base) + 16, ((payload33).area).h)
mbt_ffi_store8((iter_base) + 20, (((payload33).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload33).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload33).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload33).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload33).width)
mbt_ffi_store32((iter_base) + 28, (payload33).radius)
()
}
DrawLine(payload34) => {
mbt_ffi_store8((iter_base) + 0, (2))
mbt_ffi_store32((iter_base) + 4, (payload34).x0)
mbt_ffi_store32((iter_base) + 8, (payload34).y0)
mbt_ffi_store32((iter_base) + 12, (payload34).x1)
mbt_ffi_store32((iter_base) + 16, (payload34).y1)
mbt_ffi_store8((iter_base) + 20, (((payload34).color).r).to_int())
mbt_ffi_store8((iter_base) + 21, (((payload34).color).g).to_int())
mbt_ffi_store8((iter_base) + 22, (((payload34).color).b).to_int())
mbt_ffi_store8((iter_base) + 23, (((payload34).color).a).to_int())
mbt_ffi_store32((iter_base) + 24, (payload34).width)
()
}
DrawCircle(payload35) => {
mbt_ffi_store8((iter_base) + 0, (3))
mbt_ffi_store32((iter_base) + 4, (payload35).cx)
mbt_ffi_store32((iter_base) + 8, (payload35).cy)
mbt_ffi_store32((iter_base) + 12, (payload35).radius)
mbt_ffi_store8((iter_base) + 16, (((payload35).color).r).to_int())
mbt_ffi_store8((iter_base) + 17, (((payload35).color).g).to_int())
mbt_ffi_store8((iter_base) + 18, (((payload35).color).b).to_int())
mbt_ffi_store8((iter_base) + 19, (((payload35).color).a).to_int())
mbt_ffi_store8((iter_base) + 20, (if (payload35).filled { 1 } else { 0 }))
()
}
DrawText(payload36) => {
mbt_ffi_store8((iter_base) + 0, (4))
mbt_ffi_store32((iter_base) + 4, (payload36).x)
mbt_ffi_store32((iter_base) + 8, (payload36).y)
let ptr37 = mbt_ffi_str2ptr((payload36).text)
mbt_ffi_store32((iter_base) + 16, (payload36).text.length())
mbt_ffi_store32((iter_base) + 12, ptr37)
mbt_ffi_store32((iter_base) + 20, (payload36).size)
mbt_ffi_store8((iter_base) + 24, (((payload36).color).r).to_int())
mbt_ffi_store8((iter_base) + 25, (((payload36).color).g).to_int())
mbt_ffi_store8((iter_base) + 26, (((payload36).color).b).to_int())
mbt_ffi_store8((iter_base) + 27, (((payload36).color).a).to_int())
mbt_ffi_store8((iter_base) + 28, ((payload36).align).to_int())
mbt_ffi_store8((iter_base) + 29, (if (payload36).bold { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 30, (if (payload36).mono { 1 } else { 0 }))
cleanup_list.push(ptr37)
()
}
PushClip(payload38) => {
mbt_ffi_store8((iter_base) + 0, (5))
mbt_ffi_store32((iter_base) + 4, (payload38).x)
mbt_ffi_store32((iter_base) + 8, (payload38).y)
mbt_ffi_store32((iter_base) + 12, (payload38).w)
mbt_ffi_store32((iter_base) + 16, (payload38).h)
()
}
PopClip => {
mbt_ffi_store8((iter_base) + 0, (6))
()
}
}
}
let address42 = mbt_ffi_malloc(((f).popups).length() * 20);
for index43 = 0; index43 < ((f).popups).length(); index43 = index43 + 1 {
let iter_elem : Popup = ((f).popups)[(index43)]
let iter_base = address42 + (index43 * 20);
mbt_ffi_store32((iter_base) + 0, ((iter_elem).area).x)
mbt_ffi_store32((iter_base) + 4, ((iter_elem).area).y)
mbt_ffi_store32((iter_base) + 8, ((iter_elem).area).w)
mbt_ffi_store32((iter_base) + 12, ((iter_elem).area).h)
mbt_ffi_store32((iter_base) + 16, ((iter_elem).surface).reinterpret_as_int())
}
wasmImportSubmit((f).width, (f).height, lowered, lowered8, lowered9, address18, ((f).background).length(), address30, ((f).windows).length(), address40, ((f).panel).length(), address42, ((f).popups).length());
mbt_ffi_free(address18)
mbt_ffi_free(address30)
mbt_ffi_free(address40)
mbt_ffi_free(address42)
cleanup_list.each(mbt_ffi_free)
}
///|
/// The framebuffer as RGBA8888 (for screenshots and tests; the display path never needs it).
pub fn read_frame() -> FixedArray[Byte] {
let return_area = mbt_ffi_malloc(8)
wasmImportReadFrame(return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(return_area)
return ret
}
///|
/// A new memfd holding the framebuffer as little-endian ARGB8888, ready to hand to a Wayland
/// compositor as a wl_shm pool. The caller closes it. -1 on failure.
pub fn export_memfd() -> Int {
let result : Int = wasmImportExportMemfd();
let ret = result
return ret
}
+3
View File
@@ -0,0 +1,3 @@
The operating-system surface the compositor component needs, nothing more. The native host
implements it with real syscalls; the component holds only integer handles (fds) and bytes.
Mirrors compositor/sys.
+116
View File
@@ -0,0 +1,116 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportUnixListen(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "unix-listen"
///|
fn wasmImportUnixAccept(p0 : Int) -> Int = "chandra:host/sys@0.1.0" "unix-accept"
///|
fn wasmImportUnixConnect(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "unix-connect"
///|
fn wasmImportCloseFd(p0 : Int) = "chandra:host/sys@0.1.0" "close-fd"
///|
fn wasmImportUnlink(p0 : Int, p1 : Int) = "chandra:host/sys@0.1.0" "unlink"
///|
fn wasmImportPollRead(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "poll-read"
///|
fn wasmImportRecvmsg(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "recvmsg"
///|
fn wasmImportSendmsg(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "sendmsg"
///|
fn wasmImportMemfdCreate(p0 : Int, p1 : Int, p2 : Int) -> Int = "chandra:host/sys@0.1.0" "memfd-create"
///|
fn wasmImportPwrite(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "pwrite"
///|
fn wasmImportMmapRead(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "mmap-read"
///|
fn wasmImportMmapReadAt(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "chandra:host/sys@0.1.0" "mmap-read-at"
///|
fn wasmImportReadFile(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "read-file"
///|
fn wasmImportWriteFile(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "write-file"
///|
fn wasmImportReadProc(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "read-proc"
///|
fn wasmImportMkdirP(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "mkdir-p"
///|
fn wasmImportListDesktopFiles(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "list-desktop-files"
///|
fn wasmImportSleepMs(p0 : Int) = "chandra:host/sys@0.1.0" "sleep-ms"
///|
fn wasmImportMonotonicMs() -> Int64 = "chandra:host/sys@0.1.0" "monotonic-ms"
///|
fn wasmImportLog(p0 : Int, p1 : Int) = "chandra:host/sys@0.1.0" "log"
///|
fn wasmImportGetpid() -> Int = "chandra:host/sys@0.1.0" "getpid"
///|
fn wasmImportWallTimeField(p0 : Int) -> Int = "chandra:host/sys@0.1.0" "wall-time-field"
///|
fn wasmImportGetenv(p0 : Int, p1 : Int, p2 : Int) = "chandra:host/sys@0.1.0" "getenv"
///|
fn wasmImportHasExe(p0 : Int, p1 : Int) -> Int = "chandra:host/sys@0.1.0" "has-exe"
///|
fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int = "chandra:host/sys@0.1.0" "spawn"
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
///|
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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
+9
View File
@@ -0,0 +1,9 @@
warnings = "-44"
// ffi.mbt is generated and wasm-only; native builds use native_stub.mbt (scripts/gen-native-stubs.py).
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
+161
View File
@@ -0,0 +1,161 @@
// Generated by scripts/gen-native-stubs.py. Native stand-ins for the wasm-only ffi.mbt.
///|
fn wasmImportUnixListen(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportUnixAccept(p0 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportUnixConnect(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportCloseFd(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportUnlink(p0 : Int, p1 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportPollRead(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportRecvmsg(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportSendmsg(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportMemfdCreate(p0 : Int, p1 : Int, p2 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportPwrite(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportMmapRead(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportMmapReadAt(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportReadFile(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportWriteFile(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportReadProc(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportMkdirP(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportListDesktopFiles(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportSleepMs(p0 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportMonotonicMs() -> Int64 {
abort("wasm-only host import")
}
///|
fn wasmImportLog(p0 : Int, p1 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportGetpid() -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportWallTimeField(p0 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportGetenv(p0 : Int, p1 : Int, p2 : Int) -> Unit {
abort("wasm-only host import")
}
///|
fn wasmImportHasExe(p0 : Int, p1 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn wasmImportSpawn(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
abort("wasm-only host import")
}
///|
fn mbt_ffi_str2ptr(str : String) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String {
abort("wasm-only")
}
///|
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
@@ -0,0 +1,66 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/host/sys"
// Values
pub fn close_fd(Int32) -> Unit
pub fn getenv(String) -> String
pub fn getpid() -> Int32
pub fn has_exe(String) -> Bool
pub fn list_desktop_files(String) -> Array[String]
pub fn log(String) -> Unit
pub fn memfd_create(String, Int32) -> Int32
pub fn mkdir_p(String) -> Bool
pub fn mmap_read(Int32, Int32) -> FixedArray[Byte]
pub fn mmap_read_at(Int32, Int32, Int32) -> FixedArray[Byte]
pub fn monotonic_ms() -> UInt64
pub fn poll_read(Int32, Int32) -> Int32
pub fn pwrite(Int32, FixedArray[Byte], Int32) -> Int32
pub fn read_file(String) -> FixedArray[Byte]
pub fn read_proc(String) -> FixedArray[Byte]
pub fn recvmsg(Int32, UInt32) -> Received
pub fn sendmsg(Int32, FixedArray[Byte], Int32) -> Int32
pub fn sleep_ms(Int32) -> Unit
pub fn spawn(String, String) -> Bool
pub fn unix_accept(Int32) -> Int32
pub fn unix_connect(String) -> Int32
pub fn unix_listen(String) -> Int32
pub fn unlink(String) -> Unit
pub fn wall_time_field(Int32) -> Int32
pub fn write_file(String, FixedArray[Byte]) -> Int32
// Errors
// Types and methods
pub(all) struct Received {
count : Int32
fd : Int32
data : FixedArray[Byte]
}
// Type aliases
// Traits
+288
View File
@@ -0,0 +1,288 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Result of `recvmsg`: byte count (-1 would-block, -2 error, 0 EOF), an fd received over
/// SCM_RIGHTS (-1 when none), and the bytes read.
pub(all) struct Received {
count : Int; fd : Int; data : FixedArray[Byte]
}
///|
/// Listen on a unix socket at `path`; -1 on failure.
pub fn unix_listen(path : String) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportUnixListen(ptr, path.length());
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
/// Accept a pending client (non-blocking); -1 when none.
pub fn unix_accept(listen_fd : Int) -> Int {
let result : Int = wasmImportUnixAccept(listen_fd);
let ret = result
return ret
}
///|
pub fn unix_connect(path : String) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportUnixConnect(ptr, path.length());
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn close_fd(fd : Int) -> Unit {
wasmImportCloseFd(fd);
}
///|
pub fn unlink(path : String) -> Unit {
let ptr = mbt_ffi_str2ptr(path)
wasmImportUnlink(ptr, path.length());
mbt_ffi_free(ptr)
}
///|
/// 1 when `fd` is readable within `timeout-ms`, 0 on timeout, <0 on error.
pub fn poll_read(fd : Int, timeout_ms : Int) -> Int {
let result : Int = wasmImportPollRead(fd, timeout_ms);
let ret = result
return ret
}
///|
pub fn recvmsg(fd : Int, max_len : UInt) -> Received {
let return_area = mbt_ffi_malloc(16)
wasmImportRecvmsg(fd, (max_len).reinterpret_as_int(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
let ret = Received::{count : mbt_ffi_load32((return_area) + 0), fd : mbt_ffi_load32((return_area) + 4), data : result}
mbt_ffi_free(return_area)
return ret
}
///|
/// Send `data`, with `send-fd` (or -1) as SCM_RIGHTS; bytes sent or <0.
pub fn sendmsg(fd : Int, data : FixedArray[Byte], send_fd : Int) -> Int {
let ptr = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportSendmsg(fd, ptr, data.length(), send_fd);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn memfd_create(name : String, size : Int) -> Int {
let ptr = mbt_ffi_str2ptr(name)
let result : Int = wasmImportMemfdCreate(ptr, name.length(), size);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn pwrite(fd : Int, data : FixedArray[Byte], offset : Int) -> Int {
let ptr = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportPwrite(fd, ptr, data.length(), offset);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
/// Copy `size` bytes of the file behind `fd` (mapped read-only by the host).
pub fn mmap_read(fd : Int, size : Int) -> FixedArray[Byte] {
let return_area = mbt_ffi_malloc(8)
wasmImportMmapRead(fd, size, return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(return_area)
return ret
}
///|
/// Copy `len` bytes starting at `offset` of the file behind `fd` (a client's buffer inside its
/// shared pool; a pool can be far larger than any one buffer, so never read from byte 0).
pub fn mmap_read_at(fd : Int, offset : Int, len : Int) -> FixedArray[Byte] {
let return_area = mbt_ffi_malloc(8)
wasmImportMmapReadAt(fd, offset, len, return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(return_area)
return ret
}
///|
pub fn read_file(path : String) -> FixedArray[Byte] {
let ptr = mbt_ffi_str2ptr(path)
let return_area = mbt_ffi_malloc(8)
wasmImportReadFile(ptr, path.length(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn write_file(path : String, data : FixedArray[Byte]) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let ptr0 = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportWriteFile(ptr, path.length(), ptr0, data.length());
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(ptr0)
return ret
}
///|
/// Contents of a small /proc or /sys file ("" when unreadable).
pub fn read_proc(path : String) -> FixedArray[Byte] {
let ptr = mbt_ffi_str2ptr(path)
let return_area = mbt_ffi_malloc(8)
wasmImportReadProc(ptr, path.length(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn mkdir_p(path : String) -> Bool {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportMkdirP(ptr, path.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
return ret
}
///|
/// Names of the *.desktop files directly in `dir`.
pub fn list_desktop_files(dir : String) -> Array[String] {
let ptr = mbt_ffi_str2ptr(dir)
let return_area = mbt_ffi_malloc(8)
wasmImportListDesktopFiles(ptr, dir.length(), return_area);
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn sleep_ms(ms : Int) -> Unit {
wasmImportSleepMs(ms);
}
///|
/// Milliseconds on a monotonic clock (event timestamps).
pub fn monotonic_ms() -> UInt64 {
let result : Int64 = wasmImportMonotonicMs();
let ret = (result).reinterpret_as_uint64()
return ret
}
///|
/// Print a line to the host's stderr.
pub fn log(message : String) -> Unit {
let ptr = mbt_ffi_str2ptr(message)
wasmImportLog(ptr, message.length());
mbt_ffi_free(ptr)
}
///|
pub fn getpid() -> Int {
let result : Int = wasmImportGetpid();
let ret = result
return ret
}
///|
/// 0 year, 1 month (1-12), 2 day, 3 hour, 4 minute, 5 second, 6 weekday (0 = Sunday).
pub fn wall_time_field(which : Int) -> Int {
let result : Int = wasmImportWallTimeField(which);
let ret = result
return ret
}
///|
pub fn getenv(name : String) -> String {
let ptr = mbt_ffi_str2ptr(name)
let return_area = mbt_ffi_malloc(8)
wasmImportGetenv(ptr, name.length(), return_area);
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn has_exe(name : String) -> Bool {
let ptr = mbt_ffi_str2ptr(name)
let result : Int = wasmImportHasExe(ptr, name.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
return ret
}
///|
/// Launch `cmd` detached with WAYLAND_DISPLAY set to `display`.
pub fn spawn(cmd : String, display : String) -> Bool {
let ptr = mbt_ffi_str2ptr(cmd)
let ptr0 = mbt_ffi_str2ptr(display)
let result : Int = wasmImportSpawn(ptr, cmd.length(), ptr0, display.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
mbt_ffi_free(ptr0)
return ret
}