Wasm panel modules, widget host, merged plasmoid host design, and shell/UI work

Panel and wasm host
- The panel is built from wasm plasmoid modules (compositor/wasm: wasmer-backed host).
  Modules get capabilities by importing host interfaces; the host publishes data tables
  and serves a request queue (launch, focus window, set layout, inspector, load/unload
  modules). New WIT: windows, layout-control, inspector, modules, system.
- Merged two competing host designs: generic tables + requests are the base; the
  `system` snapshot and the id-stable `windows.all/focus` (Desktop Pulse) run on top of it.
- Panel widgets: load a .wasm from a path or file chooser, reorder by dragging,
  right-click replace/remove/add, saved to panel.edn.
- Desktop widget, system sampler (sysinfo), app catalog/humanised names, Interface
  Explorer (inspector), real font rendering (compositor/font, assets/fonts).

Compositor
- Drag the divider between tiled windows; lower tiled rows leave room for the title bar.
- Title-bar buttons, 12-hour clock, truncated titles, task-list/layout menus.
- DRM/KMS session, tcc debug builds (vendored tinycc incl. conftest.c), justfile
  recipes (modules, run, test), pixi.toml.

Known gaps
- The sources for the pulse, tasks, layout, inspector, module-manager, moon-* and
  clock-digital12 modules are not in the tree yet, so `just modules` stops at pulse and
  the host tests that load those modules fail until they land.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-24 23:38:05 -08:00
1 parent 080377fd79
commit 0145981c6a
57 files changed
+11461 -221

No files matched your search

+272 -25
View File
@@ -10,6 +10,8 @@ pub(all) struct HostWindow {
mut maximized : Bool
mut fullscreen : Bool
mut surface : @scene.ShmBufferSnapshot?
/// A size change still to be sent to the client (coalesced while dragging a divider).
mut cfg_dirty : Bool
}
///|
@@ -32,6 +34,8 @@ pub(all) struct MoonPlasmaCompositor {
mut press_fwd : Bool
mut kbd_win : UInt64?
mut mods : UInt
/// A Super key is down and nothing else was pressed since: releasing it opens the launcher.
mut super_solo : Bool
mut layout_mode : @wm.LayoutMode
}
@@ -42,6 +46,7 @@ pub fn MoonPlasmaCompositor::new(
output_w : Int,
output_h : Int,
) -> MoonPlasmaCompositor? {
ignore(@font.install()) // Adwaita Mono; keeps the bitmap font if it's missing
let server = match @wayland.WaylandServer::listen(socket_path, output_w, output_h) {
Some(s) => s
None => return None
@@ -58,6 +63,8 @@ pub fn MoonPlasmaCompositor::new(
excl_top=32, // room for the server-side title bar drawn above each client
excl_bottom=theme.panel_height,
)
let shell = @shell.DesktopShell::new(socket_path)
shell.set_output(theme, output_w, output_h)
Some({
server,
wm,
@@ -67,7 +74,7 @@ pub fn MoonPlasmaCompositor::new(
work_area,
windows: {},
damage: @scene.DamageTracker::new(),
shell: @shell.DesktopShell::new(socket_path),
shell,
ptr_x: 0.0,
ptr_y: 0.0,
ptr_win: None,
@@ -75,12 +82,14 @@ pub fn MoonPlasmaCompositor::new(
press_fwd: false,
kbd_win: None,
mods: 0U,
super_solo: false,
layout_mode: @wm.LayoutMode::Tiling,
})
}
///|
pub fn MoonPlasmaCompositor::close(self : MoonPlasmaCompositor) -> Unit {
self.shell.shutdown()
self.server.close()
}
@@ -95,14 +104,20 @@ fn MoonPlasmaCompositor::apply_actions(
match self.windows.get(wid) {
Some(win) => {
win.geometry = @scene.Rect::new(r.x, r.y, r.w, r.h)
self.server.send_toplevel_configure(
wid,
r.w,
r.h,
win.focused,
win.maximized,
win.fullscreen,
)
if self.split_drag is Some(_) {
// Dragging: send one configure per frame, not one per mouse event.
win.cfg_dirty = true
} else {
win.cfg_dirty = false
self.server.send_toplevel_configure(
wid,
r.w,
r.h,
win.focused,
win.maximized,
win.fullscreen,
)
}
self.damage.mark_full()
}
None => ()
@@ -130,8 +145,26 @@ fn MoonPlasmaCompositor::apply_actions(
}
}
///| Send the size changes coalesced during a divider drag.
fn MoonPlasmaCompositor::flush_configures(self : MoonPlasmaCompositor) -> Unit {
for wid, win in self.windows {
if win.cfg_dirty {
win.cfg_dirty = false
self.server.send_toplevel_configure(
wid,
win.geometry.w,
win.geometry.h,
win.focused,
win.maximized,
win.fullscreen,
)
}
}
}
///|
pub fn MoonPlasmaCompositor::step(self : MoonPlasmaCompositor) -> Unit {
self.flush_configures()
let events = self.server.poll_events()
for ev in events {
match ev {
@@ -145,6 +178,7 @@ pub fn MoonPlasmaCompositor::step(self : MoonPlasmaCompositor) -> Unit {
maximized: false,
fullscreen: false,
surface: None,
cfg_dirty: false,
}
self.windows.set(wid, win)
let rec : @wm.WindowRecord = {
@@ -250,15 +284,13 @@ pub fn MoonPlasmaCompositor::set_layout_mode(
pub fn MoonPlasmaCompositor::compose_frame(
self : MoonPlasmaCompositor,
) -> @renderer.Pixmap {
self.flush_configures()
let scene = @scene.SceneGraph::new(self.output_w, self.output_h)
let order = self.wm.stacking_order()
let titles : Array[String] = []
for wid in order {
match self.windows.get(wid) {
Some(win) => {
let label = if win.title.length() > 0 { win.title } else { win.app_id }
titles.push(label)
let (insets, deco_ops) = @scene.build_breeze_decoration(
win.title,
win.app_id,
@@ -284,18 +316,51 @@ pub fn MoonPlasmaCompositor::compose_frame(
}
}
let layout_label = match self.layout_mode {
@wm.LayoutMode::Tiling => "BSP Tiling"
@wm.LayoutMode::Floating => "Floating"
@wm.LayoutMode::Monocle => "Monocle"
self.shell.layout_sel = match self.layout_mode {
@wm.LayoutMode::Tiling => 0
@wm.LayoutMode::Monocle => 1
@wm.LayoutMode::Floating => 2
}
let (bg_ops, panel_ops) = self.shell.render(
self.output_w,
self.output_h,
self.theme,
layout_label,
titles,
)
// The task list shows every window, minimized ones too (so they can be restored).
let wins : Array[@shell.WinInfo] = []
for wid in order {
match self.windows.get(wid) {
Some(win) =>
wins.push({
id: win.id,
title: if win.title.length() > 0 { win.title } else { win.app_id },
focused: win.focused,
minimized: false,
})
None => ()
}
}
for id, r in self.wm.windows {
if r.minimized {
match self.windows.get(id) {
Some(win) =>
wins.push({
id,
title: if win.title.length() > 0 { win.title } else { win.app_id },
focused: false,
minimized: true,
})
None => ()
}
}
}
self.shell.windows = wins
// The window list the `windows` interface serves to wasm widgets (task-bar order).
let entries : Array[@wasm.WindowEntry] = []
for w in wins {
match self.windows.get(w.id) {
Some(win) => entries.push({ id: w.id, title: w.title, app_id: win.app_id, focused: w.focused })
None => ()
}
}
self.shell.win_list = entries
let (bg_ops, panel_ops) = self.shell.render(self.output_w, self.output_h, self.theme)
self.run_shell_actions()
scene.background_ops = bg_ops
scene.panel_ops = panel_ops
ignore(self.damage.take_damage(self.output_w, self.output_h))
@@ -390,6 +455,104 @@ fn MoonPlasmaCompositor::window_at(self : MoonPlasmaCompositor, x : Int, y : Int
None
}
///| Title-bar button under (x, y) for window `wid`: 1 minimize, 2 maximize, 3 close, 0 none.
/// Mirrors the layout in `build_breeze_decoration` (18px buttons, 8px apart, 10px from the right edge).
fn MoonPlasmaCompositor::title_button_at(
self : MoonPlasmaCompositor,
wid : UInt64,
x : Int,
y : Int,
) -> Int {
match self.windows.get(wid) {
None => 0
Some(win) => {
let g = win.geometry
let outer_w = g.w + 4
let lx = x - (g.x - 2)
let ly = y - (g.y - 32)
let size = 18
let by = (32 - size) / 2
if ly < by - 3 || ly >= by + size + 3 {
return 0
}
let close_x = outer_w - 10 - size
let max_x = close_x - 8 - size
let min_x = max_x - 8 - size
if lx >= close_x - 3 && lx < close_x + size + 3 {
3
} else if lx >= max_x - 3 && lx < max_x + size + 3 {
2
} else if lx >= min_x - 3 && lx < min_x + size + 3 {
1
} else {
0
}
}
}
}
///| Activate the title-bar button `btn` of window `wid`.
fn MoonPlasmaCompositor::press_title_button(
self : MoonPlasmaCompositor,
wid : UInt64,
btn : Int,
) -> Unit {
self.leave_pointer()
let req = match btn {
1 => @wm.WindowRequest::Minimize(true)
2 => {
let maxed = match self.wm.windows.get(wid) {
Some(r) => r.maximized
None => false
}
@wm.WindowRequest::Maximize(!maxed)
}
_ => @wm.WindowRequest::Close
}
self.apply_actions(self.wm.handle_request(wid, req, self.work_area))
if btn == 1 {
// Hand focus to the top-most remaining window.
let order = self.wm.stacking_order()
if order.length() > 0 {
let top = order[order.length() - 1]
self.apply_actions([@wm.WmAction::Focus(top), @wm.WmAction::Raise(top)])
} else {
self.set_kbd_focus(None)
}
}
self.damage.mark_full()
}
///| Restore a minimized window (or focus a visible one) from its task-bar pill.
fn MoonPlasmaCompositor::activate_task(self : MoonPlasmaCompositor, wid : UInt64) -> Unit {
let minimized = match self.wm.windows.get(wid) {
Some(r) => r.minimized
None => return
}
if minimized {
self.apply_actions(
self.wm.handle_request(wid, @wm.WindowRequest::Minimize(false), self.work_area),
)
}
self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)])
}
///| Carry out what panel modules asked for: focus a window, switch layout.
fn MoonPlasmaCompositor::run_shell_actions(self : MoonPlasmaCompositor) -> Unit {
for a in self.shell.take_actions() {
match a {
@shell.ShellAction::FocusWindow(wid) => self.activate_task(wid)
@shell.ShellAction::SetLayout(m) =>
match m {
0 => self.set_layout_mode(@wm.LayoutMode::Tiling)
1 => self.set_layout_mode(@wm.LayoutMode::Monocle)
2 => self.set_layout_mode(@wm.LayoutMode::Floating)
_ => ()
}
}
}
}
///| Tiling divider under (x, y), with a few pixels of slack either side.
fn MoonPlasmaCompositor::handle_at(
self : MoonPlasmaCompositor,
@@ -467,6 +630,20 @@ pub fn MoonPlasmaCompositor::handle_input(
self.ptr_y = y
let xi = x.to_int()
let yi = y.to_int()
if self.shell.inspecting() {
self.leave_pointer()
let id = match self.shell.component_at(xi, yi) {
"" =>
match self.window_at(xi, yi) {
Some((_, true)) => "window-surface"
Some((_, false)) => "window-decoration"
None => "desktop"
}
sid => sid
}
self.shell.set_hover(id, xi, yi)
return
}
if self.shell.pointer_move(xi, yi) || self.shell.hit(xi, yi) {
self.leave_pointer()
return
@@ -482,6 +659,17 @@ pub fn MoonPlasmaCompositor::handle_input(
self.leave_pointer()
return
}
match self.split_drag {
Some(h) => {
self.apply_actions(self.wm.drag_split(h, xi, yi, self.work_area))
return
}
None => ()
}
if self.handle_at(xi, yi) is Some(_) {
self.leave_pointer()
return
}
match self.window_at(xi, yi) {
Some((wid, true)) =>
match self.windows.get(wid) {
@@ -500,17 +688,50 @@ pub fn MoonPlasmaCompositor::handle_input(
_ => self.leave_pointer()
}
}
Scroll(v) => {
// ~10 units per wheel notch -> 3 lines.
let lines = if v > 0.0 { (v / 10.0).to_int() + 1 } else { (v / 10.0).to_int() - 1 }
ignore(self.shell.scroll_inspector(lines))
}
PointerButton(button, pressed) => {
let xi = self.ptr_x.to_int()
let yi = self.ptr_y.to_int()
if !pressed && self.shell.pointer_up() {
self.run_shell_actions()
return
}
if !pressed && self.split_drag is Some(_) {
self.split_drag = None
return
}
// Right button over a swappable panel widget opens its alternatives menu.
if button == 273U && pressed && self.shell.right_click(xi, yi) {
return
}
if pressed {
if self.shell.pointer_down(xi, yi) {
self.super_solo = false
if button != 273U && self.shell.pointer_down(xi, yi) {
self.run_shell_actions()
return
}
match self.window_at(xi, yi) {
Some((wid, false)) => {
let btn = self.title_button_at(wid, xi, yi)
if btn != 0 {
self.press_title_button(wid, btn)
return
}
}
_ => ()
}
match self.handle_at(xi, yi) {
Some(h) => {
self.split_drag = Some(h)
self.leave_pointer()
return
}
None => ()
}
match self.handle_at(xi, yi) {
Some(h) => {
self.split_drag = Some(h)
@@ -542,7 +763,24 @@ pub fn MoonPlasmaCompositor::handle_input(
}
}
Key(code, pressed) =>
if self.shell.popup_open() {
if code == 125U || code == 126U {
// Super (left/right): a bare tap toggles the launcher search; never reaches clients.
if pressed {
self.super_solo = true
} else if self.super_solo {
self.super_solo = false
if !self.shell.inspecting() {
self.shell.toggle_launcher()
}
}
} else if self.shell.inspecting() {
self.super_solo = false
// Escape leaves inspect mode; other keys are not forwarded while inspecting.
if code == 1U && pressed {
self.shell.set_inspecting(false)
}
} else if self.shell.popup_open() {
self.super_solo = false
if pressed {
let name = key_name(code, (self.mods & 1U) != 0U)
if name.length() > 0 {
@@ -550,6 +788,7 @@ pub fn MoonPlasmaCompositor::handle_input(
}
}
} else {
self.super_solo = false
match self.kbd_win {
Some(w) => self.server.keyboard_key(w, time_ms, code, pressed)
None => ()
@@ -580,6 +819,14 @@ pub fn MoonPlasmaCompositor::desired_cursor(self : MoonPlasmaCompositor) -> UInt
Some(h) => return if h.horizontal { 26U } else { 27U } // ew-resize / ns-resize
None => ()
}
let handle = match self.split_drag {
Some(h) => Some(h)
None => self.handle_at(self.ptr_x.to_int(), self.ptr_y.to_int())
}
match handle {
Some(h) => return if h.horizontal { 26U } else { 27U } // ew-resize / ns-resize
None => ()
}
match self.ptr_win {
Some(w) => self.server.client_cursor_shape(w)
None => 1U
+400 -15
View File
@@ -1,5 +1,41 @@
///| Input routing: host pointer/keyboard events reach the focused client window,
/// and the launcher button opens the shell's launcher popup.
///| Input routing: host pointer/keyboard events reach the focused client window, and the
/// panel (made entirely of wasm modules) responds to the mouse and keyboard.
/// Needs the modules: run scripts/build-modules.sh (just test does).
///| Rectangle of the panel module `id` (file stem), as last drawn.
fn rect_of(comp : @host.MoonPlasmaCompositor, id : String) -> @scene.Rect {
comp.shell.slot_rect(comp.shell.slot_of(id))
}
///| Centre of the panel module `id`.
fn center_of(comp : @host.MoonPlasmaCompositor, id : String) -> (Double, Double) raise {
let r = rect_of(comp, id)
assert_true(r.w > 0)
((r.x + r.w / 2).to_double(), (r.y + r.h / 2).to_double())
}
///| Move to (x, y), press and release `btn`, then draw a frame.
fn click_at(comp : @host.MoonPlasmaCompositor, x : Int, y : Int, t : UInt, btn? : UInt = 272U) -> Unit {
comp.handle_input(@nested.InputEvent::PointerMove(x.to_double(), y.to_double()), t)
comp.handle_input(@nested.InputEvent::PointerButton(btn, true), t + 1U)
comp.handle_input(@nested.InputEvent::PointerButton(btn, false), t + 2U)
ignore(comp.compose_frame())
}
///| Click the centre of panel module `id`.
fn click_module(comp : @host.MoonPlasmaCompositor, id : String, t : UInt) -> Unit raise {
let (x, y) = center_of(comp, id)
click_at(comp, x.to_int(), y.to_int(), t)
}
///| A fresh compositor with the default panel and a first frame drawn.
fn new_comp(tag : String) -> @host.MoonPlasmaCompositor {
let socket_path = "/tmp/wayland-moon-" + tag + "-" + @sys.getpid().to_string() + ".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
ignore(comp.compose_frame())
comp
}
///| Drain everything the compositor sent this client as (object, opcode) pairs.
fn drain_msgs(c : TestWaylandClient) -> Array[(UInt, UInt)] {
@@ -37,6 +73,7 @@ fn has_msg(msgs : Array[(UInt, UInt)], obj : UInt, op : UInt) -> Bool {
msgs.iter().any(m => m.0 == obj && m.1 == op)
}
///|
test "host input reaches the focused client and the launcher popup opens" {
let socket_path = "/tmp/wayland-moon-input-" +
@@ -95,22 +132,16 @@ test "host input reaches the focused client and the launcher popup opens" {
}
assert_eq(comp.desired_cursor(), 9U)
// Launcher: click the button -> popup opens and swallows keys.
// Launcher module: click the button -> its popup opens and swallows keys.
ignore(comp.compose_frame()) // lays out the panel
comp.handle_input(@nested.InputEvent::PointerMove(60.0, 700.0), 20U)
assert_eq(comp.desired_cursor(), 4U) // ...but the launcher button always shows a hand
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 21U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 22U)
let (lx, ly) = center_of(comp, "launcher")
comp.handle_input(@nested.InputEvent::PointerMove(lx, ly), 20U)
assert_eq(comp.desired_cursor(), 4U) // ...but panel modules always show a hand
click_at(comp, lx.to_int(), ly.to_int(), 21U)
assert_true(comp.shell.popup_open())
assert_true(comp.shell.slot_popup_rect(comp.shell.slot_of("launcher")).w > 0)
comp.handle_input(@nested.InputEvent::Key(30U, true), 23U)
let after = drain_msgs(c)
assert_false(has_msg(after, kbd_id, 3U)) // swallowed by the launcher
// Typing fills the search field: evdev 20 = t, 18 = e (key 30 = a was typed above).
comp.handle_input(@nested.InputEvent::Key(20U, true), 26U)
comp.handle_input(@nested.InputEvent::Key(18U, true), 27U)
assert_eq(comp.shell.launcher_state.query, "ate")
comp.handle_input(@nested.InputEvent::Key(14U, true), 28U)
assert_eq(comp.shell.launcher_state.query, "at")
assert_false(has_msg(drain_msgs(c), kbd_id, 3U)) // swallowed by the launcher
// Off the shell and off any window: default arrow.
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 25U)
assert_eq(comp.desired_cursor(), 1U)
@@ -146,3 +177,357 @@ test "dragging the divider between two tiled windows resizes them" {
assert_true(right2.w > right.w + 200)
assert_true(right2.x > left2.x + left2.w)
}
///|
test "the layout module opens a popup to pick Tiling, Monocle or Floating" {
let socket_path = "/tmp/wayland-moon-layout-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let _a = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
ignore(comp.compose_frame())
let slot = comp.shell.slot_of("layout")
let (cx, cy) = center_of(comp, "layout")
comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 1U)
assert_eq(comp.desired_cursor(), 4U) // it is a button: hand cursor
// Pick row `i` from the popup the button opens.
let pick = fn(i : Int, t : UInt) raise {
click_at(comp, cx.to_int(), cy.to_int(), t) // open
let pr = comp.shell.slot_popup_rect(slot)
assert_true(pr.w > 0)
click_at(comp, pr.x + pr.w / 2, pr.y + 4 + i * 28 + 14, t + 3U)
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
}
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
let tiled_w = comp.windows.get(1UL).unwrap().geometry.w
// Opening alone changes nothing.
click_at(comp, cx.to_int(), cy.to_int(), 2U)
assert_true(comp.shell.slot_popup_rect(slot).w > 0)
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
// Escape closes without picking.
comp.handle_input(@nested.InputEvent::Key(1U, true), 3U)
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
pick(1, 10U)
assert_eq(comp.layout_mode, @wm.LayoutMode::Monocle)
assert_true(comp.windows.get(1UL).unwrap().geometry.w > tiled_w + 100)
pick(2, 20U)
assert_eq(comp.layout_mode, @wm.LayoutMode::Floating)
pick(0, 30U)
assert_eq(comp.layout_mode, @wm.LayoutMode::Tiling)
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, tiled_w)
}
///|
test "title-bar buttons minimize, maximize and close windows" {
let socket_path = "/tmp/wayland-moon-btn-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let (c, _shm, _surf, _xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
ignore(comp.compose_frame())
// Button centres, from the decoration layout (18px buttons, 10px from the right edge).
let btn = fn(wid : UInt64, n : Int) {
let g = comp.windows.get(wid).unwrap().geometry
let outer_w = g.w + 4
let x = g.x - 2 + outer_w - 10 - 9 - (3 - n) * 26
let y = g.y - 32 + 16
(x, y)
}
let click = fn(p : (Int, Int), t : UInt) {
click_at(comp, p.0, p.1, t)
}
// Maximize window 1: it grows.
let w0 = comp.windows.get(1UL).unwrap().geometry.w
click(btn(1UL, 2), 1U)
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
click(btn(1UL, 2), 10U)
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
// Minimize window 1: it leaves the stacking order, then its pill in the task list restores it.
click(btn(1UL, 1), 20U)
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
assert_true(!comp.wm.stacking_order().contains(1UL))
let tasks = rect_of(comp, "tasks")
// pills: the visible window first, the minimized one second (140 wide, 6 apart)
click((tasks.x + 146 + 20, tasks.y + tasks.h / 2), 30U)
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
ignore(drain_msgs(c))
click(btn(1UL, 3), 40U)
for _i = 0; _i < 5; _i = _i + 1 {
comp.step()
@sys.sleep_ms(2)
}
assert_true(has_msg(drain_msgs(c), tl, 1U))
}
///|
test "the task list module focuses the window whose pill is clicked" {
let socket_path = "/tmp/wayland-moon-tasks-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let _a = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
ignore(comp.compose_frame())
let focused = fn() {
let mut f = 0UL
for id, w in comp.windows {
if w.focused {
f = id
}
}
f
}
let tasks = rect_of(comp, "tasks")
assert_true(tasks.w > 300) // the stretching module takes the free space
let first = comp.wm.stacking_order()[0]
click_at(comp, tasks.x + 20, tasks.y + tasks.h / 2, 1U) // pill 0
assert_eq(focused(), first)
let other = comp.wm.stacking_order()
click_at(comp, tasks.x + 146 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
assert_true(focused() != first || other.length() == 1)
}
///|
test "right-click a panel module to replace it in place, or remove it" {
let comp = new_comp("swap")
let before = comp.shell.slots()
let clock = rect_of(comp, "clock-digital12")
assert_true(clock.w > 0)
let find_row = fn(label : String) {
let mut i = -1
for k = 0; k < comp.shell.menu_rows.length(); k = k + 1 {
if comp.shell.menu_rows[k].label == label {
i = k
}
}
i
}
click_at(comp, clock.x + clock.w / 2, clock.y + clock.h / 2, 1U, btn=273U)
assert_true(comp.shell.menu_open)
let m = comp.shell.menu_rect
assert_true(m.w > 0 && m.y + m.h <= clock.y) // above the panel, not off-screen
let bin = find_row("Replace with Binary Clock")
assert_true(bin >= 0)
assert_true(find_row("Remove widget") >= 0)
assert_true(find_row("Module manager...") >= 0)
// Hover the row (hand cursor), click it: the binary clock takes the digital clock's place.
let ix = m.x + m.w / 2
let iy = m.y + 26 + 28 * bin + 14
comp.handle_input(@nested.InputEvent::PointerMove(ix.to_double(), iy.to_double()), 10U)
assert_eq(comp.desired_cursor(), 4U)
click_at(comp, ix, iy, 11U)
assert_true(!comp.shell.menu_open)
assert_eq(comp.shell.slot_of("clock-digital12"), "")
let after = comp.shell.slots()
assert_eq(after.length(), before.length())
assert_eq(after[after.length() - 1], comp.shell.slot_of("clock-binary")) // same place in the panel
assert_true(rect_of(comp, "clock-binary").w > 0)
// Escape dismisses the menu; "Remove widget" unloads the module.
let moon = rect_of(comp, "moon-disc")
click_at(comp, moon.x + moon.w / 2, moon.y + moon.h / 2, 20U, btn=273U)
assert_true(comp.shell.menu_open)
comp.handle_input(@nested.InputEvent::Key(1U, true), 30U)
assert_true(!comp.shell.menu_open)
click_at(comp, moon.x + moon.w / 2, moon.y + moon.h / 2, 40U, btn=273U)
let m2 = comp.shell.menu_rect
click_at(comp, m2.x + m2.w / 2, m2.y + 26 + 28 * find_row("Remove widget") + 14, 50U)
assert_eq(comp.shell.slot_of("moon-disc"), "")
assert_eq(comp.shell.slots().length(), before.length() - 1)
}
///|
test "tapping Super toggles the launcher; Super+key does not" {
let comp = new_comp("super")
let tap = fn(t : UInt) {
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 1U)
}
assert_false(comp.shell.popup_open())
tap(1U)
assert_true(comp.shell.popup_open())
tap(3U)
assert_false(comp.shell.popup_open())
// Super held while another key is pressed: not a tap.
comp.handle_input(@nested.InputEvent::Key(125U, true), 5U)
comp.handle_input(@nested.InputEvent::Key(30U, true), 6U)
comp.handle_input(@nested.InputEvent::Key(30U, false), 7U)
comp.handle_input(@nested.InputEvent::Key(125U, false), 8U)
assert_false(comp.shell.popup_open())
}
///|
test "the panel is saved to panel.edn and restored" {
// Never touch the user's real config: only run when a scratch dir is provided.
if @sys.getenv("MOON_PLASMA_TEST_CONFIG") == "1" {
let theme = @scene.ThemeTokens::moon_night()
let a = @shell.DesktopShell::new("x")
a.persist = true
a.set_output(theme, 1280, 720)
assert_true(a.unload_slot(a.slot_of("moon-disc")))
assert_true(a.load_module("clock-binary"))
let b = @shell.DesktopShell::new("x")
b.persist = true
b.set_output(theme, 1280, 720)
assert_eq(b.slot_of("moon-disc"), "")
assert_true(b.slot_of("clock-binary") != "")
assert_eq(b.slots().length(), a.slots().length())
}
}
///|
test "the wasm picker opens the module manager, which loads and unloads modules" {
let comp = new_comp("manager")
// The manager is not in the default panel: the picker loads it on demand.
assert_eq(comp.shell.slot_of("module-manager"), "")
let n0 = comp.shell.slots().length()
// Right-click empty panel space (the margin): the menu offers the module manager.
let panel = comp.shell.panel_rect
click_at(comp, 1, panel.y + 5, 1U, btn=273U)
assert_true(comp.shell.menu_open)
assert_eq(comp.shell.menu_rows[0].label, "Module manager...")
let m = comp.shell.menu_rect
click_at(comp, m.x + m.w / 2, m.y + 26 + 14, 10U)
assert_eq(comp.shell.slots().length(), n0 + 1)
let mgr = comp.shell.slot_of("module-manager")
assert_true(mgr != "")
ignore(comp.compose_frame())
let pr = comp.shell.slot_popup_rect(mgr)
assert_true(pr.w > 0) // the picker opened the app's popup
// Rows: header(24), one per loaded module (28), header(24), one per available module (28), browse.
let loaded = comp.shell.slots().length()
let avail_y = fn(k : Int) { pr.y + 4 + 24 + loaded * 28 + 24 + k * 28 + 14 }
let mut k_bin = -1
for k = 0; k < comp.shell.catalog.length(); k = k + 1 {
if comp.shell.catalog[k].id == "clock-binary" {
k_bin = k
}
}
assert_true(k_bin >= 0)
assert_eq(comp.shell.slot_of("clock-binary"), "")
click_at(comp, pr.x + 40, avail_y(k_bin), 20U) // select it: it is loaded into the panel
assert_true(comp.shell.slot_of("clock-binary") != "")
assert_eq(comp.shell.slots().length(), loaded + 1)
// The popup stays open; click the loaded module's row to unload it again.
let pr2 = comp.shell.slot_popup_rect(mgr)
assert_true(pr2.w > 0)
let slots = comp.shell.slots()
let mut idx = -1
for i = 0; i < slots.length(); i = i + 1 {
if slots[i] == comp.shell.slot_of("clock-binary") {
idx = i
}
}
click_at(comp, pr2.x + 40, pr2.y + 4 + 24 + idx * 28 + 14, 30U)
assert_eq(comp.shell.slot_of("clock-binary"), "")
assert_eq(comp.shell.slots().length(), loaded)
// The manager is just another module: it can be removed too, and the picker brings it back.
assert_true(comp.shell.unload_slot(mgr))
assert_eq(comp.shell.slot_of("module-manager"), "")
assert_true(comp.shell.open_module_manager())
assert_true(comp.shell.slot_of("module-manager") != "")
}
///|
test "dragging a panel module reorders it" {
let comp = new_comp("wdrag")
let order0 = comp.shell.slots()
let moon = rect_of(comp, "moon-disc")
let clock = rect_of(comp, "clock-digital12")
assert_true(moon.x < clock.x)
let cy = (clock.y + clock.h / 2).to_double()
comp.handle_input(@nested.InputEvent::PointerMove((clock.x + clock.w / 2).to_double(), cy), 1U)
assert_eq(comp.desired_cursor(), 4U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 2U)
// Drag the clock left past the moon.
comp.handle_input(@nested.InputEvent::PointerMove((moon.x + 2).to_double(), cy), 3U)
assert_eq(comp.desired_cursor(), 17U)
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 4U)
ignore(comp.compose_frame())
let order1 = comp.shell.slots()
assert_eq(order1.length(), order0.length())
assert_true(order1 != order0)
assert_eq(order1[order1.length() - 2], comp.shell.slot_of("clock-digital12"))
assert_true(rect_of(comp, "clock-digital12").x < rect_of(comp, "moon-disc").x)
assert_true(comp.desired_cursor() != 17U)
}
///|
test "any .wasm plasmoid can be loaded from a path and unloaded again" {
let comp = new_comp("path")
let n0 = comp.shell.slots().length()
let theme = @scene.ThemeTokens::moon_night()
ignore(theme)
assert_true(comp.shell.load_path("compositor/wasm/testdata/clock-digital.component.wasm") is Some(_))
assert_eq(comp.shell.slots().length(), n0 + 1)
ignore(comp.compose_frame())
let slot = comp.shell.slots()[n0]
assert_true(comp.shell.slot_rect(slot).w > 0) // it got a panel placement and was drawn
assert_true(comp.shell.load_path("compositor/wasm/testdata/missing.wasm") is None)
assert_eq(comp.shell.slots().length(), n0 + 1)
// It unloads like any module.
assert_true(comp.shell.unload_slot(slot))
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_rect(slot).w, 0)
}
///|
test "modules are added until the panel is full" {
let comp = new_comp("full")
let n0 = comp.shell.slots().length()
let mut added = 0
for _i = 0; _i < 40; _i = _i + 1 {
if comp.shell.load_module("moon-disc") {
added = added + 1
}
}
assert_true(added > 2 && added < 40)
assert_eq(comp.shell.slots().length(), n0 + added)
ignore(comp.compose_frame())
assert_true(rect_of(comp, "moon-disc").w > 0)
}
///|
test "Desktop Pulse reads live machine and window state through its granted interfaces and can raise a window" {
let socket_path = "/tmp/wayland-moon-pulse-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let _a = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
ignore(comp.compose_frame())
let n0 = comp.shell.slots().length()
assert_true(comp.shell.load_path("compositor/wasm/testdata/pulse.component.wasm") is Some(_))
// Its capability grant is exactly what the component imports; nothing else is reachable.
let slot = comp.shell.slots()[n0]
let w = comp.shell.widgets[n0]
assert_eq(w.slot, slot)
assert_eq(w.caps.length(), 3)
assert_true(w.caps.contains("system") && w.caps.contains("theme") && w.caps.contains("windows"))
ignore(comp.compose_frame())
// The host provider fed it real numbers and the window list.
assert_true(comp.shell.sampler.cur.mem_total_kib > 0L)
assert_true(comp.shell.sampler.cur.uptime_secs > 0L)
assert_eq(comp.shell.win_list.length(), 2)
let r = comp.shell.slot_rect(slot)
assert_true(r.w >= 300)
// Clicking each window's chip raises that window (first chip starts at x = 280).
for i = 0; i < 2; i = i + 1 {
let id = comp.shell.win_list[i].id
let cx = r.x + 280 + i * 23 + 10
let cy = r.y + r.h / 2
comp.handle_input(@nested.InputEvent::PointerMove(cx.to_double(), cy.to_double()), (10 + i * 4).reinterpret_as_uint())
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), (11 + i * 4).reinterpret_as_uint())
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), (12 + i * 4).reinterpret_as_uint())
ignore(comp.compose_frame())
assert_true(comp.windows.get(id).unwrap().focused)
let others_focused = comp.windows.iter().filter(kv => kv.0 != id && kv.1.focused).count()
assert_eq(others_focused, 0)
}
}
+58
View File
@@ -0,0 +1,58 @@
///| Interface Explorer: toggle from the panel, hover components, see their WIT.
///|
test "inspector shows the WIT interface of the hovered component" {
let socket_path = "/tmp/wayland-moon-inspect-" +
@sys.getpid().to_string() +
".sock"
let theme = @scene.ThemeTokens::moon_night()
let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap()
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(
comp, socket_path, "T", "t",
)
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
ignore(comp.compose_frame()) // lays out the panel
assert_false(comp.shell.inspecting())
// Open the apps popup first; turning the explorer on must not close it.
let (lx, ly) = center_of(comp, "launcher")
click_at(comp, lx.to_int(), ly.to_int(), 0U)
assert_true(comp.shell.popup_open())
// Click the Interface Explorer button to turn inspect mode on.
let (bx, by) = center_of(comp, "inspector")
click_at(comp, bx.to_int(), by.to_int(), 1U)
assert_true(comp.shell.inspecting())
assert_true(comp.shell.popup_open())
assert_eq(comp.desired_cursor(), 4U)
// Hover the launcher.
let (lx, ly) = center_of(comp, "launcher")
comp.handle_input(@nested.InputEvent::PointerMove(lx, ly), 4U)
let lslot = comp.shell.slot_of("launcher")
assert_eq(comp.shell.hover_id, lslot)
assert_eq(comp.desired_cursor(), 3U)
// The explorer describes the module's real binary: what it exports and which capabilities it imports.
let lines = comp.shell.inspector_lines_for(lslot)
assert_true(lines.iter().any(l => l.has_prefix("# plasmoid")))
assert_true(lines.iter().any(l => l.has_prefix("# app launch")))
assert_true(lines.iter().any(l => l.has_prefix("# app catalog")))
let frame = comp.compose_frame()
let png = @renderer.encode_png(frame)
ignore(@sys.write_file_bytes("_build/inspector_launcher.png", png))
// Clock, panel, window title bar and desktop resolve to their own components.
let (cx, cy) = center_of(comp, "clock-digital12")
comp.handle_input(@nested.InputEvent::PointerMove(cx, cy), 5U)
assert_eq(comp.shell.hover_id, comp.shell.slot_of("clock-digital12"))
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 6U)
assert_eq(comp.shell.hover_id, "desktop")
// Clicks are swallowed while inspecting; Escape leaves the mode.
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 7U)
assert_true(comp.shell.popup_open()) // unchanged: the click was swallowed
comp.handle_input(@nested.InputEvent::Key(1U, true), 8U)
assert_false(comp.shell.inspecting())
comp.close()
}
+10
View File
@@ -4,10 +4,20 @@ import {
"moonplasma/desktop/compositor/sys" @sys,
"moonplasma/desktop/compositor/scene" @scene,
"moonplasma/desktop/compositor/shell" @shell,
"moonplasma/desktop/compositor/wasm" @wasm,
"moonplasma/desktop/compositor/nested" @nested,
"moonplasma/desktop/compositor/font" @font,
"moonplasma/desktop/compositor/renderer" @renderer,
"moonplasma/desktop/compositor/wayland" @wayland,
"moonplasma/desktop/compositor/gfx" @gfx,
}
supported_targets = "-all+native"
options(
link: {
"native": {
"cc-link-flags": "-lwasmer",
},
},
)