feat: client-selectable compositor (protocol → host → client → C ABI → mgmt → web)
A client can now request which compositor backend the host drives its virtual
output on (gamescope/KWin/Mutter/wlroots). The host honors the request if that
backend is available, else falls back to auto-detect and reports the resolved
choice back — wire-compatible both directions (no ABI bump).
Protocol (punktfunk-core):
- New CompositorPref (config.rs): Auto|Kwin|Wlroots|Mutter|Gamescope with
u8/name mappings. Appended as one optional byte to Hello (client preference)
and Welcome (host's resolved choice). Both decoders already tolerate trailing
bytes, so old↔new interop is preserved — ABI_VERSION stays 2. Round-trip +
back-compat (truncated-message) tests.
- C ABI: punktfunk_connect_ex(compositor) + PUNKTFUNK_COMPOSITOR_* constants;
punktfunk_connect delegates with AUTO, so the existing symbol is unchanged.
NativeClient::connect / worker_main thread the preference through.
Host:
- vdisplay::available() enumerates usable backends via cheap, side-effect-free
probes (KWin zkde global, gamescope binary+version, GNOME/Sway env), plus
Compositor id/label/as_pref/from_pref/all helpers.
- m3 handshake resolves the preference to a concrete backend during the
handshake (pick_compositor pure + resolved logging), reports it in Welcome,
and threads it into virtual_stream (replacing the unconditional detect()).
- mgmt GET /v1/compositors lists every backend with availability + the
auto-detected default (OpenAPI regenerated).
Client:
- punktfunk-client-rs --compositor NAME; logs the host's resolved choice from
the Welcome ("session offer … compositor=…").
Web console:
- Host page gains a Compositors card (availability + default badges) via the
codegen'd useListCompositors hook; en/de strings added.
Also fixes a pre-existing, env-dependent test-isolation bug:
mgmt::tests::paired_clients_list_and_unpair seeded the real
~/.config/punktfunk/paired.json (AppState::new loads it), so a real
GameStream-paired client leaked into body[0] on a dev box — now cleared first.
Live-validated against headless KWin: --compositor kwin honored, --compositor
mutter falls back to kwin (available=[kwin, gamescope]), resolved choice
round-trips to the client. Tests: +6 (wire/back-compat, resolution precedence,
endpoint); workspace green, clippy/fmt clean, C ABI harness PASS at abi_version=2,
web typecheck + build clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,91 @@ pub enum Compositor {
|
||||
Gamescope,
|
||||
}
|
||||
|
||||
impl Compositor {
|
||||
/// Stable lowercase id used on the wire / management API (matches
|
||||
/// [`punktfunk_core::CompositorPref::as_str`]).
|
||||
pub fn id(self) -> &'static str {
|
||||
match self {
|
||||
Compositor::Kwin => "kwin",
|
||||
Compositor::Wlroots => "wlroots",
|
||||
Compositor::Mutter => "mutter",
|
||||
Compositor::Gamescope => "gamescope",
|
||||
}
|
||||
}
|
||||
|
||||
/// Human label for UIs.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Compositor::Kwin => "KWin / KDE Plasma",
|
||||
Compositor::Wlroots => "wlroots (Sway / Hyprland)",
|
||||
Compositor::Mutter => "Mutter / GNOME",
|
||||
Compositor::Gamescope => "gamescope",
|
||||
}
|
||||
}
|
||||
|
||||
/// The protocol [`punktfunk_core::CompositorPref`] naming this backend.
|
||||
pub fn as_pref(self) -> punktfunk_core::CompositorPref {
|
||||
use punktfunk_core::CompositorPref as P;
|
||||
match self {
|
||||
Compositor::Kwin => P::Kwin,
|
||||
Compositor::Wlroots => P::Wlroots,
|
||||
Compositor::Mutter => P::Mutter,
|
||||
Compositor::Gamescope => P::Gamescope,
|
||||
}
|
||||
}
|
||||
|
||||
/// The concrete backend a [`punktfunk_core::CompositorPref`] names, or `None` for `Auto`.
|
||||
pub fn from_pref(p: punktfunk_core::CompositorPref) -> Option<Compositor> {
|
||||
use punktfunk_core::CompositorPref as P;
|
||||
Some(match p {
|
||||
P::Auto => return None,
|
||||
P::Kwin => Compositor::Kwin,
|
||||
P::Wlroots => Compositor::Wlroots,
|
||||
P::Mutter => Compositor::Mutter,
|
||||
P::Gamescope => Compositor::Gamescope,
|
||||
})
|
||||
}
|
||||
|
||||
/// Every backend, in a stable display order (for enumeration / UIs).
|
||||
pub fn all() -> [Compositor; 4] {
|
||||
[
|
||||
Compositor::Kwin,
|
||||
Compositor::Gamescope,
|
||||
Compositor::Mutter,
|
||||
Compositor::Wlroots,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// The compositor backends usable on this host *right now*: gamescope wherever its binary is
|
||||
/// installed (it spawns a nested session — independent of the running desktop), plus the live
|
||||
/// session's own compositor (KWin / Mutter / wlroots) when the host runs inside it. Cheap,
|
||||
/// side-effect-free probes — safe to call per management request. A concrete client preference
|
||||
/// is validated against this set before it's honored (see the m3 handshake's resolution).
|
||||
pub fn available() -> Vec<Compositor> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let mut v = Vec::new();
|
||||
if kwin::is_available() {
|
||||
v.push(Compositor::Kwin);
|
||||
}
|
||||
if gamescope::is_available() {
|
||||
v.push(Compositor::Gamescope);
|
||||
}
|
||||
if mutter::is_available() {
|
||||
v.push(Compositor::Mutter);
|
||||
}
|
||||
if wlroots::is_available() {
|
||||
v.push(Compositor::Wlroots);
|
||||
}
|
||||
v
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Detect the compositor to drive: `PUNKTFUNK_COMPOSITOR` override, else `XDG_CURRENT_DESKTOP`.
|
||||
pub fn detect() -> Result<Compositor> {
|
||||
if let Ok(v) = std::env::var("PUNKTFUNK_COMPOSITOR") {
|
||||
|
||||
Reference in New Issue
Block a user