The wasm compositor as a login session: DRM/KMS + libinput through the host
CI / test (push) Failing after 1m13s
CI / test (push) Failing after 1m13s
New moonplasma:host/display import (open, poll, present, cursor, input events, close). The wasmtime host implements it by compiling the compositor's own kms shim (libseat + DRM/KMS + libinput + xkbcommon) via build.rs (feature drm, default on), so the native and wasm backends share one implementation. compositor/kms gets a wasm backend with the same API, and the shared app loop gains --drm. - session: install.py installs the host, compositor.wasm, fonts, config, wit and modules and the display-manager entry (--native keeps the old native session); the launcher starts the host when installed. just run-drm / install-session use the wasm compositor; *-native keep the old. - compositor.wasm moves to build/ (out of build/components, where the module catalog scans). Verified: component builds with the new import, host instantiates it and renders frames, installed layout (fonts/modules/theme from the share dir) renders correctly in a sandbox, native build and tests unchanged. NOT exercised on a real login VT. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95b7275b3a
commit
c03d4c6c17
32 files changed
+862
-124
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
fn wasmImportOpen(p0 : Int) = "moonplasma:host/display@0.1.0" "open"
|
||||
|
||||
///|
|
||||
fn wasmImportPoll() -> Int = "moonplasma:host/display@0.1.0" "poll"
|
||||
|
||||
///|
|
||||
fn wasmImportFrameReady() -> Int = "moonplasma:host/display@0.1.0" "frame-ready"
|
||||
|
||||
///|
|
||||
fn wasmImportPresent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "moonplasma:host/display@0.1.0" "present"
|
||||
|
||||
///|
|
||||
fn wasmImportSetCursorShape(p0 : Int) = "moonplasma:host/display@0.1.0" "set-cursor-shape"
|
||||
|
||||
///|
|
||||
fn wasmImportTakeInput(p0 : Int) = "moonplasma:host/display@0.1.0" "take-input"
|
||||
|
||||
///|
|
||||
fn wasmImportClose() = "moonplasma:host/display@0.1.0" "close"
|
||||
|
||||
///|
|
||||
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_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)
|
||||
|
||||
///|
|
||||
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(bytes)
|
||||
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> 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)
|
||||
|
||||
@@ -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,71 @@
|
||||
// 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 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_load8_u(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
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_free(position : Int) -> Unit {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_malloc(size : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
|
||||
///|
|
||||
fn mbt_ffi_load32(offset : Int) -> Int {
|
||||
abort("wasm-only")
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "moonplasma/desktop/interface/moonplasma/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 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) enum SeatEvent {
|
||||
PointerMove(PointerPos)
|
||||
PointerButton(KeyState)
|
||||
Key(KeyState)
|
||||
Modifiers(Modifiers)
|
||||
}
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
@@ -0,0 +1,131 @@
|
||||
// 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
|
||||
}
|
||||
///|
|
||||
pub(all) enum SeatEvent {
|
||||
PointerMove(PointerPos)
|
||||
PointerButton(KeyState)
|
||||
Key(KeyState)
|
||||
Modifiers(Modifiers)
|
||||
}
|
||||
///|
|
||||
/// 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 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 * 24)
|
||||
|
||||
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()})
|
||||
}
|
||||
_ => 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();
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user