Files
chandra/compositor/kms/kms_native.mbt
T
VandClaude Opus 5.5 af774d76fe
CI / test (push) Failing after 16s
Rename the project to Chandra
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
2026-11-25 17:12:57 +00:00

135 lines
3.7 KiB
MoonBit

///| Native display backend for running chandra as a login session: DRM/KMS
/// output (dumb buffers, page flips, hardware cursor), libinput keyboard and
/// pointer, xkbcommon keymap, libseat for device access and VT switching.
/// All state lives in the C shim (kms_stub.c); this wrapper exposes it with the
/// same shape as `@nested.NestedWindow` so the main loop can drive either.
///|
extern "C" fn c_open() -> Int = "mp_kms_open"
///|
extern "C" fn c_width() -> Int = "mp_kms_width"
///|
extern "C" fn c_height() -> Int = "mp_kms_height"
///|
extern "C" fn c_quit_requested() -> Int = "mp_kms_quit_requested"
///|
extern "C" fn c_poll() -> Int = "mp_kms_poll"
///|
extern "C" fn c_frame_ready() -> Int = "mp_kms_frame_ready"
///|
extern "C" fn c_present(pixels : FixedArray[Byte], w : Int, h : Int) -> Int = "mp_kms_present"
///|
extern "C" fn c_set_cursor_shape(shape : Int) = "mp_kms_set_cursor_shape"
///|
extern "C" fn c_next_event() -> Int = "mp_kms_next_event"
///|
extern "C" fn c_arg(i : Int) -> Int = "mp_kms_arg"
///|
extern "C" fn c_keymap_len() -> Int = "mp_kms_keymap_len"
///|
extern "C" fn c_keymap_copy(out : FixedArray[Byte]) -> Int = "mp_kms_keymap_copy"
///|
extern "C" fn c_close() = "mp_kms_close"
///|
pub(all) struct Kms {
width : Int
height : Int
keymap : Bytes
}
///| Open the seat, the first connected DRM output and libinput. Returns None
/// (after printing why to stderr) when not running on an active login VT.
pub fn Kms::open() -> Kms? {
if c_open() != 0 {
c_close()
return None
}
let n = c_keymap_len()
let buf : FixedArray[Byte] = FixedArray::make(n, b'\x00')
let got = if n > 0 { c_keymap_copy(buf) } else { 0 }
let keymap = Bytes::from_fixedarray(buf, len=got)
Some({ width: c_width(), height: c_height(), keymap })
}
///| Service the seat, DRM and input fds. False once Ctrl+Alt+Backspace was pressed.
pub fn Kms::poll(_self : Kms) -> Bool {
ignore(c_poll())
c_quit_requested() == 0
}
///| True when a new frame can be presented (seat active, no page flip in flight).
pub fn Kms::frame_ready(_self : Kms) -> Bool {
c_frame_ready() != 0
}
///| Present a composed frame (its size must match the output mode).
pub fn Kms::present(_self : Kms, pixmap : @renderer.Pixmap) -> Unit {
ignore(c_present(pixmap.data, pixmap.width, pixmap.height))
}
///| Show the cursor for a wp_cursor_shape_v1 value.
pub fn Kms::set_cursor_shape(_self : Kms, shape : UInt) -> Unit {
c_set_cursor_shape(shape.reinterpret_as_int())
}
///| Input queued since the last call, in the compositor's event type.
pub fn Kms::take_input(_self : Kms) -> Array[@nested.InputEvent] {
let out : Array[@nested.InputEvent] = []
while true {
let t = c_next_event()
if t == 0 {
break
}
let a = c_arg(1)
let b = c_arg(2)
match t {
1 => out.push(PointerMove(a.to_double(), b.to_double()))
2 => out.push(PointerButton(a.reinterpret_as_uint(), b != 0))
3 => out.push(Key(a.reinterpret_as_uint(), b != 0))
4 =>
out.push(
Modifiers(
a.reinterpret_as_uint(),
b.reinterpret_as_uint(),
c_arg(3).reinterpret_as_uint(),
c_arg(4).reinterpret_as_uint(),
),
)
5 =>
out.push(
Scroll(
a.reinterpret_as_uint(),
b.to_double() / 256.0,
c_arg(3),
),
)
_ => ()
}
}
out
}
///| Restore the previous video mode and release the seat.
pub fn Kms::close(_self : Kms) -> Unit {
c_close()
}
///| The native build draws with the software renderer and uses `present`; there is no host
/// framebuffer to show.
pub fn Kms::present_frame(_self : Kms) -> Unit {
abort("present_frame is only available to the wasm compositor")
}