The client's games on the desktop, launching Steam's desktop UI under gamescope

bannerlator-desktop-games writes one menu entry per installed game (both libraries, the
client's own artwork) and links Steam Games / SD Games in the home folder. The entries, and the
menu's Steam / Big Picture ones, run bannerlator-steam-launch: the client cannot draw on the
desktop (labwc, no dma-buf), so it leaves a request in the session directory; the service
watches it (FileObserver), ends the desktop session and hands the activity a Steam session to
start - desktop UI (BL_STEAM_UI=desktop drops -gamepadui) with the game's rungameid URL.
This commit is contained in:
The412Banner committed 2026-09-22 09:46:19 -04:00
1 parent 1374091d1b
commit d0ca41d160
9 files changed
+240 -6

No files matched your search

+5
View File
@@ -79,6 +79,11 @@ if [ ! -f /var/cache/fontconfig/.steamdeck-built ] && command -v fc-cache >/dev/
fc-cache -f >/dev/null 2>&1 && touch /var/cache/fontconfig/.steamdeck-built
echo "== fontconfig: cache rebuilt, default sans is $(fc-match sans-serif 2>/dev/null)"
fi
# The menu's "Steam" / "Steam Big Picture" entries and one entry per installed game: all of them
# hand off to the app (bannerlator-steam-launch), since the client cannot draw on this desktop.
ln -sf /usr/local/bin/bannerlator-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null
python3 /usr/local/bin/bannerlator-desktop-games 2>&1 | sed 's/^/[games] /'
echo "== steamdeck-desktop: labwc ($WLR_RENDERER) on $WAYLAND_DISPLAY"
# ~/.steamdeck-desktop-debug: labwc's own debug log (views and layer surfaces mapping) too.
DEBUG=; [ -f "$HOME/.steamdeck-desktop-debug" ] && DEBUG=-d
@@ -0,0 +1,109 @@
#!/usr/bin/python3
# The client's installed games, on the desktop: one menu entry per game (Games category), which
# starts it through bannerlator-steam-launch in Steam's desktop UI under gamescope, and two links
# in the home folder to the game files themselves. Run at every desktop start; stale entries go.
#
# bannerlator-desktop-games [steam root]
import os
import re
import sys
HOME = os.environ.get("HOME", "/root")
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HOME, ".local/share/Steam")
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/bannerlator-sd", "SD Games"))
# The client's own tools and runtimes live in steamapps beside the games; they are not titles.
NOT_GAMES = {228980, 1493710, 3127680, 4183110, 4427310, 4185400}
APPS_DIR = os.path.join(HOME, ".local/share/applications")
PREFIX = "steamdeck-game-"
NAME = re.compile(r'^\s*"name"\s*"([^"]*)"', re.M)
STATE = re.compile(r'^\s*"StateFlags"\s*"(\d+)"', re.M)
def games(library):
steamapps = os.path.join(library, "steamapps")
out = []
if not os.path.isdir(steamapps):
return out
for entry in sorted(os.listdir(steamapps)):
m = re.fullmatch(r"appmanifest_(\d+)\.acf", entry)
if not m:
continue
appid = int(m.group(1))
if appid in NOT_GAMES:
continue
try:
with open(os.path.join(steamapps, entry), encoding="utf-8", errors="replace") as f:
text = f.read()
except OSError:
continue
name = NAME.search(text)
state = STATE.search(text)
# StateFlags 4 = fully installed; anything else is downloading, updating or broken.
if not name or not state or (int(state.group(1)) & 4) == 0:
continue
out.append((appid, name.group(1)))
return out
def icon_for(appid):
cache = os.path.join(STEAM_ROOT, "appcache/librarycache", str(appid))
for candidate in ("logo.png", "library_600x900.jpg", "header.jpg"):
path = os.path.join(cache, candidate)
if os.path.isfile(path):
return path
return "steam"
def write_entries():
os.makedirs(APPS_DIR, exist_ok=True)
wanted = {}
for library, _ in LIBRARIES:
for appid, name in games(library):
wanted.setdefault(appid, name)
for entry in os.listdir(APPS_DIR):
if entry.startswith(PREFIX) and entry.endswith(".desktop"):
appid = entry[len(PREFIX):-len(".desktop")]
if not appid.isdigit() or int(appid) not in wanted:
os.unlink(os.path.join(APPS_DIR, entry))
for appid, name in wanted.items():
safe = name.replace("\n", " ").strip() or str(appid)
body = (
"[Desktop Entry]\nType=Application\nName=%s\nComment=Steam game %d - opens in Steam under gamescope\n"
"Exec=/usr/local/bin/bannerlator-steam-launch desktop %d\nIcon=%s\nTerminal=false\n"
"Categories=Game;\nX-SteamDeck-AppId=%d\n" % (safe, appid, appid, icon_for(appid), appid)
)
path = os.path.join(APPS_DIR, "%s%d.desktop" % (PREFIX, appid))
try:
with open(path, encoding="utf-8") as f:
if f.read() == body:
continue
except OSError:
pass
with open(path, "w", encoding="utf-8") as f:
f.write(body)
return wanted
def link_libraries():
for library, label in LIBRARIES:
common = os.path.join(library, "steamapps", "common")
link = os.path.join(HOME, label)
if os.path.isdir(common):
if os.path.islink(link) and os.readlink(link) == common:
continue
if os.path.islink(link) or os.path.isfile(link):
os.unlink(link)
if not os.path.exists(link):
os.symlink(common, link)
elif os.path.islink(link):
os.unlink(link)
def main():
wanted = write_entries()
link_libraries()
print("bannerlator-desktop-games: %d game(s) on the desktop menu" % len(wanted))
if __name__ == "__main__":
main()
@@ -319,9 +319,13 @@ BUSCONF
# FEX_ROOTFS names it outright and is read whatever the config situation.
[ -d /usr/share/guestos/fex-mesa ] && export FEX_ROOTFS=/usr/share/guestos/fex-mesa
# The client exits 42 when it has updated itself and wants a fresh start (steam.sh does this).
# BL_STEAM_UI=desktop = the client's desktop UI (a window, the library as a list), which the
# desktop's launchers ask for; gamescope shows one window at a time and the game takes over.
_bl_ui=(-gamepadui)
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
while :; do
step "starting the Steam client"
"$steam_root/steamrtarm64/steam" -gamepadui -clientbeta publicbeta \
step "starting the Steam client${BL_STEAM_UI:+ ($BL_STEAM_UI UI)}"
"$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" -clientbeta publicbeta \
-no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 \
-cef-use-gl=angle -cef-use-angle=vulkan "$@"
rc=$?
@@ -0,0 +1,28 @@
#!/bin/bash
# Asks the app to start the Steam client, from inside a session (the desktop's menu entries and
# the per-game launchers bannerlator-desktop-games writes):
# bannerlator-steam-launch desktop [appid|steam-url] Steam's desktop UI, optionally a game
# bannerlator-steam-launch bigpicture [appid|steam-url] Big Picture
# The client cannot run on the desktop: labwc composites in software and offers no dma-buf, so a
# game (or the client's own Vulkan window) would die at its first frame. It runs under gamescope,
# which is a session of its own - so this writes a request into the directory the app watches,
# and the app ends the desktop session and starts a Steam session in its place.
set -u
ui=${1:-desktop}
target=${2:-}
case $ui in desktop|bigpicture) ;; *) echo "usage: $0 desktop|bigpicture [appid|steam://url]" >&2; exit 64 ;; esac
url=
case $target in
"") ;;
steam://*) url=$target ;;
*[!0-9]*) echo "not an app id or steam:// URL: $target" >&2; exit 64 ;;
*) url=steam://rungameid/$target ;;
esac
dir=${BL_LAUNCH_DIR:-}
if [ -z "$dir" ] || [ ! -d "$dir" ]; then
echo "bannerlator-steam-launch: not inside a SteamDeck session (BL_LAUNCH_DIR unset)" >&2
exit 69
fi
# Written whole, then renamed: the app reads it on close, never half-written.
printf 'ui=%s\nurl=%s\n' "$ui" "$url" > "$dir/steam-launch.tmp" && mv -f "$dir/steam-launch.tmp" "$dir/steam-launch"
echo "bannerlator-steam-launch: asked the app for Steam ($ui${url:+, $url})"