| wayland-bar-compositor: a wlroots compositor in jolt, for panels on X11 1d16366 nandi 8d ago | 1 | # wayland-bar-compositor |
| 2 | |
| 3 | A Wayland compositor written in jolt directly on wlroots, for putting a Wayland |
| 4 | panel (such as `cosmic-panel`) onto an X11 desktop. |
| 5 | |
| 6 | There is no shared object here: `jolt.ffi` binds libwlroots, libwayland-server, |
| 7 | libxkbcommon, libX11, libXext and libXi directly. The compositor opens one |
| 8 | wlroots X11 output, draws layer-shell and xdg-shell clients through the wlroots |
| 9 | scene graph, and forwards pointer and keyboard input to them. |
| 10 | |
| 11 | Because it owns the scene, it shapes its own X11 window: the bar strip plus |
| 12 | the outline of whatever popups are mapped, traced from the rendered frame so |
| 13 | rounded corners show the desktop behind them. XInput2 raw button presses on the |
| 14 | root window let a click on an X11 app close open popups. |
| 15 | |
| 16 | wayland-bar-compositor the compositor |
| 17 | build generates offsets.edn from the installed headers |
| 18 | gen-offsets.c the offsetof dump build compiles |
| 19 | offsets.edn wlroots struct layout facts, read at startup |
| 20 | protocol/ wlr-layer-shell XML for the header wlroots omits |
| 21 | |
| 22 | ## Running |
| 23 | |
| 24 | ```bash |
| 25 | ./build # after any wlroots update |
| 26 | WLR_BACKENDS=x11 WLR_RENDERER=pixman \ |
| 27 | ./wayland-bar-compositor --size 1920x640 --strip 0,0,1920,40 --title my-bar -- cosmic-panel |
| 28 | ``` |
| 29 | |
| 30 | `--size` is the whole output, bar plus room for popups; `--strip` is the part |
| 31 | always shown; `--title` names the X11 window so a launcher can find it and dock |
| 32 | it (`_NET_WM_WINDOW_TYPE_DOCK` plus a strut). Set `WBC_DEBUG=1` to log input, |
| 33 | popups and shape changes. |
| 34 | |
| 35 | ## Why a compositor in jolt works |
| 36 | |
| 37 | Every wlroots listener shares one native callback that dispatches on the |
| 38 | listener's address, and listeners come from a free list, so surfaces that come |
| 39 | and go don't leak callbacks. The event loop is `wl_event_loop_dispatch` called |
| 40 | from jolt's own thread, so every callback arrives on that thread — nothing |
| 41 | blocks the collector. wlroots changes struct layouts between minor versions, |
| 42 | which is why the offsets are generated from the headers rather than written by |
| 43 | hand. |
| 44 | |
| 45 | Written for wlroots 0.20 on x86_64. On a native Wayland desktop — COSMIC with |
| 46 | cosmic-comp, for one — none of this is needed: the panel runs directly. |