mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
Desktop GPU: menu games run in their own gamescope; labwc on the patched wlroots
droiddeck-gpu runs a program in a gamescope of its own on the app's compositor (wayland-0), full screen over the desktop - the path the rail's play chips use, where Vulkan works. droiddeck-desktop-gpu gives every Game/Emulator menu entry a per-user copy through it (auto: while the desktop is on pixman), keeping 'Run in a desktop window' as an action. droiddeck-desktop loads /usr/local/lib/droiddeck-wlroots for the vulkan/gles2 renderers and falls back to pixman when labwc stops at start. The build stages the wlroots release named by tools/wlroots/release.env, once published.
This commit is contained in:
1 parent
7dc00d9b23
commit
d984a4ba31
8 files changed
+238
-20
No files matched your search
@@ -14,9 +14,25 @@ export QT_QPA_PLATFORMTHEME=lxqt
|
||||
# The prefs for this are only advisory and a profile can override them; the environment is not.
|
||||
export MOZ_DISABLE_CONTENT_SANDBOX=1 MOZ_DISABLE_GMP_SANDBOX=1 MOZ_DISABLE_RDD_SANDBOX=1
|
||||
export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
|
||||
# wlroots allocates through gbm on a real DRM node, which the KGSL stand-in is not: pixman
|
||||
# (software, shm) is what boots here. BL_WLR_RENDERER=vulkan/gles2 tries acceleration.
|
||||
# pixman composites in software and gives programs shm buffers only, so a Vulkan program on it
|
||||
# fails at its swapchain. vulkan (or gles2) composite on the GPU and give programs DMA-BUFs, but
|
||||
# stock wlroots allocates through gbm on a real DRM node and the KGSL stand-in is not one ("unable
|
||||
# to create allocator"): they need the app's patched wlroots (tools/wlroots), whose Vulkan
|
||||
# allocator exports the buffers instead. BL_WLR_RENDERER picks; see the fallback at the end.
|
||||
export WLR_RENDERER=${BL_WLR_RENDERER:-pixman}
|
||||
WLROOTS_DIR=/usr/local/lib/droiddeck-wlroots
|
||||
BASE_LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}
|
||||
use_renderer() {
|
||||
export WLR_RENDERER=$1
|
||||
if [ "$1" != pixman ] && [ -f "$WLROOTS_DIR/libwlroots-0.20.so" ]; then
|
||||
export LD_LIBRARY_PATH=$WLROOTS_DIR${BASE_LD_LIBRARY_PATH:+:$BASE_LD_LIBRARY_PATH}
|
||||
elif [ -n "$BASE_LD_LIBRARY_PATH" ]; then
|
||||
export LD_LIBRARY_PATH=$BASE_LD_LIBRARY_PATH
|
||||
else
|
||||
unset LD_LIBRARY_PATH
|
||||
fi
|
||||
}
|
||||
use_renderer "$WLR_RENDERER"
|
||||
# The desktop's own log, beside the session's, so labwc and the programs on it can be read apart
|
||||
# from the session that started them. The session log keeps the milestones either way.
|
||||
if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
@@ -85,12 +101,38 @@ export BL_DESKTOP=1
|
||||
ln -sf /usr/local/bin/bannerlator-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null
|
||||
ln -sf /usr/local/bin/bannerlator-steam-shim /usr/local/bin/steam 2>/dev/null
|
||||
python3 /usr/local/bin/bannerlator-desktop-games 2>&1 | sed 's/^/[games] /'
|
||||
# Games and emulators from the menu run through droiddeck-gpu (their own gamescope on the app's
|
||||
# compositor) while the desktop is on pixman, where they could not draw with the GPU.
|
||||
# BL_DESKTOP_GPU=on/off overrides; each entry keeps "Run in a desktop window" either way.
|
||||
gpu_entries() { python3 /usr/local/bin/droiddeck-desktop-gpu 2>&1 | sed 's/^/[gpu] /'; }
|
||||
gpu_entries
|
||||
|
||||
echo "== droiddeck-desktop: labwc ($WLR_RENDERER) on $WAYLAND_DISPLAY"
|
||||
# ~/.droiddeck-desktop-debug: labwc's own debug log (views and layer surfaces mapping) too.
|
||||
DEBUG=; [ -f "$HOME/.droiddeck-desktop-debug" ] && DEBUG=-d
|
||||
# A session bus: the panel's menus, the file manager and the portal all expect one.
|
||||
if command -v dbus-run-session >/dev/null 2>&1; then
|
||||
exec dbus-run-session -- labwc $DEBUG -C "$HOME/.config/labwc"
|
||||
run_labwc() {
|
||||
echo "== droiddeck-desktop: labwc ($WLR_RENDERER${LD_LIBRARY_PATH:+, wlroots from $WLROOTS_DIR}) on $WAYLAND_DISPLAY"
|
||||
# A session bus: the panel's menus, the file manager and the portal all expect one.
|
||||
if command -v dbus-run-session >/dev/null 2>&1; then
|
||||
dbus-run-session -- labwc $DEBUG -C "$HOME/.config/labwc"
|
||||
else
|
||||
labwc $DEBUG -C "$HOME/.config/labwc"
|
||||
fi
|
||||
}
|
||||
if [ "$WLR_RENDERER" = pixman ]; then
|
||||
run_labwc
|
||||
exit $?
|
||||
fi
|
||||
exec labwc $DEBUG -C "$HOME/.config/labwc"
|
||||
# A GPU renderer this device cannot start ends the desktop within a second or two; rather than a
|
||||
# session that closes at once, the desktop comes up on pixman and the log says why.
|
||||
started=$(date +%s)
|
||||
run_labwc
|
||||
rc=$?
|
||||
if [ "$rc" -ne 0 ] && [ $(( $(date +%s) - started )) -lt 15 ]; then
|
||||
echo "== droiddeck-desktop: labwc on $WLR_RENDERER stopped at start (exit $rc); starting on pixman instead"
|
||||
use_renderer pixman
|
||||
find "$XDG_RUNTIME_DIR" -mindepth 1 -maxdepth 1 ! -name 'wayland-0*' ! -name 'keymap.xkb' -exec rm -rf {} + 2>/dev/null
|
||||
gpu_entries
|
||||
run_labwc
|
||||
rc=$?
|
||||
fi
|
||||
exit $rc
|
||||
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/python3
|
||||
# The desktop's games and emulators, started on the GPU. Every menu entry whose categories say
|
||||
# Game or Emulator gets a copy of its own in ~/.local/share/applications (which wins over
|
||||
# /usr/share/applications) whose Exec runs it through droiddeck-gpu: full screen on the app's
|
||||
# compositor, where Vulkan and OpenGL work. The entry keeps the old way as a second action, "Run in
|
||||
# a desktop window". Run at every desktop start; copies whose original is gone, or all of them when
|
||||
# the switch is off, are removed.
|
||||
#
|
||||
# BL_DESKTOP_GPU=auto (default: on while the desktop is composited by pixman) | on | off
|
||||
import os
|
||||
import re
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
SYSTEM_DIR = "/usr/share/applications"
|
||||
USER_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
MARK = "X-DroidDeck-GPU=1"
|
||||
# The client and its games already hand themselves to the app (bannerlator-steam-launch).
|
||||
SKIP = re.compile(r"^(steam|droiddeck-game-|droiddeck-steam|steamdeck-)", re.I)
|
||||
|
||||
|
||||
def enabled():
|
||||
mode = os.environ.get("BL_DESKTOP_GPU", "auto").strip().lower()
|
||||
if mode in ("on", "1", "yes", "true"):
|
||||
return True
|
||||
if mode in ("off", "0", "no", "false"):
|
||||
return False
|
||||
return os.environ.get("WLR_RENDERER", "pixman") == "pixman"
|
||||
|
||||
|
||||
def main_group(text):
|
||||
"""The [Desktop Entry] group's lines, and everything after it."""
|
||||
lines = text.splitlines()
|
||||
start = next((i for i, l in enumerate(lines) if l.strip() == "[Desktop Entry]"), None)
|
||||
if start is None:
|
||||
return None, None, None
|
||||
end = next((i for i in range(start + 1, len(lines)) if lines[i].startswith("[")), len(lines))
|
||||
return lines[:start + 1], lines[start + 1:end], lines[end:]
|
||||
|
||||
|
||||
def wrap(text):
|
||||
head, group, rest = main_group(text)
|
||||
if group is None:
|
||||
return None
|
||||
keys = {}
|
||||
for l in group:
|
||||
if "=" in l and not l.lstrip().startswith("#"):
|
||||
k, v = l.split("=", 1)
|
||||
keys.setdefault(k.strip(), v)
|
||||
cats = set(filter(None, keys.get("Categories", "").split(";")))
|
||||
if not cats & {"Game", "Emulator"}:
|
||||
return None
|
||||
if keys.get("Type", "Application") != "Application" or keys.get("NoDisplay", "").lower() == "true":
|
||||
return None
|
||||
exec_line = keys.get("Exec", "").strip()
|
||||
if not exec_line or exec_line.startswith("droiddeck-gpu "):
|
||||
return None
|
||||
out_group = []
|
||||
actions = keys.get("Actions", "")
|
||||
for l in group:
|
||||
k = l.split("=", 1)[0].strip() if "=" in l else None
|
||||
if k == "Exec":
|
||||
out_group.append("Exec=droiddeck-gpu " + exec_line)
|
||||
elif k == "Actions":
|
||||
continue
|
||||
else:
|
||||
out_group.append(l)
|
||||
while out_group and not out_group[-1].strip():
|
||||
out_group.pop()
|
||||
out_group.append("Actions=" + ("droiddeck-window;" + actions if actions else "droiddeck-window;"))
|
||||
out_group.append(MARK)
|
||||
window = ["", "[Desktop Action droiddeck-window]", "Name=Run in a desktop window", "Exec=" + exec_line]
|
||||
# The entry's own actions (new window, a different mode...) run on the GPU as well.
|
||||
wrapped_rest = []
|
||||
for l in rest:
|
||||
if l.startswith("Exec=") and not l[5:].startswith("droiddeck-gpu "):
|
||||
l = "Exec=droiddeck-gpu " + l[5:]
|
||||
wrapped_rest.append(l)
|
||||
if wrapped_rest and wrapped_rest[0].strip():
|
||||
wrapped_rest.insert(0, "")
|
||||
return "\n".join(head + out_group + window + wrapped_rest) + "\n"
|
||||
|
||||
|
||||
def ours(path):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
return MARK in f.read()
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
on = enabled()
|
||||
os.makedirs(USER_DIR, exist_ok=True)
|
||||
written = set()
|
||||
if on and os.path.isdir(SYSTEM_DIR):
|
||||
for name in sorted(os.listdir(SYSTEM_DIR)):
|
||||
if not name.endswith(".desktop") or SKIP.match(name):
|
||||
continue
|
||||
target = os.path.join(USER_DIR, name)
|
||||
# A copy the user made or edited themselves is theirs.
|
||||
if os.path.exists(target) and not ours(target):
|
||||
continue
|
||||
try:
|
||||
with open(os.path.join(SYSTEM_DIR, name), encoding="utf-8", errors="replace") as f:
|
||||
text = wrap(f.read())
|
||||
except OSError:
|
||||
continue
|
||||
if text is None:
|
||||
continue
|
||||
with open(target + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
os.replace(target + ".tmp", target)
|
||||
written.add(name)
|
||||
removed = 0
|
||||
for name in os.listdir(USER_DIR):
|
||||
path = os.path.join(USER_DIR, name)
|
||||
if name.endswith(".desktop") and name not in written and ours(path):
|
||||
os.remove(path)
|
||||
removed += 1
|
||||
print(f"droiddeck-desktop-gpu: {'on' if on else 'off'}, {len(written)} entries on the GPU, {removed} removed")
|
||||
|
||||
|
||||
main()
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# Runs a program from the desktop on the GPU: in a gamescope of its own that draws straight into
|
||||
# the app's compositor (wayland-0), not inside labwc. The desktop is composited by pixman, and
|
||||
# pixman gives its windows no DMA-BUFs - a Vulkan program there fails at its swapchain
|
||||
# (VK_ERROR_SURFACE_LOST, RPCS3's error). Here it gets the same path as a program started from the
|
||||
# app's rail: full screen over the desktop until it exits, then the desktop is back.
|
||||
# droiddeck-gpu <program> [args...]
|
||||
set -u
|
||||
[ $# -gt 0 ] || { echo "usage: droiddeck-gpu <program> [args...]" >&2; exit 64; }
|
||||
if [ -n "${BL_DEBUG_DIR:-}" ]; then
|
||||
exec >>"$BL_DEBUG_DIR/desktop.log" 2>&1
|
||||
fi
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
fi
|
||||
[ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled)
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
# gamescope is a client of the app's compositor, beside labwc; the program inside it reaches it
|
||||
# through gamescope's own Xwayland, as in a Steam session.
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11
|
||||
# AppImages cannot mount under proot; the menu entries already say so, a hand-typed one may not.
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
gamescope "${args[@]}" -- "$@"
|
||||
rc=$?
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc"
|
||||
exit $rc
|
||||
Reference in new issue
Block a user