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
+54
-3
@@ -1,12 +1,12 @@
|
||||
//! Native host for the moon-plasma compositor component.
|
||||
//!
|
||||
//! The compositor is a wasm component (build/components/compositor.wasm) that imports exactly one
|
||||
//! The compositor is a wasm component (build/compositor.wasm) that imports exactly one
|
||||
//! interface, `moonplasma:host/sys` (wit/host/sys.wit): sockets, memfd, poll, spawn, files, time.
|
||||
//! This program is the other side of that interface. The component only ever holds integer
|
||||
//! handles; every real file descriptor lives here.
|
||||
//!
|
||||
//! moon-plasma-host [--component PATH] [-- compositor args...]
|
||||
//! moon-plasma-host build/components/compositor.wasm --socket /run/user/1000/wayland-moon-0 --window
|
||||
//! moon-plasma-host build/compositor.wasm --socket /run/user/1000/wayland-moon-0 --window
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::io::Read;
|
||||
@@ -16,6 +16,8 @@ use wasmtime::component::{Component, HasSelf, Linker};
|
||||
use wasmtime::{Config, Engine, Result, Store};
|
||||
|
||||
mod plasmoid;
|
||||
#[cfg(feature = "drm")]
|
||||
mod kms;
|
||||
|
||||
wasmtime::component::bindgen!({
|
||||
path: "../wit/host",
|
||||
@@ -227,6 +229,54 @@ impl moonplasma::host::plasmoids::Host for State {
|
||||
}
|
||||
}
|
||||
|
||||
impl moonplasma::host::display::Host for State {
|
||||
fn open(&mut self) -> Option<moonplasma::host::display::Output> {
|
||||
#[cfg(feature = "drm")]
|
||||
{
|
||||
kms::open()
|
||||
}
|
||||
#[cfg(not(feature = "drm"))]
|
||||
{
|
||||
eprintln!("this host was built without the `drm` feature (no login-session backend)");
|
||||
None
|
||||
}
|
||||
}
|
||||
fn poll(&mut self) -> bool {
|
||||
#[cfg(feature = "drm")]
|
||||
return kms::poll();
|
||||
#[cfg(not(feature = "drm"))]
|
||||
false
|
||||
}
|
||||
fn frame_ready(&mut self) -> bool {
|
||||
#[cfg(feature = "drm")]
|
||||
return kms::frame_ready();
|
||||
#[cfg(not(feature = "drm"))]
|
||||
false
|
||||
}
|
||||
fn present(&mut self, pixels: Vec<u8>, width: u32, height: u32) {
|
||||
#[cfg(feature = "drm")]
|
||||
kms::present(&pixels, width, height);
|
||||
#[cfg(not(feature = "drm"))]
|
||||
let _ = (pixels, width, height);
|
||||
}
|
||||
fn set_cursor_shape(&mut self, shape: u32) {
|
||||
#[cfg(feature = "drm")]
|
||||
kms::set_cursor_shape(shape);
|
||||
#[cfg(not(feature = "drm"))]
|
||||
let _ = shape;
|
||||
}
|
||||
fn take_input(&mut self) -> Vec<moonplasma::host::display::SeatEvent> {
|
||||
#[cfg(feature = "drm")]
|
||||
return kms::take_input();
|
||||
#[cfg(not(feature = "drm"))]
|
||||
Vec::new()
|
||||
}
|
||||
fn close(&mut self) {
|
||||
#[cfg(feature = "drm")]
|
||||
kms::close();
|
||||
}
|
||||
}
|
||||
|
||||
impl moonplasma::host::font::Host for State {
|
||||
fn load(&mut self, slot: u32, path: String) -> bool {
|
||||
if slot as usize >= self.fonts.len() {
|
||||
@@ -592,7 +642,7 @@ fn main() -> Result<()> {
|
||||
let component_path = if args.first().map(|a| a.ends_with(".wasm")).unwrap_or(false) {
|
||||
args.remove(0)
|
||||
} else {
|
||||
"build/components/compositor.wasm".to_string()
|
||||
"build/compositor.wasm".to_string()
|
||||
};
|
||||
if args.first().map(|a| a == "--").unwrap_or(false) {
|
||||
args.remove(0);
|
||||
@@ -614,6 +664,7 @@ fn main() -> Result<()> {
|
||||
let mut linker: Linker<State> = Linker::new(&engine);
|
||||
moonplasma::host::sys::add_to_linker::<State, HasSelf<State>>(&mut linker, |s| s)?;
|
||||
moonplasma::host::font::add_to_linker::<State, HasSelf<State>>(&mut linker, |s| s)?;
|
||||
moonplasma::host::display::add_to_linker::<State, HasSelf<State>>(&mut linker, |s| s)?;
|
||||
moonplasma::host::plasmoids::add_to_linker::<State, HasSelf<State>>(&mut linker, |s| s)?;
|
||||
let mut store = Store::new(&engine, State::default());
|
||||
store.data_mut().pl = Some(plasmoid::Runtime::new(&engine)?);
|
||||
|
||||
Reference in new issue
Block a user