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
@@ -1,9 +1,9 @@
|
||||
# moon-plasma architecture
|
||||
# chandra architecture
|
||||
|
||||
> Status legend used throughout: **[M0]** implemented in this repository today,
|
||||
> **[designed]** interface sketched here but not in `wit/` yet, **[open]** needs a decision.
|
||||
|
||||
moon-plasma is a KDE-Plasma-like desktop in which **every part is a WebAssembly
|
||||
chandra is a KDE-Plasma-like desktop in which **every part is a WebAssembly
|
||||
component** (Component Model, WIT-defined interfaces, written in MoonBit) running
|
||||
on top of a deliberately tiny trusted **host**. The point is not to clone Plasma
|
||||
pixel for pixel; it is to take Plasma's *decomposition* (shell / window manager /
|
||||
@@ -12,7 +12,7 @@ versioned, permission-checked, hot-swappable interface.
|
||||
|
||||
## 1. Plasma → component-model map
|
||||
|
||||
| Plasma piece | What it does | moon-plasma counterpart | Component or host? |
|
||||
| Plasma piece | What it does | chandra counterpart | Component or host? |
|
||||
|---|---|---|---|
|
||||
| `plasmashell` (containments, panels) | Hosts the desktop & panels, loads plasmoids | `shell` component exporting `desktop-surface` + `panel-layout` **[M0]** | component |
|
||||
| Plasmoids / widgets (QML + C++/JS) | Clock, task manager, kickoff… | `widget` world exporting `plasmoid` **[M0]**: `digital-clock`, `binary-clock`, `launcher` | component, one instance per widget |
|
||||
@@ -187,7 +187,7 @@ WASI-style, deny-by-default:
|
||||
|
||||
## 7. Versioning WIT packages
|
||||
|
||||
* Packages are semver'd (`moonplasma:desktop@0.1.0`). While `0.x`, any minor may
|
||||
* Packages are semver'd (`chandra:desktop@0.1.0`). While `0.x`, any minor may
|
||||
break; components pin the exact package version in their world.
|
||||
* From `1.0`: **additive-only minors** – new interfaces, new functions, new
|
||||
worlds, new variant cases at the *end* only when consumers are required to
|
||||
@@ -195,9 +195,9 @@ WASI-style, deny-by-default:
|
||||
grow (e.g. `plasmoid-info`, `tokens`) should become `record` + `option`/`list`
|
||||
extension points before 1.0, or be replaced by a new interface version
|
||||
(`plasmoid@1.1`) that the host serves alongside the old one.
|
||||
* Split by domain so versions move independently: `moonplasma:desktop` (types,
|
||||
theme, plasmoid, panel), later `moonplasma:wm`, `moonplasma:search`,
|
||||
`moonplasma:notify`, `moonplasma:config`, `moonplasma:session`, `moonplasma:vfs`.
|
||||
* Split by domain so versions move independently: `chandra:desktop` (types,
|
||||
theme, plasmoid, panel), later `chandra:wm`, `chandra:search`,
|
||||
`chandra:notify`, `chandra:config`, `chandra:session`, `chandra:vfs`.
|
||||
* The host advertises the set of interface versions it implements and may
|
||||
serve N and N-1 side by side via adapters; a component declares what it
|
||||
targets and fails to load otherwise (no silent downgrade).
|
||||
@@ -223,7 +223,7 @@ does **not** transfer is `host/src/desktop.mjs`; it is intentionally small
|
||||
|
||||
## 9. Interface catalogue
|
||||
|
||||
Implemented in `wit/` (package `moonplasma:desktop@0.1.0`):
|
||||
Implemented in `wit/` (package `chandra:desktop@0.1.0`):
|
||||
|
||||
| Interface | Purpose |
|
||||
|---|---|
|
||||
|
||||
+7
-7
@@ -47,7 +47,7 @@ Component sizes are 24–33 KB each (release build, no wasm-opt).
|
||||
* Generated helper functions are emitted in nondeterministic order, so
|
||||
`scripts/gen-bindings.sh --check` compares sorted lines, not bytes.
|
||||
* `moon.mod.json` is no longer accepted by this moon (0.1.20261119): use `moon.mod`.
|
||||
* jco strips the `@version` from import keys (`moonplasma:desktop/clock`), and
|
||||
* jco strips the `@version` from import keys (`chandra:desktop/clock`), and
|
||||
maps WIT `variant` → `{tag, val}`, `enum` → string, `option` → value/`undefined`,
|
||||
`result` import returns → `{tag:'ok'|'err', val}` (or throw).
|
||||
* `moon test` runs on the wasm target through `moonrun`; packages that import the
|
||||
@@ -60,7 +60,7 @@ Component sizes are 24–33 KB each (release build, no wasm-opt).
|
||||
|
||||
| Package | Relevance | Backends / caveat |
|
||||
|---|---|---|
|
||||
| `mizchi/wit` 0.4.x | WIT parser/resolver in MoonBit | could power an in-MoonBit `moon-plasma` CLI that inspects worlds; not needed at M0 |
|
||||
| `mizchi/wit` 0.4.x | WIT parser/resolver in MoonBit | could power an in-MoonBit `chandra` CLI that inspects worlds; not needed at M0 |
|
||||
| `moonrockz/wit` | WIT scanner/CST/formatter | same |
|
||||
| `mizchi/wite` 0.11 | component-aware analyzer/optimizer (`wite` can verify a component against WIT, compose WAC) | candidate replacement for `wasm-tools` size/verify steps |
|
||||
| `moonbitlang/async` | async runtime (native/…); not a component-model async | the component-model async ABI (WASIp3) is in wit-bindgen's backend but out of scope until hosts support it |
|
||||
@@ -96,16 +96,16 @@ wit-bindgen 0.63.0, wasmtime 51.0.0, jco 1.42.0, Node 20/24.
|
||||
|
||||
```bash
|
||||
wit-bindgen moonbit wit --world clock-widget --out-dir . \
|
||||
--gen-dir components/clock-digital/gen --project-name moonplasma/desktop --ignore-module-file
|
||||
--gen-dir components/clock-digital/gen --project-name chandra/desktop --ignore-module-file
|
||||
moon build --target wasm --release
|
||||
wasm-tools component embed wit _build/wasm/release/build/components/clock-digital/gen/gen.wasm \
|
||||
--world clock-widget --encoding utf16 -o e.wasm
|
||||
wasm-tools component new e.wasm -o build/components/clock-digital.wasm
|
||||
wasm-tools component wit build/components/clock-digital.wasm
|
||||
# world root { import moonplasma:desktop/types@0.1.0;
|
||||
# import moonplasma:desktop/clock@0.1.0;
|
||||
# import moonplasma:desktop/theme@0.1.0;
|
||||
# export moonplasma:desktop/plasmoid@0.1.0; }
|
||||
# world root { import chandra:desktop/types@0.1.0;
|
||||
# import chandra:desktop/clock@0.1.0;
|
||||
# import chandra:desktop/theme@0.1.0;
|
||||
# export chandra:desktop/plasmoid@0.1.0; }
|
||||
jco transpile build/components/clock-digital.wasm -o build/jco/clock-digital --instantiation async
|
||||
node host/src/cli.mjs --time 2026-11-24T14:07:00 # instantiates all components, prints the desktop
|
||||
```
|
||||
|
||||
+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