Add reproducible headless desktop for the X11/NVENC capture path

A Moonlight client connecting to the x11-backend host got a black screen
even though pairing, NVENC, and input injection all worked: the headless
Xorg on :0 had no window manager rendering on it, so capture=x11 grabbed
an empty black root window. (The wlr/kms backends don't hit this — their
capture source renders for itself.)

This was a hand-built path with nothing in the repo to reproduce the
desktop piece. Now:

- files/headless-desktop.service: Openbox session on :0, bound to
  xorg-headless.service, enabled via default.target for lingering boots,
  with a best-effort xsetroot so the desktop is visibly non-black.
- lib/headless.sh: capture_backend_is_x11 + install_headless_desktop
  (idempotent; pulls openbox/xsetroot via the distro dispatch).
- install.sh: installs the desktop unit when capture=x11 is detected.
- status.sh: x11 branch now FAILs if no window manager is on :0 instead
  of only checking the X server answers — the gap that hid this failure.
- docs: TROUBLESHOOTING §13 black-screen lesson; FOLLOWUPS P3 updated.

Part of the P3 x11-backend work; --backend flag, config.sh x11 variant,
and xorg-headless templates remain outstanding.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 23:43:00 +00:00
parent ab23107300
commit 6fc34a2bd2
6 changed files with 137 additions and 0 deletions

View File

@@ -182,6 +182,20 @@ case "${CAP:-}" in
fail "DISPLAY=:0 not reachable (X server not answering)" "Check xorg-headless.service logs."
fi
fi
# Is a window manager actually rendering on :0? X can be up and reachable
# yet have no WM/desktop drawing anything — Sunshine then captures an empty
# black root window (pairing/NVENC/input all work; client sees only black).
if command -v xprop >/dev/null 2>&1; then
wm_check=$( (if [[ $EUID -eq 0 && "$SUSER" != "$(id -un)" ]]; then sudo -u "$SUSER" DISPLAY=:0 xprop -root _NET_SUPPORTING_WM_CHECK; else DISPLAY=:0 xprop -root _NET_SUPPORTING_WM_CHECK; fi) 2>/dev/null)
if grep -q 'window id' <<<"$wm_check"; then
pass "a window manager is running on :0 (something to capture)"
else
fail "no window manager on :0 — capture will be a black screen" \
"Start a desktop on the headless Xorg: 'systemctl --user enable --now headless-desktop.service' (install.sh installs it for the x11 backend). See TROUBLESHOOTING.md §13."
fi
else
note "xprop not installed — skipping window-manager-on-:0 check (install x11-utils to enable it)"
fi
# wlr env leaking into an x11 unit (stale sway drop-in — TROUBLESHOOTING §13)
if [[ -n $UNIT ]]; then
env_dump=$(uctl show "$UNIT" -p Environment 2>/dev/null)