| glimmer-cosmic: a libcosmic backend for glimmer (spike) 6a3304d nandi 8d ago | 1 | # glimmer-cosmic |
| 2 | |
| 3 | The **libcosmic** backend for glimmer — a spike. The same hiccup that |
| 4 | [glimmer-vidya](../glimmer-vidya) paints with egui and [glimmer-tui](../glimmer-tui) |
| 5 | paints in a terminal, painted with COSMIC's widgets and theme through |
| 6 | [`crates/jolt-cosmic`](../../crates/jolt-cosmic). |
| 7 | |
| 8 | ```bash |
| 9 | cargo build --release -p jolt-cosmic |
| 10 | LD_LIBRARY_PATH=../../target/release jolt counter |
| 11 | LD_LIBRARY_PATH=../../target/release jolt smoke # non-interactive, quits itself |
| 12 | ``` |
| 13 | |
| 14 | ## What is the same |
| 15 | |
| 16 | The tree half is glimmer-vidya's. Nodes are integer handles in a Rust arena, |
| 17 | props are written across by name, handlers stay on the jolt side and are found |
| 18 | by node id when an event comes back, and a widget writes its new value into its |
| 19 | own props so a control that ignores its event still works. |
| 20 | |
| 21 | ## What is not: who owns the loop |
| 22 | |
| 23 | egui lets its caller drive frames. libcosmic does not: `cosmic::app::run` takes |
| 24 | the main thread (winit insists) and keeps it until the window closes. So the |
| 25 | loop is inverted: |
| 26 | |
| 27 | ``` |
| 28 | main thread cosmic_run ──────────────────────────────────── returns on close |
| 29 | ▲ wake(tree) │ click / change / toggled |
| 30 | worker (future) mount → commit → wait ─ drain, dispatch, timers → commit → wait … |
| 31 | ``` |
| 32 | |
| 33 | * The reconciler runs on a worker, which is the "UI thread" as glimmer sees it: |
| 34 | `schedule` queues onto it, handlers and timers run on it. |
| 35 | * Its edits land in the arena under a mutex, but libcosmic paints a snapshot |
| 36 | taken at `cosmic_tree_commit`, once per pass. A reconcile half-way through a |
| 37 | patch is never on screen, and a pass that changed nothing commits nothing. |
| 38 | * The worker sleeps in `cosmic_wait` until there is an event, a `schedule`, a |
| 39 | due timer or a close — an idle window costs neither side anything. |
| 40 | * Every call but `cosmic_run` is safe from any thread, which is not true of |
| 41 | libvidya. |
| 42 | |
| 43 | ## Spike limits |
| 44 | |
| 45 | * Tags: `:window` `:box`/`:hbox`/`:vbox` `:page` `:card` `:frame` `:scroll` |
| Paint the rest of frq's tags in glimmer-cosmic 7703c75 nandi 8d ago | 46 | `:label` `:title` `:title-2` `:dim-label` `:button` `:link` `:checkbutton` |
| 47 | `:entry` `:separator` `:spacer` `:progress` `:status` `:spinner` `:image` |
| 48 | `:avatar` `:emoji` `:reaction`. Anything else paints as a column. |
| 49 | * Layout follows glimmer-jvui: a container fills its parent's cross axis, |
| 50 | `:fill-height` takes what is left, `:width-request 0` is no request, and |
| 51 | `:margin`/`:margin-top`… `:spacing` `:align` are read. |
| 52 | * `:scroll` fills both ways, follows new rows while `:stick-to-bottom` and the |
| 53 | reader is at the end, jumps when `:scroll-to-bottom` changes, keeps its place |
| 54 | by `:scroll-key` across a remount, reports `"end"`/`"away"` on `:on-change`, |
| 55 | and moves to a row that sets `:scroll-here` — by the row's index, since there |
| 56 | is no layout to ask, so it is close rather than exact in a list of rows of |
| 57 | different heights. |
| 58 | * Events: `click`, `toggled`, `change`, `activate`, `hover`, `unhover`. |
| 59 | * Not yet: `:image {:feed …}` (live frames; the slot is drawn empty), a |
| 60 | wrapping `:hbox {:wrap true}`, `:on-rows` `:on-paste-empty` `:on-key` on an |
| 61 | entry, `:max-rows` (the entry is one line). |
| glimmer-cosmic: a libcosmic backend for glimmer (spike) 6a3304d nandi 8d ago | 62 | * One window per process — winit cannot make a second event loop — so there is |
| 63 | no REPL `start!`/`stop!` yet, and no headless test beyond the arena's own |
| 64 | Rust tests. |
| 65 | * libcosmic is MPL-2.0 and a git dependency; see `crates/jolt-cosmic/Cargo.toml`. |