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

@@ -0,0 +1,27 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportListApps(p0 : Int) = "chandra:desktop/app-catalog@0.1.0" "list-apps"
///|
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_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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)
@@ -0,0 +1,5 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,17 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/app-catalog"
import {
"chandra/desktop/interface/chandra/desktop/types",
}
// Values
pub fn list_apps() -> Array[@types.AppEntry]
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,31 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Installed applications (static list in the PoC; .desktop files later).
pub fn list_apps() -> Array[@types.AppEntry] {
let return_area = mbt_ffi_malloc(8)
wasmImportListApps(return_area);
let array : Array[@types.AppEntry] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 40)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 24), mbt_ffi_load32((iter_base) + 28))
let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 32), mbt_ffi_load32((iter_base) + 36))
array.push(@types.AppEntry::{id : result, name : result0, comment : result1, category : result2, glyph : result3})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,36 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLaunch(p0 : Int, p1 : Int, p2 : Int) = "chandra:desktop/app-launch@0.1.0" "launch"
///|
#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_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)
///|
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_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,13 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/app-launch"
// Values
pub fn launch(String) -> Result[Unit, String]
// Errors
// Types and methods
// Type aliases
// Traits
@@ -0,0 +1,29 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Ask the host to start an application by catalog id.
pub fn launch(id : String) -> Result[Unit, String] {
let ptr = mbt_ffi_str2ptr(id)
let return_area = mbt_ffi_malloc(12)
wasmImportLaunch(ptr, id.length(), return_area);
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
0 => {
Result::Ok(())
}
1 => {
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 4), mbt_ffi_load32((return_area) + 8))
Result::Err(result)
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,2 @@
Host-brokered capabilities. A component can only call what its world
imports AND what the host grants it in the desktop manifest.
+24
View File
@@ -0,0 +1,24 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportNow(p0 : Int) = "chandra:desktop/clock@0.1.0" "now"
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
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_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_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
+5
View File
@@ -0,0 +1,5 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,17 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/clock"
import {
"chandra/desktop/interface/chandra/desktop/types",
}
// Values
pub fn now() -> @types.Datetime
// Errors
// Types and methods
// Type aliases
// Traits
+13
View File
@@ -0,0 +1,13 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Local wall-clock time (the host owns the time zone).
pub fn now() -> @types.Datetime {
let return_area = mbt_ffi_malloc(12)
wasmImportNow(return_area);
let ret = @types.Datetime::{year : (mbt_ffi_load32((return_area) + 0)).reinterpret_as_uint(), month : (mbt_ffi_load8_u((return_area) + 4)).to_byte(), day : (mbt_ffi_load8_u((return_area) + 5)).to_byte(), hour : (mbt_ffi_load8_u((return_area) + 6)).to_byte(), minute : (mbt_ffi_load8_u((return_area) + 7)).to_byte(), second : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), weekday : (mbt_ffi_load8_u((return_area) + 9)).to_byte()}
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1 @@
The Interface Explorer: hover any system component to see its WIT.
@@ -0,0 +1,8 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportIsOn() -> Int = "chandra:desktop/inspector@0.1.0" "is-on"
///|
fn wasmImportSetOn(p0 : Int) = "chandra:desktop/inspector@0.1.0" "set-on"
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,16 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn is_on() -> Bool {
let result : Int = wasmImportIsOn();
let ret = (result != 0)
return ret
}
///|
pub fn set_on(on : Bool) -> Unit {
wasmImportSetOn((if on { 1 } else { 0 }));
}
@@ -0,0 +1 @@
The window manager's layout mode (tiling / monocle / floating).
@@ -0,0 +1,33 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLayoutModes(p0 : Int) = "chandra:desktop/layout-control@0.1.0" "layout-modes"
///|
fn wasmImportCurrentLayout() -> Int = "chandra:desktop/layout-control@0.1.0" "current-layout"
///|
fn wasmImportSetLayout(p0 : Int) = "chandra:desktop/layout-control@0.1.0" "set-layout"
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
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_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)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,37 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Display names, indexed by mode.
pub fn layout_modes() -> Array[String] {
let return_area = mbt_ffi_malloc(8)
wasmImportLayoutModes(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(return_area)
return ret
}
///|
pub fn current_layout() -> UInt {
let result : Int = wasmImportCurrentLayout();
let ret = (result).reinterpret_as_uint()
return ret
}
///|
pub fn set_layout(mode : UInt) -> Unit {
wasmImportSetLayout((mode).reinterpret_as_int());
}
@@ -0,0 +1,2 @@
Hot-swap of the system's own wasm modules. A module with this capability
is a module manager: it decides what is loaded into the panel.
+44
View File
@@ -0,0 +1,44 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportAvailable(p0 : Int) = "chandra:desktop/modules@0.1.0" "available"
///|
fn wasmImportLoaded(p0 : Int) = "chandra:desktop/modules@0.1.0" "loaded"
///|
fn wasmImportLoadModule(p0 : Int, p1 : Int) = "chandra:desktop/modules@0.1.0" "load-module"
///|
fn wasmImportUnloadInstance(p0 : Int, p1 : Int) = "chandra:desktop/modules@0.1.0" "unload-instance"
///|
fn wasmImportBrowse() = "chandra:desktop/modules@0.1.0" "browse"
///|
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_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
@@ -0,0 +1 @@
warnings = "-44"
+85
View File
@@ -0,0 +1,85 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// A loadable module found on the module search path.
pub(all) struct ModuleInfo {
id : String; name : String; path : String; loaded : UInt
}
///|
/// A module instance currently loaded in the panel, in panel order.
pub(all) struct InstanceInfo {
slot : String; module_ : String; name : String
}
///|
pub fn available() -> Array[ModuleInfo] {
let return_area = mbt_ffi_malloc(8)
wasmImportAvailable(return_area);
let array : Array[ModuleInfo] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 28)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
array.push(ModuleInfo::{id : result, name : result0, path : result1, loaded : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint()})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
pub fn loaded() -> Array[InstanceInfo] {
let return_area = mbt_ffi_malloc(8)
wasmImportLoaded(return_area);
let array : Array[InstanceInfo] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 24)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result1 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
array.push(InstanceInfo::{slot : result, module_ : result0, name : result1})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Load the module file at `path` into the panel (any number of instances).
pub fn load_module(path : String) -> Unit {
let ptr = mbt_ffi_str2ptr(path)
wasmImportLoadModule(ptr, path.length());
mbt_ffi_free(ptr)
}
///|
/// Unload one loaded instance, freeing its panel space.
pub fn unload_instance(slot : String) -> Unit {
let ptr = mbt_ffi_str2ptr(slot)
wasmImportUnloadInstance(ptr, slot.length());
mbt_ffi_free(ptr)
}
///|
/// Ask the host to show its native file chooser for a .wasm elsewhere on disk.
pub fn browse() -> Unit {
wasmImportBrowse();
}
@@ -0,0 +1,2 @@
Ending the login session. A module with this capability is a logout button: the host stops the
compositor, and the display manager takes the screen back.
@@ -0,0 +1,5 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportLogout() = "chandra:desktop/session@0.1.0" "logout"
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,8 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub fn logout() -> Unit {
wasmImportLogout();
}
@@ -0,0 +1 @@
Look-and-feel design tokens (Plasma "Look and Feel"/colour scheme analogue).
+31
View File
@@ -0,0 +1,31 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportGetTokens(p0 : Int) = "chandra:desktop/theme@0.1.0" "get-tokens"
///|
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)
///|
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)
+14
View File
@@ -0,0 +1,14 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
}
warnings = "-44"
// ffi.mbt is generated wasm-only; native builds (the compositor) get abort stubs
// from native_stub.mbt so the pure `Tokens` types stay usable.
options(
targets: {
"ffi.mbt": ["wasm", "wasm-gc"],
"native_stub.mbt": ["native"],
},
)
@@ -0,0 +1,33 @@
///| Native stand-ins for the wasm component-model FFI in ffi.mbt. The native
/// compositor uses only the `Tokens`/`Palette` types; `get_tokens` is a guest
/// import that has no meaning outside a wasm component, so it aborts.
///|
fn wasmImportGetTokens(_p0 : Int) -> Unit {
abort("theme.get-tokens is a wasm component import; unavailable on native")
}
///|
fn mbt_ffi_free(_position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2str(_ptr : Int, _len : Int) -> String {
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_load8_u(_offset : Int) -> Int {
abort("wasm-only")
}
@@ -0,0 +1,38 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/theme"
import {
"chandra/desktop/interface/chandra/desktop/types",
}
// Values
pub fn get_tokens() -> Tokens
// Errors
// Types and methods
pub(all) struct Palette {
desktop_top : @types.Color
desktop_bottom : @types.Color
surface : @types.Color
surface_hover : @types.Color
surface_popup : @types.Color
foreground : @types.Color
foreground_muted : @types.Color
accent : @types.Color
accent_foreground : @types.Color
border : @types.Color
}
pub(all) struct Tokens {
name : String
palette : Palette
font_size : UInt32
radius : UInt32
spacing : UInt32
panel_height : UInt32
}
// Type aliases
// Traits
+23
View File
@@ -0,0 +1,23 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Palette {
desktop_top : @types.Color; desktop_bottom : @types.Color; surface : @types.Color; surface_hover : @types.Color; surface_popup : @types.Color; foreground : @types.Color; foreground_muted : @types.Color; accent : @types.Color; accent_foreground : @types.Color; border : @types.Color
}
///|
pub(all) struct Tokens {
name : String; palette : Palette; font_size : UInt; radius : UInt; spacing : UInt; panel_height : UInt
}
///|
/// Read on every render so a theme swap shows up on the next frame.
pub fn get_tokens() -> Tokens {
let return_area = mbt_ffi_malloc(64)
wasmImportGetTokens(return_area);
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = Tokens::{name : result, palette : Palette::{desktop_top : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 8)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 9)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 10)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 11)).to_byte()}, desktop_bottom : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 12)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 13)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 14)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 15)).to_byte()}, surface : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 16)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 17)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 18)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 19)).to_byte()}, surface_hover : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 20)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 21)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 22)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 23)).to_byte()}, surface_popup : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 24)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 25)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 26)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 27)).to_byte()}, foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 28)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 29)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 30)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 31)).to_byte()}, foreground_muted : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 32)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 33)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 34)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 35)).to_byte()}, accent : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 36)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 37)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 38)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 39)).to_byte()}, accent_foreground : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 40)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 41)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 42)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 43)).to_byte()}, border : @types.Color::{r : (mbt_ffi_load8_u((return_area) + 44)).to_byte(), g : (mbt_ffi_load8_u((return_area) + 45)).to_byte(), b : (mbt_ffi_load8_u((return_area) + 46)).to_byte(), a : (mbt_ffi_load8_u((return_area) + 47)).to_byte()}}, font_size : (mbt_ffi_load32((return_area) + 48)).reinterpret_as_uint(), radius : (mbt_ffi_load32((return_area) + 52)).reinterpret_as_uint(), spacing : (mbt_ffi_load32((return_area) + 56)).reinterpret_as_uint(), panel_height : (mbt_ffi_load32((return_area) + 60)).reinterpret_as_uint()}
mbt_ffi_free(return_area)
return ret
}
@@ -0,0 +1,2 @@
Shared value types. Everything here is plain data (no resources) so that
it can cross any component boundary and any host implementation.
+2
View File
@@ -0,0 +1,2 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
+1
View File
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,120 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/desktop/types"
// Values
// Errors
// Types and methods
pub(all) struct AppEntry {
id : String
name : String
comment : String
category : String
glyph : String
}
pub(all) struct CircleOp {
center : Point
radius : UInt32
color : Color
filled : Bool
}
pub(all) struct Color {
r : Byte
g : Byte
b : Byte
a : Byte
}
pub(all) struct Datetime {
year : UInt32
month : Byte
day : Byte
hour : Byte
minute : Byte
second : Byte
weekday : Byte
}
pub(all) enum DrawOp {
FillRect(FillRectOp)
StrokeRect(StrokeRectOp)
Line(LineOp)
Circle(CircleOp)
Text(TextOp)
PushClip(Rect)
PopClip
}
pub(all) struct FillRectOp {
rect : Rect
color : Color
radius : UInt32
}
pub(all) enum InputEvent {
PointerMove(Point)
PointerDown(Point)
PointerUp(Point)
PointerLeave
FocusLost
KeyDown(String)
}
pub(all) struct LineOp {
start : Point
end : Point
color : Color
width : UInt32
}
pub(all) struct Point {
x : Int32
y : Int32
}
pub(all) struct Rect {
x : Int32
y : Int32
w : UInt32
h : UInt32
}
pub(all) struct Size {
w : UInt32
h : UInt32
}
pub(all) struct StrokeRectOp {
rect : Rect
color : Color
width : UInt32
radius : UInt32
}
pub(all) enum TextAlign {
LEFT
CENTER
RIGHT
}
pub fn TextAlign::from(Int32) -> Self
pub fn TextAlign::ordinal(Self) -> Int32
pub(all) struct TextOp {
origin : Point
text : String
style : TextStyle
}
pub(all) struct TextStyle {
size : UInt32
color : Color
align : TextAlign
bold : Bool
}
// Type aliases
// Traits
+98
View File
@@ -0,0 +1,98 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct Size {
w : UInt; h : UInt
}
///|
pub(all) struct Point {
x : Int; y : Int
}
///|
pub(all) struct Rect {
x : Int; y : Int; w : UInt; h : UInt
}
///|
/// Non-premultiplied sRGB, 8 bits per channel.
pub(all) struct Color {
r : Byte; g : Byte; b : Byte; a : Byte
}
///|
pub(all) enum TextAlign {
LEFT; CENTER; RIGHT
} derive()
///|
pub fn TextAlign::ordinal(self : TextAlign) -> Int {
match self {
LEFT => 0
CENTER => 1
RIGHT => 2
}
}
///|
pub fn TextAlign::from(self : Int) -> TextAlign {
match self {
0 => LEFT
1 => CENTER
2 => RIGHT
_ => panic()
}
}
///|
pub(all) struct TextStyle {
size : UInt; color : Color; align : TextAlign; bold : Bool
}
///|
pub(all) struct FillRectOp {
rect : Rect; color : Color; radius : UInt
}
///|
pub(all) struct StrokeRectOp {
rect : Rect; color : Color; width : UInt; radius : UInt
}
///|
pub(all) struct LineOp {
start : Point; end : Point; color : Color; width : UInt
}
///|
pub(all) struct CircleOp {
center : Point; radius : UInt; color : Color; filled : Bool
}
///|
/// `origin` is the left edge (align=left), centre (center) or right edge
/// (right) of the text, at the vertical *middle* of the line box.
pub(all) struct TextOp {
origin : Point; text : String; style : TextStyle
}
///|
/// The render-list vocabulary. Components never touch pixels: they return
/// a list of these in their own local coordinate space (origin top-left),
/// and the host/compositor translates, clips and rasterises them.
pub(all) enum DrawOp {
FillRect(FillRectOp)
StrokeRect(StrokeRectOp)
Line(LineOp)
Circle(CircleOp)
Text(TextOp)
PushClip(Rect)
PopClip
}
///|
pub(all) enum InputEvent {
PointerMove(Point)
PointerDown(Point)
PointerUp(Point)
PointerLeave
FocusLost
KeyDown(String)
}
///|
pub(all) struct Datetime {
year : UInt; month : Byte; day : Byte; hour : Byte; minute : Byte; second : Byte; weekday : Byte
}
///|
pub(all) struct AppEntry {
id : String; name : String; comment : String; category : String; glyph : String
}
@@ -0,0 +1,2 @@
The desktop wallpaper. The shell draws a fixed set of wallpapers (from draw ops, coloured by the
theme); a module with this capability lists them and picks which one is on the desktop.
@@ -0,0 +1,33 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportWallpapers(p0 : Int) = "chandra:desktop/wallpaper@0.1.0" "wallpapers"
///|
fn wasmImportCurrentWallpaper() -> Int = "chandra:desktop/wallpaper@0.1.0" "current-wallpaper"
///|
fn wasmImportSetWallpaper(p0 : Int) = "chandra:desktop/wallpaper@0.1.0" "set-wallpaper"
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
@@ -0,0 +1 @@
warnings = "-44"
@@ -0,0 +1,38 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// Display names, indexed by choice.
pub fn wallpapers() -> Array[String] {
let return_area = mbt_ffi_malloc(8)
wasmImportWallpapers(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(return_area)
return ret
}
///|
pub fn current_wallpaper() -> UInt {
let result : Int = wasmImportCurrentWallpaper();
let ret = (result).reinterpret_as_uint()
return ret
}
///|
/// Show wallpaper `index` (out-of-range indices are ignored). The choice is remembered.
pub fn set_wallpaper(index : UInt) -> Unit {
wasmImportSetWallpaper((index).reinterpret_as_int());
}
@@ -0,0 +1 @@
The window list, as shown by a task bar. `id` is an opaque host handle.
+44
View File
@@ -0,0 +1,44 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportListWindows(p0 : Int) = "chandra:desktop/windows@0.1.0" "list-windows"
///|
fn wasmImportFocusWindow(p0 : Int) = "chandra:desktop/windows@0.1.0" "focus-window"
///|
fn wasmImportAll(p0 : Int) = "chandra:desktop/windows@0.1.0" "all"
///|
fn wasmImportFocus(p0 : Int64) = "chandra:desktop/windows@0.1.0" "focus"
///|
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_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.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_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
@@ -0,0 +1 @@
warnings = "-44"
+67
View File
@@ -0,0 +1,67 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct WindowInfo {
id : UInt; title : String; focused : UInt; minimized : UInt
}
///|
/// Richer, id-stable view for widgets that show more than a task bar (the Pulse widget).
pub(all) struct WindowDetail {
id : UInt64; title : String; app_id : String; focused : Bool
}
///|
pub fn list_windows() -> Array[WindowInfo] {
let return_area = mbt_ffi_malloc(8)
wasmImportListWindows(return_area);
let array : Array[WindowInfo] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 20)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 4), mbt_ffi_load32((iter_base) + 8))
array.push(WindowInfo::{id : (mbt_ffi_load32((iter_base) + 0)).reinterpret_as_uint(), title : result, focused : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), minimized : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint()})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Focus, raise (and un-minimize) a window.
pub fn focus_window(id : UInt) -> Unit {
wasmImportFocusWindow((id).reinterpret_as_int());
}
///|
pub fn all() -> Array[WindowDetail] {
let return_area = mbt_ffi_malloc(8)
wasmImportAll(return_area);
let array : Array[WindowDetail] = [];
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 result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 8), mbt_ffi_load32((iter_base) + 12))
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 16), mbt_ffi_load32((iter_base) + 20))
array.push(WindowDetail::{id : (mbt_ffi_load64((iter_base) + 0)).reinterpret_as_uint64(), title : result, app_id : result0, focused : (mbt_ffi_load8_u((iter_base) + 24) != 0)})
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Raise and focus a window (restoring it if minimized).
pub fn focus(id : UInt64) -> Unit {
wasmImportFocus((id).reinterpret_as_int64());
}
+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
}
+63
View File
@@ -0,0 +1,63 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
fn wasmImportSyncWindows(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int) = "chandra:wm/policy@0.2.0" "sync-windows"
///|
fn wasmImportOnWindowOpen(p0 : Int, p1 : Int) = "chandra:wm/policy@0.2.0" "on-window-open"
///|
fn wasmImportOnWindowClose(p0 : Int64, p1 : Int) = "chandra:wm/policy@0.2.0" "on-window-close"
///|
fn wasmImportOnWindowRequest(p0 : Int64, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int, p6 : Int, p7 : Int, p8 : Int) = "chandra:wm/policy@0.2.0" "on-window-request"
///|
fn wasmImportOnPointer(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) = "chandra:wm/policy@0.2.0" "on-pointer"
///|
fn wasmImportSetLayoutMode(p0 : Int, p1 : Int, p2 : Int, p3 : Int, p4 : Int, p5 : Int) = "chandra:wm/policy@0.2.0" "set-layout-mode"
///|
fn wasmImportStackingOrder(p0 : Int) = "chandra:wm/policy@0.2.0" "stacking-order"
///|
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_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_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)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) 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)
///|
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
#|(func (param i32) (result i64) local.get 0 i64.load)
+5
View File
@@ -0,0 +1,5 @@
import {
"chandra/desktop/interface/chandra/desktop/types" @types,
}
warnings = "-44"
@@ -0,0 +1,90 @@
// Generated using `moon info`, DON'T EDIT IT
package "chandra/desktop/interface/chandra/wm/policy"
import {
"chandra/desktop/interface/chandra/desktop/types",
}
// Values
pub fn on_pointer(@types.Point, UInt32?, Bool) -> InputTarget
pub fn on_window_close(UInt64) -> Array[WmAction]
pub fn on_window_open(WindowState, @types.Rect) -> Array[WmAction]
pub fn on_window_request(UInt64, WindowRequest, @types.Rect) -> Array[WmAction]
pub fn set_layout_mode(LayoutMode, @types.Rect) -> Array[WmAction]
pub fn stacking_order() -> Array[UInt64]
pub fn sync_windows(Array[@types.Rect], Array[WindowState]) -> Array[WmAction]
// Errors
// Types and methods
pub(all) enum InputTarget {
Client((UInt64, @types.Point))
Decoration((UInt64, @types.Point))
ShellPanel(@types.Point)
None
}
pub(all) enum LayoutMode {
FLOATING
TILING
MONOCLE
}
pub fn LayoutMode::from(Int32) -> Self
pub fn LayoutMode::ordinal(Self) -> Int32
pub(all) struct WindowCaps(Byte)
pub fn WindowCaps::default() -> Self
pub fn WindowCaps::is_set(Self, WindowCapsFlag) -> Bool
pub fn WindowCaps::set(Self, WindowCapsFlag) -> Self
pub fn WindowCaps::unset(Self, WindowCapsFlag) -> Self
pub(all) enum WindowCapsFlag {
CAN_MOVE
CAN_RESIZE
CAN_MAXIMIZE
CAN_MINIMIZE
CAN_FULLSCREEN
}
pub(all) enum WindowRequest {
Maximize(Bool)
Fullscreen(Bool)
Minimize(Bool)
Close
Activate
MoveTo(@types.Point)
ResizeTo(@types.Size)
}
pub(all) struct WindowState {
id : UInt64
app_id : String
title : String
geometry : @types.Rect
min_size : @types.Size
max_size : @types.Size?
focused : Bool
maximized : Bool
fullscreen : Bool
workspace : UInt32
caps : WindowCaps
}
pub(all) enum WmAction {
SetGeometry((UInt64, @types.Rect))
Focus(UInt64)
Raise(UInt64)
Close(UInt64)
SetMaximized((UInt64, Bool))
SetFullscreen((UInt64, Bool))
}
// Type aliases
// Traits
+518
View File
@@ -0,0 +1,518 @@
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
pub(all) struct WindowCaps(Byte) derive()
///|
pub fn WindowCaps::default() -> WindowCaps {
WindowCaps(b'\x00')
}
///|
pub(all) enum WindowCapsFlag {
CAN_MOVE; CAN_RESIZE; CAN_MAXIMIZE; CAN_MINIMIZE; CAN_FULLSCREEN
}
///|
fn WindowCapsFlag::value(self : WindowCapsFlag) -> Byte {
match self {
CAN_MOVE => ((1U << 0).to_byte())
CAN_RESIZE => ((1U << 1).to_byte())
CAN_MAXIMIZE => ((1U << 2).to_byte())
CAN_MINIMIZE => ((1U << 3).to_byte())
CAN_FULLSCREEN => ((1U << 4).to_byte())
}
}
///|
pub fn WindowCaps::set(self : Self, other: WindowCapsFlag) -> WindowCaps {
let WindowCaps(flag) = self
WindowCaps(flag.lor(other.value()))
}
///|
pub fn WindowCaps::unset(self : Self, other: WindowCapsFlag) -> WindowCaps {
let WindowCaps(flag) = self
WindowCaps(flag.land(other.value().lnot()))
}
///|
pub fn WindowCaps::is_set(self : Self, other: WindowCapsFlag) -> Bool {
let WindowCaps(flag) = self
(flag.land(other.value()) == other.value())
}
///|
pub(all) enum LayoutMode {
FLOATING; TILING; MONOCLE
} derive()
///|
pub fn LayoutMode::ordinal(self : LayoutMode) -> Int {
match self {
FLOATING => 0
TILING => 1
MONOCLE => 2
}
}
///|
pub fn LayoutMode::from(self : Int) -> LayoutMode {
match self {
0 => FLOATING
1 => TILING
2 => MONOCLE
_ => panic()
}
}
///|
pub(all) struct WindowState {
id : UInt64; app_id : String; title : String; geometry : @types.Rect; min_size : @types.Size; max_size : @types.Size?; focused : Bool; maximized : Bool; fullscreen : Bool; workspace : UInt; caps : WindowCaps
}
///|
pub(all) enum WindowRequest {
Maximize(Bool)
Fullscreen(Bool)
Minimize(Bool)
Close
Activate
MoveTo(@types.Point)
ResizeTo(@types.Size)
}
///|
pub(all) enum WmAction {
SetGeometry((UInt64, @types.Rect))
Focus(UInt64)
Raise(UInt64)
Close(UInt64)
SetMaximized((UInt64, Bool))
SetFullscreen((UInt64, Bool))
}
///|
pub(all) enum InputTarget {
Client((UInt64, @types.Point))
Decoration((UInt64, @types.Point))
ShellPanel(@types.Point)
None
}
///|
/// Called on startup or WM hot-swap to synchronize existing windows.
pub fn sync_windows(outputs : Array[@types.Rect], windows : Array[WindowState]) -> Array[WmAction] {
let cleanup_list : Array[Int] = []
let address = mbt_ffi_malloc((outputs).length() * 16);
for index = 0; index < (outputs).length(); index = index + 1 {
let iter_elem : @types.Rect = (outputs)[(index)]
let iter_base = address + (index * 16);
mbt_ffi_store32((iter_base) + 0, (iter_elem).x)
mbt_ffi_store32((iter_base) + 4, (iter_elem).y)
mbt_ffi_store32((iter_base) + 8, ((iter_elem).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 12, ((iter_elem).h).reinterpret_as_int())
}
let address2 = mbt_ffi_malloc((windows).length() * 72);
for index3 = 0; index3 < (windows).length(); index3 = index3 + 1 {
let iter_elem : WindowState = (windows)[(index3)]
let iter_base = address2 + (index3 * 72);
mbt_ffi_store64((iter_base) + 0, ((iter_elem).id).reinterpret_as_int64())
let ptr = mbt_ffi_str2ptr((iter_elem).app_id)
mbt_ffi_store32((iter_base) + 12, (iter_elem).app_id.length())
mbt_ffi_store32((iter_base) + 8, ptr)
let ptr0 = mbt_ffi_str2ptr((iter_elem).title)
mbt_ffi_store32((iter_base) + 20, (iter_elem).title.length())
mbt_ffi_store32((iter_base) + 16, ptr0)
mbt_ffi_store32((iter_base) + 24, ((iter_elem).geometry).x)
mbt_ffi_store32((iter_base) + 28, ((iter_elem).geometry).y)
mbt_ffi_store32((iter_base) + 32, (((iter_elem).geometry).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 36, (((iter_elem).geometry).h).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 40, (((iter_elem).min_size).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 44, (((iter_elem).min_size).h).reinterpret_as_int())
match ((iter_elem).max_size) {
None => {
mbt_ffi_store8((iter_base) + 48, (0))
()
}
Some(payload1) => {
mbt_ffi_store8((iter_base) + 48, (1))
mbt_ffi_store32((iter_base) + 52, ((payload1).w).reinterpret_as_int())
mbt_ffi_store32((iter_base) + 56, ((payload1).h).reinterpret_as_int())
()
}
}
mbt_ffi_store8((iter_base) + 60, (if (iter_elem).focused { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 61, (if (iter_elem).maximized { 1 } else { 0 }))
mbt_ffi_store8((iter_base) + 62, (if (iter_elem).fullscreen { 1 } else { 0 }))
mbt_ffi_store32((iter_base) + 64, ((iter_elem).workspace).reinterpret_as_int())
let WindowCaps(flag) = (iter_elem).caps
mbt_ffi_store8((iter_base) + 68, flag.to_int())
cleanup_list.push(ptr)
cleanup_list.push(ptr0)
}
let return_area = mbt_ffi_malloc(8)
wasmImportSyncWindows(address, (outputs).length(), address2, (windows).length(), return_area);
let array : Array[WmAction] = [];
for index4 = 0; index4 < (mbt_ffi_load32((return_area) + 4)); index4 = index4 + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index4 * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
}
1 => {
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
2 => {
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
3 => {
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
4 => {
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
5 => {
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(address)
mbt_ffi_free(address2)
mbt_ffi_free(return_area)
cleanup_list.each(mbt_ffi_free)
return ret
}
///|
pub fn on_window_open(win : WindowState, work_area : @types.Rect) -> Array[WmAction] {
let return_area = mbt_ffi_malloc(88)
mbt_ffi_store64((return_area) + 0, ((win).id).reinterpret_as_int64())
let ptr = mbt_ffi_str2ptr((win).app_id)
mbt_ffi_store32((return_area) + 12, (win).app_id.length())
mbt_ffi_store32((return_area) + 8, ptr)
let ptr0 = mbt_ffi_str2ptr((win).title)
mbt_ffi_store32((return_area) + 20, (win).title.length())
mbt_ffi_store32((return_area) + 16, ptr0)
mbt_ffi_store32((return_area) + 24, ((win).geometry).x)
mbt_ffi_store32((return_area) + 28, ((win).geometry).y)
mbt_ffi_store32((return_area) + 32, (((win).geometry).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 36, (((win).geometry).h).reinterpret_as_int())
mbt_ffi_store32((return_area) + 40, (((win).min_size).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 44, (((win).min_size).h).reinterpret_as_int())
match ((win).max_size) {
None => {
mbt_ffi_store8((return_area) + 48, (0))
()
}
Some(payload1) => {
mbt_ffi_store8((return_area) + 48, (1))
mbt_ffi_store32((return_area) + 52, ((payload1).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 56, ((payload1).h).reinterpret_as_int())
()
}
}
mbt_ffi_store8((return_area) + 60, (if (win).focused { 1 } else { 0 }))
mbt_ffi_store8((return_area) + 61, (if (win).maximized { 1 } else { 0 }))
mbt_ffi_store8((return_area) + 62, (if (win).fullscreen { 1 } else { 0 }))
mbt_ffi_store32((return_area) + 64, ((win).workspace).reinterpret_as_int())
let WindowCaps(flag) = (win).caps
mbt_ffi_store8((return_area) + 68, flag.to_int())
mbt_ffi_store32((return_area) + 72, (work_area).x)
mbt_ffi_store32((return_area) + 76, (work_area).y)
mbt_ffi_store32((return_area) + 80, ((work_area).w).reinterpret_as_int())
mbt_ffi_store32((return_area) + 84, ((work_area).h).reinterpret_as_int())
let return_area2 = mbt_ffi_malloc(8)
wasmImportOnWindowOpen(return_area, return_area2);
let array : Array[WmAction] = [];
for index = 0; index < (mbt_ffi_load32((return_area2) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area2) + 0)) + (index * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
}
1 => {
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
2 => {
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
3 => {
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
4 => {
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
5 => {
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area2) + 0))
let ret = array
mbt_ffi_free(return_area)
mbt_ffi_free(ptr)
mbt_ffi_free(ptr0)
mbt_ffi_free(return_area2)
return ret
}
///|
pub fn on_window_close(id : UInt64) -> Array[WmAction] {
let return_area = mbt_ffi_malloc(8)
wasmImportOnWindowClose((id).reinterpret_as_int64(), return_area);
let array : Array[WmAction] = [];
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 => {
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
}
1 => {
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
2 => {
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
3 => {
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
4 => {
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
5 => {
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
_ => 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 on_window_request(id : UInt64, req : WindowRequest, work_area : @types.Rect) -> Array[WmAction] {
let (lowered,lowered6,lowered7) = match req {
Maximize(payload) => {
((0), (if payload { 1 } else { 0 }), 0)
}
Fullscreen(payload0) => {
((1), (if payload0 { 1 } else { 0 }), 0)
}
Minimize(payload1) => {
((2), (if payload1 { 1 } else { 0 }), 0)
}
Close => {
((3), 0, 0)
}
Activate => {
((4), 0, 0)
}
MoveTo(payload4) => {
((5), (payload4).x, (payload4).y)
}
ResizeTo(payload5) => {
((6), ((payload5).w).reinterpret_as_int(), ((payload5).h).reinterpret_as_int())
}
}
let return_area = mbt_ffi_malloc(8)
wasmImportOnWindowRequest((id).reinterpret_as_int64(), lowered, lowered6, lowered7, (work_area).x, (work_area).y, ((work_area).w).reinterpret_as_int(), ((work_area).h).reinterpret_as_int(), return_area);
let array : Array[WmAction] = [];
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 => {
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
}
1 => {
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
2 => {
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
3 => {
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
4 => {
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
5 => {
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
_ => 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 on_pointer(pos : @types.Point, button : UInt?, pressed : Bool) -> InputTarget {
let (lowered, lowered1) = match (button) {
None => {
((0), 0)
}
Some(payload0) => {
((1), (payload0).reinterpret_as_int())
}
}
let return_area = mbt_ffi_malloc(24)
wasmImportOnPointer((pos).x, (pos).y, lowered, lowered1, (if pressed { 1 } else { 0 }), return_area);
let lifted = match (mbt_ffi_load8_u((return_area) + 0)) {
0 => {
InputTarget::Client(((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64(), @types.Point::{x : mbt_ffi_load32((return_area) + 16), y : mbt_ffi_load32((return_area) + 20)}))
}
1 => {
InputTarget::Decoration(((mbt_ffi_load64((return_area) + 8)).reinterpret_as_uint64(), @types.Point::{x : mbt_ffi_load32((return_area) + 16), y : mbt_ffi_load32((return_area) + 20)}))
}
2 => {
InputTarget::ShellPanel(@types.Point::{x : mbt_ffi_load32((return_area) + 8), y : mbt_ffi_load32((return_area) + 12)})
}
3 => {
InputTarget::None
}
_ => panic()
}
let ret = lifted
mbt_ffi_free(return_area)
return ret
}
///|
pub fn set_layout_mode(mode : LayoutMode, work_area : @types.Rect) -> Array[WmAction] {
let return_area = mbt_ffi_malloc(8)
wasmImportSetLayoutMode(mode.ordinal(), (work_area).x, (work_area).y, ((work_area).w).reinterpret_as_int(), ((work_area).h).reinterpret_as_int(), return_area);
let array : Array[WmAction] = [];
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 => {
WmAction::SetGeometry(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), @types.Rect::{x : mbt_ffi_load32((iter_base) + 16), y : mbt_ffi_load32((iter_base) + 20), w : (mbt_ffi_load32((iter_base) + 24)).reinterpret_as_uint(), h : (mbt_ffi_load32((iter_base) + 28)).reinterpret_as_uint()}))
}
1 => {
WmAction::Focus((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
2 => {
WmAction::Raise((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
3 => {
WmAction::Close((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64())
}
4 => {
WmAction::SetMaximized(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
5 => {
WmAction::SetFullscreen(((mbt_ffi_load64((iter_base) + 8)).reinterpret_as_uint64(), (mbt_ffi_load8_u((iter_base) + 16) != 0)))
}
_ => panic()
}
array.push(lifted)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}
///|
/// Returns window IDs in bottom-to-top Z-order.
pub fn stacking_order() -> Array[UInt64] {
let return_area = mbt_ffi_malloc(8)
wasmImportStackingOrder(return_area);
let array : Array[UInt64] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
array.push((mbt_ffi_load64((iter_base) + 0)).reinterpret_as_uint64())
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(return_area)
return ret
}