Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hiNfjrw2edja7LiRLB
This commit is contained in:
5 files changed
+223
-25
No files matched your search
@@ -12,6 +12,12 @@ CAPI="$ROOT/.tools/wasmtime-c-api"
|
||||
command -v moon >/dev/null || { echo "error: moon not found" >&2; exit 1; }
|
||||
export C_INCLUDE_PATH="$CAPI/include${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}"
|
||||
export LIBRARY_PATH="$CAPI/lib${LIBRARY_PATH:+:$LIBRARY_PATH}"
|
||||
# libseat (and its headers) from the pixi env when there is one (see pixi.toml).
|
||||
PIXI="$ROOT/.pixi/envs/default"
|
||||
if [ -d "$PIXI/lib" ]; then
|
||||
export C_INCLUDE_PATH="$C_INCLUDE_PATH:$PIXI/include"
|
||||
export LIBRARY_PATH="$LIBRARY_PATH:$PIXI/lib"
|
||||
fi
|
||||
moon build --target native --release --warn-list -a wasmhost/bin
|
||||
mkdir -p build
|
||||
cp _build/native/release/build/wasmhost/bin/bin.exe build/wasmhost
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
///| `chandra:host/display`: the login session (DRM/KMS output, libinput, xkbcommon, libseat),
|
||||
/// through compositor/kms's shim (kms_stub.c), the one the native compositor uses.
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_open() -> Int = "mp_kms_open"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_width() -> Int = "mp_kms_width"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_height() -> Int = "mp_kms_height"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_quit_requested() -> Int = "mp_kms_quit_requested"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_poll() -> Int = "mp_kms_poll"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_frame_ready() -> Int = "mp_kms_frame_ready"
|
||||
|
||||
///|
|
||||
#borrow(pixels)
|
||||
extern "C" fn mp_kms_present(pixels : Bytes, w : Int, h : Int) -> Int = "mp_kms_present"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_set_cursor_shape(shape : Int) = "mp_kms_set_cursor_shape"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_set_power(on : Int) = "mp_kms_set_power"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_next_event() -> Int = "mp_kms_next_event"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_arg(i : Int) -> Int = "mp_kms_arg"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_keymap_len() -> Int = "mp_kms_keymap_len"
|
||||
|
||||
///|
|
||||
#borrow(out)
|
||||
extern "C" fn mp_kms_keymap_copy(out : Bytes) -> Int = "mp_kms_keymap_copy"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_close() = "mp_kms_close"
|
||||
|
||||
///|
|
||||
extern "C" fn mp_kms_fd(i : Int) -> Int = "mp_kms_fd"
|
||||
|
||||
///| Show the rasteriser's framebuffer (raster_stub.c).
|
||||
extern "C" fn rs_present_kms() = "rs_present_kms"
|
||||
|
||||
///| The seat, DRM and input fds while the display is open (none otherwise), for an idle wait.
|
||||
fn display_wait_fds() -> Array[Int] {
|
||||
let out : Array[Int] = []
|
||||
for i in 0..<3 {
|
||||
let fd = mp_kms_fd(i)
|
||||
if fd >= 0 {
|
||||
out.push(fd)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///| Input queued since the last call, as seat events.
|
||||
fn take_input() -> Array[@wt.Val] {
|
||||
let out : Array[@wt.Val] = []
|
||||
while true {
|
||||
let t = mp_kms_next_event()
|
||||
if t == 0 {
|
||||
break
|
||||
}
|
||||
let a = mp_kms_arg(1)
|
||||
let b = mp_kms_arg(2)
|
||||
let key_state = fn() -> @wt.Val {
|
||||
Record([("code", U32(a.reinterpret_as_uint())), ("pressed", Bool(b != 0))])
|
||||
}
|
||||
match t {
|
||||
1 =>
|
||||
out.push(
|
||||
Variant(
|
||||
"pointer-move",
|
||||
Some(Record([("x", F64(a.to_double())), ("y", F64(b.to_double()))])),
|
||||
),
|
||||
)
|
||||
2 => out.push(Variant("pointer-button", Some(key_state())))
|
||||
3 => out.push(Variant("key", Some(key_state())))
|
||||
4 =>
|
||||
out.push(
|
||||
Variant(
|
||||
"modifiers",
|
||||
Some(
|
||||
Record([
|
||||
("depressed", U32(a.reinterpret_as_uint())),
|
||||
("latched", U32(b.reinterpret_as_uint())),
|
||||
("locked", U32(mp_kms_arg(3).reinterpret_as_uint())),
|
||||
("group", U32(mp_kms_arg(4).reinterpret_as_uint())),
|
||||
]),
|
||||
),
|
||||
),
|
||||
)
|
||||
5 =>
|
||||
out.push(
|
||||
Variant(
|
||||
"scroll",
|
||||
Some(
|
||||
Record([
|
||||
("axis", U32(a.reinterpret_as_uint())),
|
||||
("value", F64(b.to_double() / 256.0)),
|
||||
("discrete", S32(mp_kms_arg(3))),
|
||||
]),
|
||||
),
|
||||
),
|
||||
)
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
fn display_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
|
||||
[
|
||||
(
|
||||
"open",
|
||||
_ => {
|
||||
if mp_kms_open() != 0 {
|
||||
// Not an active login VT; the shim has said why on stderr.
|
||||
mp_kms_close()
|
||||
return [Option(None)]
|
||||
}
|
||||
let n = mp_kms_keymap_len()
|
||||
let keymap = if n > 0 {
|
||||
let buf = Bytes::make(n, b'\x00')
|
||||
let got = mp_kms_keymap_copy(buf)
|
||||
buf[0:@cmp.maximum(got, 0)].to_owned()
|
||||
} else {
|
||||
b""
|
||||
}
|
||||
[
|
||||
Option(
|
||||
Some(
|
||||
Record([
|
||||
("width", U32(mp_kms_width().reinterpret_as_uint())),
|
||||
("height", U32(mp_kms_height().reinterpret_as_uint())),
|
||||
("keymap", @wt.Val::bytes(keymap)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]
|
||||
},
|
||||
),
|
||||
(
|
||||
"poll",
|
||||
_ => {
|
||||
mp_kms_poll() |> ignore
|
||||
boolean(mp_kms_quit_requested() == 0)
|
||||
},
|
||||
),
|
||||
("frame-ready", _ => boolean(mp_kms_frame_ready() != 0)),
|
||||
(
|
||||
"present",
|
||||
a => {
|
||||
let px = a[0].to_bytes()
|
||||
let w = a[1].to_int()
|
||||
let h = a[2].to_int()
|
||||
if px.length() >= w * h * 4 {
|
||||
mp_kms_present(px, w, h) |> ignore
|
||||
}
|
||||
none
|
||||
},
|
||||
),
|
||||
(
|
||||
"present-frame",
|
||||
_ => {
|
||||
rs_present_kms()
|
||||
none
|
||||
},
|
||||
),
|
||||
(
|
||||
"set-cursor-shape",
|
||||
a => {
|
||||
mp_kms_set_cursor_shape(a[0].to_int())
|
||||
none
|
||||
},
|
||||
),
|
||||
(
|
||||
"set-power",
|
||||
a => {
|
||||
mp_kms_set_power(if a[0].to_bool() { 1 } else { 0 })
|
||||
none
|
||||
},
|
||||
),
|
||||
("take-input", _ => [List(take_input())]),
|
||||
(
|
||||
"close",
|
||||
_ => {
|
||||
mp_kms_close()
|
||||
none
|
||||
},
|
||||
),
|
||||
]
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
"chandra/desktop/compositor/font" @font,
|
||||
"chandra/desktop/compositor/renderer" @renderer,
|
||||
"chandra/desktop/compositor/wasm" @wasm,
|
||||
"chandra/desktop/compositor/kms" @kms,
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/wasmhost/wt" @wt,
|
||||
@@ -17,12 +18,15 @@ supported_targets = "-all+native"
|
||||
pkgtype(kind: "executable")
|
||||
|
||||
// libwasmtime comes prebuilt (scripts/setup-toolchain.sh); scripts/build-wasmhost.sh puts it on
|
||||
// the compiler's and linker's search paths. Linked statically: the binary needs nothing at runtime.
|
||||
// the compiler's and linker's search paths, and links it statically. The DRM/KMS backend's system
|
||||
// libraries are linked as usual; libseat may come from the pixi env (pixi.toml), so build/wasmhost
|
||||
// looks for it there too (the rpath is relative to build/), not through LD_LIBRARY_PATH, which
|
||||
// apps started by the compositor would inherit.
|
||||
options(
|
||||
"native-stub": [ "host_stub.c", "raster_stub.c" ],
|
||||
link: {
|
||||
"native": {
|
||||
"cc-link-flags": "-l:libwasmtime.a -lpthread -ldl -lm",
|
||||
"cc-link-flags": "-l:libwasmtime.a -lpthread -ldl -lm -ldrm -linput -lseat -lxkbcommon -ludev -Wl,-rpath,$ORIGIN/../.pixi/envs/default/lib",
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -598,3 +598,10 @@ int32_t rs_export_memfd(void) {
|
||||
free(data);
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* compositor/kms/kms_stub.c: show an RGBA8888 frame on the login session's output. */
|
||||
int32_t mp_kms_present(moonbit_bytes_t pixels, int32_t w, int32_t h);
|
||||
|
||||
void rs_present_kms(void) {
|
||||
if (fb) mp_kms_present((moonbit_bytes_t)fb, fb_w, fb_h);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
///| Interfaces not served yet (filled in stage by stage).
|
||||
|
||||
///|
|
||||
fn display_wait_fds() -> Array[Int] {
|
||||
[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
///|
|
||||
fn display_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
|
||||
[
|
||||
("open", _ => [Option(None)]),
|
||||
("poll", _ => [Bool(false)]),
|
||||
("frame-ready", _ => [Bool(false)]),
|
||||
("present", _ => none),
|
||||
("present-frame", _ => none),
|
||||
("set-cursor-shape", _ => none),
|
||||
("take-input", _ => [List([])]),
|
||||
("close", _ => none),
|
||||
]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user