From d0ca41d160d3862c7deb83ed685acb73021f51db Mon Sep 17 00:00:00 2001 From: The412Banner Date: Tue, 22 Sep 2026 09:46:19 -0400 Subject: [PATCH] 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. --- README.md | 12 ++ .../com/steamdeck/launcher/SessionActivity.kt | 17 ++- .../launcher/session/SessionFiles.kt | 2 + .../launcher/session/SessionService.kt | 60 +++++++++- .../launcher/session/SessionState.kt | 5 + tools/linuxfs/desktop/steamdeck-desktop | 5 + .../usr/local/bin/bannerlator-desktop-games | 109 ++++++++++++++++++ .../overlay/usr/local/bin/bannerlator-session | 8 +- .../usr/local/bin/bannerlator-steam-launch | 28 +++++ 9 files changed, 240 insertions(+), 6 deletions(-) create mode 100755 tools/linuxfs/overlay/usr/local/bin/bannerlator-desktop-games create mode 100755 tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch diff --git a/README.md b/README.md index b247ab1941..ec3b4eb86e 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ ledger rather than a feature list — where something has not been run on hardwa | Emulators launched under gamescope (▶ in Desktop & apps) | ⚠️ built; not yet seen with a game | | The device's volume keys during a session | ⚠️ fixed (they were swallowed); not yet re-tried | | Game storage: a second Steam library on a card or a folder | ⚠️ built; not yet seen installing to it | +| The client's games in the desktop menu, launching Steam's desktop UI under gamescope | ⚠️ built; not yet tried | | Stopping a competing Steam client | ⚠️ it is asked to stop and says so, but one that restarts itself from boot wins the race — uninstall it | | DirectAudio for games, and the microphone | ⚠️ wired and the modules load; voice not yet confirmed in Steam's tester | | Client and game core masks | ⚠️ applied and logged; no measured difference yet | @@ -185,6 +186,17 @@ page and moves games between them itself. Set to internal only, the entry is rem card and shared storage are FUSE-backed and stream slowly - keep games that stream video or big assets internal. ⚠️ Built; not yet seen installing to a card. +### The client's games on the desktop + +The desktop's menu lists every game the Steam client has installed (Games category, the game's +own artwork), and the home folder has **Steam Games** and **SD Games** links to their files. A +game entry - and the menu's **Steam** / **Steam Big Picture** entries - cannot run the client on +the desktop, where nothing can draw with Vulkan; they hand off to the app +(`bannerlator-steam-launch`), which ends the desktop session and starts a Steam session in its +place: the client's **desktop UI** under gamescope, and the game straight away when one was +chosen. Back opens the drawer as in any session; Stop session returns to the app. The list is +rebuilt at every desktop start. ⚠️ Built; not yet tried on a device. + ### Running an emulator with the GPU The desktop composites in software (labwc on pixman) and so offers its programs no dma-buf: a diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index dc282ae4f4..7679b8aa42 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -338,6 +338,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { SessionService.start( this, intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM, intent.getStringExtra(SessionService.EXTRA_PROGRAM), + intent.getStringExtra(SessionService.EXTRA_STEAM_UI), + intent.getStringExtra(SessionService.EXTRA_STEAM_URL), ) } applyFrameGen() @@ -436,7 +438,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun onSessionEnded(status: Int) { if (status == 0) { - runOnUiThread { if (!isFinishing && !isDestroyed) finish() } + runOnUiThread { + if (isFinishing || isDestroyed) return@runOnUiThread + // A session the guest asked for (the desktop's Steam launchers) takes this one's + // place: the compositor stays, a new activity attaches and starts the service. + SessionState.relaunch?.let { next -> + SessionState.relaunch = null + startActivity(next) + } + finish() + } return } // What the log says about why, read off the main thread (notifyEnded arrives on it). @@ -590,14 +601,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { cursorPos = androidx.compose.ui.geometry.Offset(x, y) cursorVisible = true uiHandler.removeCallbacks(cursorHide) - if (SessionState.mode == SessionService.MODE_STEAM) uiHandler.postDelayed(cursorHide, 2500) + if (SessionState.mode == SessionService.MODE_STEAM && SessionState.steamUi != "desktop") uiHandler.postDelayed(cursorHide, 2500) } /** Touchpad on the desktop, direct in Steam, unless the drawer says otherwise. */ private fun usingTouchpad(): Boolean = when (SessionPrefs.touchMode(this)) { SessionPrefs.TOUCH_PAD -> true SessionPrefs.TOUCH_DIRECT -> false - else -> SessionState.mode != SessionService.MODE_STEAM + else -> SessionState.mode != SessionService.MODE_STEAM || SessionState.steamUi == "desktop" } /** The picture's rectangle inside the view: where the pointer may go. */ diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt index 2ade38db07..b246eb1759 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt @@ -34,6 +34,8 @@ object SessionFiles { "usr/local/bin/bannerlator-seed-redists" to "usr/local/bin/bannerlator-seed-redists", "usr/local/bin/bannerlator-proton-extra" to "usr/local/bin/bannerlator-proton-extra", "usr/local/bin/bannerlator-netmanager" to "usr/local/bin/bannerlator-netmanager", + "usr/local/bin/bannerlator-steam-launch" to "usr/local/bin/bannerlator-steam-launch", + "usr/local/bin/bannerlator-desktop-games" to "usr/local/bin/bannerlator-desktop-games", ) // The desktop's launcher and labwc defaults, only where the desktop package is installed: // staging them into a runtime without it would make the desktop look present when it is not. diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt index 934acf390c..bda8e57407 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt @@ -67,6 +67,8 @@ class SessionService : Service() { if (SessionState.running) return START_NOT_STICKY SessionState.mode = intent?.getStringExtra(EXTRA_MODE) ?: MODE_STEAM SessionState.program = intent?.getStringExtra(EXTRA_PROGRAM) + SessionState.steamUi = intent?.getStringExtra(EXTRA_STEAM_UI) + SessionState.steamUrl = intent?.getStringExtra(EXTRA_STEAM_URL) // Another Steam client on the device signs ours out seconds after every login; the one that // does it here runs from boot without being opened. Only the Steam session signs in. if (SessionState.mode == MODE_STEAM) RivalClients.stopBeforeSession(this) @@ -288,8 +290,15 @@ class SessionService : Service() { .takeIf { it.isFile }?.let { FileUtils.readString(it)?.trim() } guest.add("BL_WLR_RENDERER=" + (override?.takeIf { it.isNotEmpty() } ?: SessionPrefs.desktopRenderer(this))) } + // Where the guest leaves a request for another session (the desktop's Steam launchers). + guest.add("BL_LAUNCH_DIR=" + sessionRoot.path) + if (SessionState.mode == MODE_STEAM && SessionState.steamUi == "desktop") guest.add("BL_STEAM_UI=desktop") guest.add(LinuxRuntime.SESSION_SCRIPT) guest.add(SessionState.mode) + if (SessionState.mode == MODE_STEAM) SessionState.steamUrl?.takeIf { it.startsWith("steam://") }?.let { + guest.add(it) + Log.i(TAG, "steam: handing the client $it") + } // A program under gamescope: the script's run mode takes the path (an AppImage, a script // or a binary inside the runtime). This is how an emulator gets the GPU - the desktop's // labwc composites in software and offers no dma-buf, so a Vulkan swapchain cannot exist @@ -376,6 +385,7 @@ class SessionService : Service() { components.forEach { it.start() } val line = command.joinToString(" ") { it.replace(" ", "\\ ") } + watchLaunchRequests(sessionRoot) sessionPid = ProcessHelper.exec(line, hostEnv.toStringArray(), root, { status -> Log.i(TAG, "session ended: $status") stopSession(status ?: -1) @@ -468,9 +478,49 @@ class SessionService : Service() { if (killed > 0) Log.w(TAG, "killed $killed leftover process(es) of a previous session") } + /** + * The desktop's Steam launchers cannot start the client where they are (no dma-buf on the + * desktop), so they leave `steam-launch` in the session directory instead: which UI, and a + * steam:// URL or nothing. This ends the session and hands the activity the one to start. + */ + private var launchWatcher: android.os.FileObserver? = null + + private fun watchLaunchRequests(dir: File) { + launchWatcher?.stopWatching() + @Suppress("DEPRECATION") + val watcher = object : android.os.FileObserver(dir.path, CLOSE_WRITE or MOVED_TO) { + override fun onEvent(event: Int, path: String?) { + if (path != "steam-launch") return + val file = File(dir, path) + val text = try { file.readText() } catch (e: Exception) { return } + file.delete() + var ui = "desktop" + var url = "" + text.lineSequence().forEach { line -> + when { + line.startsWith("ui=") -> ui = line.removePrefix("ui=").trim() + line.startsWith("url=") -> url = line.removePrefix("url=").trim() + } + } + Log.i(TAG, "launch request from the session: Steam $ui" + (if (url.isNotEmpty()) " $url" else "")) + val next = Intent(this@SessionService, com.steamdeck.launcher.SessionActivity::class.java) + .putExtra(EXTRA_MODE, MODE_STEAM) + .putExtra(EXTRA_STEAM_UI, ui) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + if (url.isNotEmpty()) next.putExtra(EXTRA_STEAM_URL, url) + SessionState.relaunch = next + android.os.Handler(android.os.Looper.getMainLooper()).post { stopSession(0) } + } + } + watcher.startWatching() + launchWatcher = watcher + } + private fun stopSession(status: Int) { if (!SessionState.running) return SessionState.running = false + launchWatcher?.stopWatching() + launchWatcher = null // proot's --kill-on-exit takes the guest tree down only if proot gets to run it, and // SIGKILL never lets it. A SIGKILLed proot left its tracees alive with no tracer: every // seccomp-trapped syscall then failed with ENOSYS, they spun on retries at a full core @@ -626,10 +676,18 @@ class SessionService : Service() { /** A program inside the runtime, fullscreen under gamescope (EXTRA_PROGRAM = its path). */ const val MODE_RUN = "run" const val EXTRA_PROGRAM = "program" + /** MODE_STEAM: "desktop" for the client's desktop UI (default Big Picture); a steam:// URL to hand it. */ + const val EXTRA_STEAM_UI = "steamUi" + const val EXTRA_STEAM_URL = "steamUrl" - fun start(context: Context, mode: String = MODE_STEAM, program: String? = null) { + fun start( + context: Context, mode: String = MODE_STEAM, program: String? = null, + steamUi: String? = null, steamUrl: String? = null, + ) { val intent = Intent(context, SessionService::class.java).putExtra(EXTRA_MODE, mode) if (program != null) intent.putExtra(EXTRA_PROGRAM, program) + if (steamUi != null) intent.putExtra(EXTRA_STEAM_UI, steamUi) + if (steamUrl != null) intent.putExtra(EXTRA_STEAM_URL, steamUrl) if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent) else context.startService(intent) } diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt index c5dafa7a4f..41b83fce21 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt @@ -12,6 +12,11 @@ object SessionState { var running = false /** MODE_RUN: the program inside the runtime the session was started for. */ var program: String? = null + /** MODE_STEAM: "desktop" for the client's desktop UI, else Big Picture; and a steam:// URL to hand it. */ + var steamUi: String? = null + var steamUrl: String? = null + /** A session the guest asked for (the desktop's Steam launchers): started by the activity once this one has ended. */ + var relaunch: android.content.Intent? = null /** HDR10 was asked for and the panel can show it: the compositor was told, and the session * gets DXVK_HDR=1 and gamescope --hdr-enabled. Decided by the activity before the compositor starts. */ @JvmStatic var hdr = false diff --git a/tools/linuxfs/desktop/steamdeck-desktop b/tools/linuxfs/desktop/steamdeck-desktop index e420d27ffd..be8bc5e676 100644 --- a/tools/linuxfs/desktop/steamdeck-desktop +++ b/tools/linuxfs/desktop/steamdeck-desktop @@ -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 diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-desktop-games b/tools/linuxfs/overlay/usr/local/bin/bannerlator-desktop-games new file mode 100755 index 0000000000..aa65144608 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-desktop-games @@ -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() diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index c44efcbb41..edbb40fbf2 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -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=$? diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch new file mode 100755 index 0000000000..ad08ce0769 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch @@ -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})"