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
This commit is contained in:
323 files changed
+1055
-1013
No files matched your search
+24
-24
@@ -1,7 +1,7 @@
|
||||
# `moon-plasma` Compositor & Window Manager Architecture
|
||||
# `chandra` Compositor & Window Manager Architecture
|
||||
|
||||
> **Target repository:** [experiments/moon-plasma](https://git.site.latha.org/experiments/moon-plasma)
|
||||
> **Scope:** Architectural design for evolving `moon-plasma` from its M0 JS/Canvas2D proof-of-concept into a native Wayland compositor and hot-swappable Window Manager (M3–M8), preserving its core invariant: **every policy is a sandboxed MoonBit WebAssembly component; the host only owns mechanism, devices, and scanout.**
|
||||
> **Scope:** Architectural design for evolving `chandra` from its M0 JS/Canvas2D proof-of-concept into a native Wayland compositor and hot-swappable Window Manager (M3–M8), preserving its core invariant: **every policy is a sandboxed MoonBit WebAssembly component; the host only owns mechanism, devices, and scanout.**
|
||||
|
||||
---
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
Traditional Wayland compositors (KWin, Sway, Mutter) bundle device management, Wayland protocol state, GPU compositing, window management policy, decorations, and shell UI into a single privileged process. A crash or logic bug in a decoration or tiling script can bring down the entire display server.
|
||||
|
||||
`moon-plasma` inverts this by splitting the compositor along a **typed WebAssembly Component Model (WIT) boundary**:
|
||||
`chandra` inverts this by splitting the compositor along a **typed WebAssembly Component Model (WIT) boundary**:
|
||||
|
||||
| Layer | Responsibility | Implementation | Trust Level |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
@@ -81,14 +81,14 @@ In M0 (`host/src/desktop.mjs`), the host hardcodes hit-testing. In the composito
|
||||
|
||||
## 3. WIT Interface Design (`wit/` Extensions)
|
||||
|
||||
Building on `moonplasma:desktop@0.1.0` (`wit/types.wit`, `wit/plasmoid.wit`, `wit/shell.wit`), the compositor introduces two new domain packages (per `docs/ARCHITECTURE.md` §7 versioning rules) while remaining compatible with `wit-bindgen moonbit` 0.63.0 (`--encoding utf16`).
|
||||
Building on `chandra:desktop@0.1.0` (`wit/types.wit`, `wit/plasmoid.wit`, `wit/shell.wit`), the compositor introduces two new domain packages (per `docs/ARCHITECTURE.md` §7 versioning rules) while remaining compatible with `wit-bindgen moonbit` 0.63.0 (`--encoding utf16`).
|
||||
|
||||
### 3.1 `moonplasma:compositor/surface@0.2.0`
|
||||
### 3.1 `chandra:compositor/surface@0.2.0`
|
||||
```wit
|
||||
package moonplasma:compositor@0.2.0;
|
||||
package chandra:compositor@0.2.0;
|
||||
|
||||
interface surface {
|
||||
use moonplasma:desktop/types@0.1.0.{size, rect};
|
||||
use chandra:desktop/types@0.1.0.{size, rect};
|
||||
|
||||
/// Unforgeable host handle to a committed client buffer (SHM or DMA-BUF).
|
||||
/// Components cannot read pixels; they can only inspect metadata and
|
||||
@@ -102,7 +102,7 @@ interface surface {
|
||||
|
||||
/// Extended render-list op for compositing foreign surfaces & cached layers.
|
||||
variant composite-op {
|
||||
draw(moonplasma:desktop/types@0.1.0.draw-op),
|
||||
draw(chandra:desktop/types@0.1.0.draw-op),
|
||||
draw-surface(surface-draw),
|
||||
push-opacity(u8),
|
||||
pop-opacity,
|
||||
@@ -117,13 +117,13 @@ interface surface {
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 `moonplasma:wm/policy@0.2.0`
|
||||
### 3.2 `chandra:wm/policy@0.2.0`
|
||||
```wit
|
||||
package moonplasma:wm@0.2.0;
|
||||
package chandra:wm@0.2.0;
|
||||
|
||||
interface policy {
|
||||
use moonplasma:desktop/types@0.1.0.{rect, size, point, input-event};
|
||||
use moonplasma:compositor/surface@0.2.0.{buffer-surface, composite-op};
|
||||
use chandra:desktop/types@0.1.0.{rect, size, point, input-event};
|
||||
use chandra:compositor/surface@0.2.0.{buffer-surface, composite-op};
|
||||
|
||||
type window-id = u64;
|
||||
|
||||
@@ -206,7 +206,7 @@ compositor/
|
||||
│ ├── renderer.mbt # Pixmap, SrcOver blending, rounded rects, 5x7 font, shm blit, PNG/PPM
|
||||
│ └── renderer_test.mbt # Unit tests (wasm + native)
|
||||
├── host/ # Compositor host wiring WaylandServer + lib/wm + SceneGraph + Renderer
|
||||
│ ├── compositor.mbt # MoonPlasmaCompositor
|
||||
│ ├── compositor.mbt # ChandraCompositor
|
||||
│ └── e2e_test.mbt # Native e2e Wayland client + SCM_RIGHTS + BSP/Floating + PNG test
|
||||
└── bin/ # Standalone native compositor binary
|
||||
└── main.mbt # CLI (--socket, --theme)
|
||||
@@ -215,14 +215,14 @@ compositor/
|
||||
### 4.2 MoonBit Components & Pure Libraries
|
||||
Following the existing `lib/*` + `components/*/gen/stub.mbt` split:
|
||||
- `lib/wm/`: Pure MoonBit tiling/stacking/focus state machines (unit-tested with `moon test` on both `wasm` and `native`).
|
||||
- `components/wm-hybrid/`: Hybrid BSP tiling / Floating / Monocle WM component implementing `moonplasma:wm/policy`.
|
||||
- `components/wm-hybrid/`: Hybrid BSP tiling / Floating / Monocle WM component implementing `chandra:wm/policy`.
|
||||
- `components/decoration-breeze/`: Default server-side decoration component.
|
||||
|
||||
---
|
||||
|
||||
## 5. Event Loop & Concurrency Model
|
||||
|
||||
As documented in `docs/TOOLCHAIN.md`, `moonbitlang/async` targets native/JS runtimes and is **not** WASI P3 component-model async. In the pure-MoonBit native compositor (`compositor/host/`), `MoonPlasmaCompositor::step()` drives a non-blocking poll loop over the listening Unix socket and connected Wayland client fds, dispatching `CompositorEvent`s into `@wm.WmState` and updating `SceneGraph` + `DamageTracker` synchronously with zero thread contention.
|
||||
As documented in `docs/TOOLCHAIN.md`, `moonbitlang/async` targets native/JS runtimes and is **not** WASI P3 component-model async. In the pure-MoonBit native compositor (`compositor/host/`), `ChandraCompositor::step()` drives a non-blocking poll loop over the listening Unix socket and connected Wayland client fds, dispatching `CompositorEvent`s into `@wm.WmState` and updating `SceneGraph` + `DamageTracker` synchronously with zero thread contention.
|
||||
|
||||
---
|
||||
|
||||
@@ -253,17 +253,17 @@ Each output renders a layered tree evaluated bottom-to-top:
|
||||
| Phase | Milestone | Deliverable | Verification Gate |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **Phase 1** | **M3** | **Pure MoonBit Native Compositor** (`compositor/` with Wayland wire server, `lib/wm`, Breeze SSD, software rasterizer, PNG encoder). | `moon test --target native compositor/renderer compositor/host` passes e2e Wayland client + `SCM_RIGHTS` + BSP/Floating + PNG verification. |
|
||||
| **Phase 2** | **M4** | **WM World & Components** (`moonplasma:wm/policy`, `decoration`, `components/wm-hybrid`, `components/decoration-breeze`). | `moon test` passes on `lib/wm`; `scripts/build-wm.sh` builds Wasm components cleanly. |
|
||||
| **Phase 2** | **M4** | **WM World & Components** (`chandra:wm/policy`, `decoration`, `components/wm-hybrid`, `components/decoration-breeze`). | `moon test` passes on `lib/wm`; `scripts/build-wm.sh` builds Wasm components cleanly. |
|
||||
| **Phase 3** | **M5+** | **Interactive Input & Live Display Backend** (`wl_pointer` / `wl_keyboard` forwarding, DRM/KMS or nested X11/Wayland scanout). | Launch real Wayland clients (`foot`, `weston-terminal`) interactively. |
|
||||
|
||||
---
|
||||
|
||||
## 8. Window Manager (WM) Architecture
|
||||
|
||||
In `moon-plasma`, the **Window Manager is pure MoonBit policy** (`lib/wm/` and `components/wm-hybrid/`), completely decoupled from Wayland wire serialization and pixel rendering.
|
||||
In `chandra`, the **Window Manager is pure MoonBit policy** (`lib/wm/` and `components/wm-hybrid/`), completely decoupled from Wayland wire serialization and pixel rendering.
|
||||
|
||||
### 8.1 Integration with the Compositor & Wayland Protocols
|
||||
`MoonPlasmaCompositor` translates Wayland protocol events into `lib/wm` calls and applies the returned `Array[WmAction]` back to `WaylandServer`:
|
||||
`ChandraCompositor` translates Wayland protocol events into `lib/wm` calls and applies the returned `Array[WmAction]` back to `WaylandServer`:
|
||||
|
||||
| Wayland / Shell Event | Compositor (`compositor/wayland`) Action | WM (`lib/wm`) Role |
|
||||
| :--- | :--- | :--- |
|
||||
@@ -304,10 +304,10 @@ Workspace
|
||||
- **Negotiation:** On `xdg_toplevel` creation, the host advertises `zxdg_decoration_manager_v1` with default mode `ServerSide`.
|
||||
- Clients that accept SSD (most Qt/GTK/terminal apps) omit client shadows/titlebars; the host invokes the `decoration` MoonBit component.
|
||||
- Clients that insist on CSD (e.g., GTK4/libadwaita apps requesting `ClientSide`) are honored and wrapped in a minimal `0px` decoration node (only focus ring if configured).
|
||||
- **`moonplasma:wm/decoration@0.2.0` Interface:**
|
||||
- **`chandra:wm/decoration@0.2.0` Interface:**
|
||||
```wit
|
||||
interface decoration {
|
||||
use moonplasma:desktop/types@0.1.0.{rect, size, draw-op};
|
||||
use chandra:desktop/types@0.1.0.{rect, size, draw-op};
|
||||
use policy.{window-state};
|
||||
|
||||
enum hit-role { none, titlebar, close, maximize, minimize, resize-n, resize-s, resize-e, resize-w, resize-nw, resize-ne, resize-sw, resize-se }
|
||||
@@ -330,7 +330,7 @@ Workspace
|
||||
- On startup, `wm-policy` registers bindings (e.g., `Super+Return` → launch terminal, `Super+Q` → close focused, `Super+1..9` → switch workspace, `Super+Space` → toggle floating/tiled, `Alt+Tab` → cycle MRU).
|
||||
- The host matches raw `xkbcommon` keysyms + modifiers in the input hot-path *before* forwarding to the focused Wayland client, invoking `wm.on-action(action_id)` on match.
|
||||
- **Host-Mediated Shell/Taskbar IPC (`window-registry` read-only grant):**
|
||||
- Instead of an ad-hoc UNIX socket protocol (`plasma-shell` / `hyprctl`), `moon-plasma` panels, taskbars, and pager plasmoids import a **capability-attenuated `window-registry` WIT interface**:
|
||||
- Instead of an ad-hoc UNIX socket protocol (`plasma-shell` / `hyprctl`), `chandra` panels, taskbars, and pager plasmoids import a **capability-attenuated `window-registry` WIT interface**:
|
||||
- `list-windows() -> list<window-summary>` (id, title, app-id, workspace, focused, minimized — *never* raw buffers or input).
|
||||
- `activate(id)` / `minimize(id)` / `close(id)` → routed by the host to `wm-policy.on-window-request(...)`.
|
||||
- A `task-manager` plasmoid on the panel can thus render live window buttons, show urgent badges, and switch focus using the exact same `plasmoid` + `draw-op` model as `clock-digital` and `launcher`.
|
||||
@@ -371,13 +371,13 @@ All layout math (`compute_bsp_rects`, `insert_leaf`, `remove_leaf`, `focus_direc
|
||||
|
||||
## 9. `wasi-gfx` GUI Loading & Presentation Architecture
|
||||
|
||||
To load and present the `moon-plasma` GUI portably across both the native MoonBit compositor and WebAssembly/browser hosts, `moon-plasma` integrates the [wasi-gfx](https://wasi-gfx.dev/) WIT specification (`wasi-gfx:surface@0.2.0` and `wasi-gfx:frame-buffer@0.2.0`):
|
||||
To load and present the `chandra` GUI portably across both the native MoonBit compositor and WebAssembly/browser hosts, `chandra` integrates the [wasi-gfx](https://wasi-gfx.dev/) WIT specification (`wasi-gfx:surface@0.2.0` and `wasi-gfx:frame-buffer@0.2.0`):
|
||||
|
||||
1. **WIT Contracts (`wit/gfx/`):**
|
||||
- `wit/gfx/deps/wasi-gfx-frame-buffer-0.2.0/frame-buffer.wit`: `wasi-gfx:frame-buffer/frame-buffer@0.2.0` (`buffer` resource with `get-with-copy` / `set-with-copy`).
|
||||
- `wit/gfx/deps/wasi-gfx-surface-0.2.0/surface.wit`: `wasi-gfx:surface/surface@0.2.0` (`surface` resource, `create-desc`, `resize-event`, `frame-event`, `pointer-event`, `key-event`, and `stream<...>` event channels).
|
||||
- `wit/gfx/deps/wasi-gfx-surface-0.2.0/surface-frame-buffer.wit`: `wasi-gfx:surface/surface-frame-buffer@0.2.0` (`context` resource binding a `surface` to `get-current-buffer()` + `present()`).
|
||||
- `wit/gfx/worlds.wit`: `moonplasma:gfx@0.2.0/gui-loader` world importing `wasi-gfx` and exporting `init-gui`, `render-frame`, `on-resize`, `on-pointer`, and `on-key`.
|
||||
- `wit/gfx/worlds.wit`: `chandra:gfx@0.2.0/gui-loader` world importing `wasi-gfx` and exporting `init-gui`, `render-frame`, `on-resize`, `on-pointer`, and `on-key`.
|
||||
|
||||
2. **MoonBit `wasi-gfx` GUI Component (`components/gfx-gui/`):**
|
||||
- Built with `wit-bindgen moonbit wit/gfx --world gui-loader` and `scripts/build-gfx.sh`.
|
||||
@@ -385,7 +385,7 @@ To load and present the `moon-plasma` GUI portably across both the native MoonBi
|
||||
|
||||
3. **Pure-MoonBit Native `wasi-gfx` Runtime (`compositor/gfx/`):**
|
||||
- Implements `Surface`, `FrameBuffer`, `SurfaceFrameBufferContext`, `present_pixmap`, and `present_scene` in pure MoonBit.
|
||||
- `MoonPlasmaCompositor::present_to_gfx` and `MoonPlasmaCompositor::handle_gfx_events` in `compositor/host/` connect the native Wayland compositor to `wasi-gfx` surfaces (also exposed via `--gfx-out <path.png>` in `compositor/bin/main.mbt`).
|
||||
- `ChandraCompositor::present_to_gfx` and `ChandraCompositor::handle_gfx_events` in `compositor/host/` connect the native Wayland compositor to `wasi-gfx` surfaces (also exposed via `--gfx-out <path.png>` in `compositor/bin/main.mbt`).
|
||||
|
||||
4. **JS / Browser `wasi-gfx` Host Adapter (`host/src/wasi-gfx.mjs`, `host/web/main.mjs`):**
|
||||
- Provides `WasiGfxSurface`, `WasiGfxBuffer`, `WasiGfxFrameBufferContext`, and `createWasiGfxHost()` for both `jco`-transpiled `wasi-gfx` components and the browser desktop shell (`host/web/main.mjs`), routing input streams and presenting RGBA8888 frames onto the `<canvas>`.
|
||||
|
||||
Reference in new issue
Block a user