From 5f1b102e328712cd4b21f4622cc5c9cdd30a5850 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 06:49:03 -0400 Subject: [PATCH 1/5] fix: give the guest a short XDG_RUNTIME_DIR so gamescope starts with the app on adopted storage --- .../com/droiddeck/launcher/runtime/GuestCommand.kt | 2 +- .../droiddeck/launcher/runtime/LinuxRuntime.java | 13 ++++++++++++- .../droiddeck/launcher/session/SessionService.kt | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt index d420d5771d..16d20ba5db 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/GuestCommand.kt @@ -44,7 +44,7 @@ object GuestCommand { .forEach { cmd.add("-b"); cmd.add(it) } cmd += listOf( "/usr/bin/env", "-i", "HOME=/root", "USER=root", "LANG=C.UTF-8", - "PATH=/usr/local/bin:/usr/bin:/bin", "XDG_RUNTIME_DIR=${runtimeDir.path}", + "PATH=/usr/local/bin:/usr/bin:/bin", "XDG_RUNTIME_DIR=${LinuxRuntime.GUEST_RUNTIME_DIR}", "XDG_DATA_HOME=/root/.local/share", "FLATPAK_BWRAP=${FlatpakManager.BWRAP}", "XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share:/usr/local/share:/usr/share", ) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index 6ad52da27f..3b2a7a80a5 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -34,6 +34,14 @@ public final class LinuxRuntime { /** Shortcut extra naming which of the modes above a Linux entry launches. */ public static final String EXTRA_LINUX_MODE = "linux_mode"; private static final String KGSL_DEVICE = "/dev/kgsl-3d0"; + /** + * Where the guest sees a command's XDG_RUNTIME_DIR. A Unix socket's path must fit in 108 bytes, + * and libwayland checks the guest's path before proot ever sees it: with the app on an SD card + * adopted as internal storage the files directory is /mnt/expand//user/0//files, + * and gamescope-0 under it is one byte over, so gamescope could not open its socket and the + * session ended at once. A long host path behind it is proot's to shorten. + */ + public static final String GUEST_RUNTIME_DIR = "/run/droiddeck"; /** Where every Linux session's debug log lands: public, so a user can just hand the folder over. */ public static final String DEBUG_LOG_DIR = "DroidDeck"; @@ -185,7 +193,10 @@ public final class LinuxRuntime { bind(cmd, new File(root, "etc/bannerlator/empty").getPath() + ":/sys/fs/selinux"); bind(cmd, context.getFilesDir().getPath()); bind(cmd, context.getCacheDir().getPath()); - if (runtimeDir != null) bind(cmd, runtimeDir.getPath()); + if (runtimeDir != null) { + bind(cmd, runtimeDir.getPath()); + bind(cmd, runtimeDir.getPath() + ":" + GUEST_RUNTIME_DIR); + } if (sessionRoot != null) bind(cmd, sessionRoot.getPath()); if (externalStorage != null && externalStorage.isDirectory()) { bind(cmd, externalStorage.getPath()); diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 2bca7f669c..f1c43c2362 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -277,7 +277,7 @@ class SessionService : Service() { // The desktop's Steam launchers start the client there (bannerlator-steam-launch), through the // same set-up as a Steam session: it gets what the client and its games are started with. val steamHere = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP - addClientEnvironment(guest, runtimeDir, steamHere) + addClientEnvironment(guest, steamHere) val pulse = startAudio(guest, sessionDir) @@ -483,7 +483,7 @@ class SessionService : Service() { } /** The guest's base environment: paths, the display, the GL/Vulkan stack and the client's switches. */ - private fun addClientEnvironment(guest: MutableList, runtimeDir: File, steamHere: Boolean) { + private fun addClientEnvironment(guest: MutableList, steamHere: Boolean) { guest.add("/usr/bin/env") guest.add("-i") guest.add("HOME=/root") @@ -494,7 +494,7 @@ class SessionService : Service() { // Without this the session is UTC: the client's clock, its logs and every timestamp in a // session bundle sit hours off the device's. Bannerlator carries the same line. guest.add("TZ=" + java.util.TimeZone.getDefault().id) - guest.add("XDG_RUNTIME_DIR=" + runtimeDir.path) + guest.add("XDG_RUNTIME_DIR=" + LinuxRuntime.GUEST_RUNTIME_DIR) guest.add("XDG_SESSION_TYPE=wayland") guest.add("WAYLAND_DISPLAY=wayland-0") guest.add("GAMESCOPE_FORCE_GENERAL_QUEUE=1") From e8c69a89a2710651c9a108659b10075b4436533e Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 14:31:30 -0400 Subject: [PATCH 2/5] fix: keep the game running behind the Steam menu and QAM, as on a Steam Deck --- tools/gamescope/PATCHES.md | 7 ++ ...am-overlay-keeps-game-keyboard-focus.patch | 70 +++++++++++++++++++ .../overlay/usr/local/bin/bannerlator-session | 2 + 3 files changed, 79 insertions(+) create mode 100644 tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index ad4fc4b348..6d0c1a1190 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -39,5 +39,12 @@ library list, before anything is published. then focus is handed over again. `GAMESCOPE_RESTORE_FOCUS_WINDOW` on the root window asks for the same restore from outside (the session script's resume watcher). +- `0113-steam-overlay-keeps-game-keyboard-focus.patch` - this app: the Steam client opens the Quick + Access Menu and Steam menu over a game with `STEAM_INPUT_FOCUS` 1, which moves X keyboard focus to + its overlay; wine then deactivates the game and a fullscreen game minimizes itself, freezing + behind the menu instead of running on as on a Steam Deck. Steam's own overlay taking input now + keeps keyboard focus on the game, as mode 2 does; its input comes from the controller through + Steam Input, not the X keyboard. + Sixteen more of Armada's patches are DRM/lease/HDR-on-KMS work for a native display, which this app's Wayland-hosted gamescope never reaches, or need a newer gamescope than the runtime has. diff --git a/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch b/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch new file mode 100644 index 0000000000..9a09e26c85 --- /dev/null +++ b/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch @@ -0,0 +1,70 @@ +From: DroidDeck +Subject: [PATCH] steamcompmgr: keep the game's keyboard focus under Steam's overlay + +The Steam client opens its Quick Access Menu and Steam menu over a game by setting +STEAM_OVERLAY 1 and STEAM_INPUT_FOCUS 1 on its window. Mode 1 moves X keyboard focus to the +overlay, so the game's window gets FocusOut: wine moves the foreground to the desktop, a fullscreen +game deactivates and minimizes itself (WM_CHANGE_STATE IconicState), and it stops rendering behind +the menu - frozen, all threads asleep, until the menu closes (Alan Wake's American Nightmare, +Proton Experimental ARM64). On a Steam Deck the game runs on behind the menu. + +Mode 2 already means "input to the overlay, keyboard focus stays on the focus window". Treat +Steam's own overlay taking input in mode 1 the same way at the three places mode 2 is honoured. +The overlay's input does not need X keyboard focus: the controller drives it through Steam Input. +Measured by rewriting the property to 2 by hand: the game kept running behind the menu and the +controller still moved only the menu. + +diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp +index 372a82c..f870974 100644 +--- a/src/steamcompmgr.cpp ++++ b/src/steamcompmgr.cpp +@@ -1321,6 +1321,22 @@ window_is_steam( steamcompmgr_win_t *w ) + return w && ( w->isSteamLegacyBigPicture || w->appID == 769 ); + } + ++// Whether keyboard focus stays on the focus window while this window has input focus. ++// STEAM_INPUT_FOCUS 2 asks for that. The Steam client also opens its Quick Access Menu and Steam ++// menu over a game with 1, which moves X keyboard focus to the overlay: wine then deactivates the ++// game, a fullscreen game minimizes itself, and it froze behind the menu instead of running on as ++// on a Steam Deck. The overlay's own input does not need X keyboard focus (the controller drives ++// it through Steam Input), so Steam's overlay keeps the game's keyboard focus too. ++static bool ++window_keeps_game_keyboard_focus( steamcompmgr_win_t *w ) ++{ ++ if ( !w ) ++ return false; ++ if ( w->inputFocusMode == 2 ) ++ return true; ++ return w->inputFocusMode == 1 && w->isOverlay && window_is_steam( w ); ++} ++ + static bool + window_is_vr_scene_app( steamcompmgr_win_t *w ) + { +@@ -4728,7 +4744,7 @@ void xwayland_ctx_t::DetermineAndApplyFocus( const std::vector< steamcompmgr_win + + if ( gamescope::VirtualConnectorIsSingleOutput() ) + { +- if ( inputFocus && inputFocus->inputFocusMode == 2 ) ++ if ( window_keeps_game_keyboard_focus( inputFocus ) ) + keyboardFocusWin = ctx->focus.focusWindow; + } + else +@@ -5340,7 +5356,7 @@ determine_and_apply_focus( global_focus_t *pFocus ) + pFocus->inputFocusMode = pFocus->inputFocusWindow->inputFocusMode; + + if ( gamescope::VirtualConnectorIsSingleOutput() && +- pFocus->inputFocusMode == 2 ) ++ window_keeps_game_keyboard_focus( pFocus->inputFocusWindow ) ) + { + pFocus->keyboardFocusWindow = pFocus->overrideWindow + ? pFocus->overrideWindow +@@ -6485,7 +6501,7 @@ handle_wl_surface_id(xwayland_ctx_t *ctx, steamcompmgr_win_t *w, uint32_t surfac + steamcompmgr_win_t *keyboardFocusWindow = pCurrentFocus->inputFocusWindow; + + if ( gamescope::VirtualConnectorIsSingleOutput() && +- keyboardFocusWindow && keyboardFocusWindow->inputFocusMode == 2 ) ++ window_keeps_game_keyboard_focus( keyboardFocusWindow ) ) + keyboardFocusWindow = pCurrentFocus->focusWindow; + + if ( w == keyboardFocusWindow ) diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index 1f55e3089d..cb65953400 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -172,6 +172,8 @@ if [ -z "${BL_INSIDE:-}" ]; then # HDR10: the app opened its compositor's colour-management gate for this session (BL_HDR=1); # gamescope then offers HDR to its clients through the same wp_color_manager_v1 it binds on ours. [ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled) + # Extra gamescope arguments for an experiment (--debug-focus, say), from Download/droiddeck-env. + [ -n "${BL_GAMESCOPE_ARGS:-}" ] && read -r -a _bl_extra <<<"$BL_GAMESCOPE_ARGS" && args+=("${_bl_extra[@]}") # Deck mode's performance overlay (Quick Access Menu → Performance → Overlay Level) is drawn by # mangoapp, which gamescope starts beside the client; the client sets the level by rewriting # MANGOHUD_CONFIGFILE. The apk stages Valve's aarch64 build (tools/mangoapp) - without it the menu From df7ba1fead0e47760bbb46c82f1e83381acf0c57 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 14:43:30 -0400 Subject: [PATCH 3/5] fix: skip the pointer warps that jolted the game as the QAM opened and closed --- tools/gamescope/PATCHES.md | 3 +- ...am-overlay-keeps-game-keyboard-focus.patch | 40 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index 6d0c1a1190..1952e6c9b6 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -44,7 +44,8 @@ library list, before anything is published. its overlay; wine then deactivates the game and a fullscreen game minimizes itself, freezing behind the menu instead of running on as on a Steam Deck. Steam's own overlay taking input now keeps keyboard focus on the game, as mode 2 does; its input comes from the controller through - Steam Input, not the X keyboard. + Steam Input, not the X keyboard. The pointer warps gamescope makes as input moves to Steam and + back are skipped around it, since the game - still taking input - saw them as a mouse jump. Sixteen more of Armada's patches are DRM/lease/HDR-on-KMS work for a native display, which this app's Wayland-hosted gamescope never reaches, or need a newer gamescope than the runtime has. diff --git a/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch b/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch index 9a09e26c85..08ef94074c 100644 --- a/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch +++ b/tools/gamescope/patches/0113-steam-overlay-keeps-game-keyboard-focus.patch @@ -14,8 +14,14 @@ The overlay's input does not need X keyboard focus: the controller drives it thr Measured by rewriting the property to 2 by hand: the game kept running behind the menu and the controller still moved only the menu. +With the game keeping focus, the pointer resets gamescope makes when input moves to Steam (warp +to the centre, park in the corner) and back (warp to the centre) reached it as a sudden mouse +move: a mouse-look camera spun every time the menu opened and closed. Skip them while Steam's +overlay opens over a game that keeps focus, and as it closes - by then the overlay has dropped its +STEAM_INPUT_FOCUS, so whether the opening kept focus is remembered. + diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp -index 372a82c..f870974 100644 +index 372a82c..3fab3c6 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -1321,6 +1321,22 @@ window_is_steam( steamcompmgr_win_t *w ) @@ -50,7 +56,35 @@ index 372a82c..f870974 100644 keyboardFocusWin = ctx->focus.focusWindow; } else -@@ -5340,7 +5356,7 @@ determine_and_apply_focus( global_focus_t *pFocus ) +@@ -4834,12 +4850,26 @@ void xwayland_ctx_t::DetermineAndApplyFocus( const std::vector< steamcompmgr_win + if ( ctx->focus.inputFocusWindow != inputFocus || + ctx->focus.inputFocusMode != inputFocus->inputFocusMode ) + { ++ // Steam's overlay opening over a game, or closing again, while the game keeps keyboard focus ++ // (window_keeps_game_keyboard_focus): the game is still taking input, so a pointer warp ++ // reaches it as a sudden mouse move - the camera of a mouse-look game spun as the Quick ++ // Access Menu opened and as it closed. The overlay is driven by the controller and the ++ // cursor is hidden, so leave the pointer where it is. Closing, the overlay has already ++ // dropped its STEAM_INPUT_FOCUS, so whether the opening kept focus is remembered. ++ static bool s_bOverlayKeptGameFocus = false; ++ bool bOverlayKeepsGameFocus = window_keeps_game_keyboard_focus( inputFocus ) && ++ ctx->focus.focusWindow && !window_is_steam( ctx->focus.focusWindow ); ++ bool bSkipPointerReset = bOverlayKeepsGameFocus || s_bOverlayKeptGameFocus; ++ s_bOverlayKeptGameFocus = bOverlayKeepsGameFocus; ++ + // If the window doesn't want focus when hidden, move it away + // as we are going to hide it straight after. + // otherwise, if we switch from wanting it to not + // (steam -> game) + // put us back in the centre of the screen. +- if (window_wants_no_focus_when_mouse_hidden(inputFocus)) ++ if ( bSkipPointerReset ) ++ ; ++ else if (window_wants_no_focus_when_mouse_hidden(inputFocus)) + ctx->focus.bResetToCorner = true; + else if ( window_wants_no_focus_when_mouse_hidden(inputFocus) != window_wants_no_focus_when_mouse_hidden(ctx->focus.inputFocusWindow) ) + ctx->focus.bResetToCenter = true; +@@ -5340,7 +5370,7 @@ determine_and_apply_focus( global_focus_t *pFocus ) pFocus->inputFocusMode = pFocus->inputFocusWindow->inputFocusMode; if ( gamescope::VirtualConnectorIsSingleOutput() && @@ -59,7 +93,7 @@ index 372a82c..f870974 100644 { pFocus->keyboardFocusWindow = pFocus->overrideWindow ? pFocus->overrideWindow -@@ -6485,7 +6501,7 @@ handle_wl_surface_id(xwayland_ctx_t *ctx, steamcompmgr_win_t *w, uint32_t surfac +@@ -6485,7 +6515,7 @@ handle_wl_surface_id(xwayland_ctx_t *ctx, steamcompmgr_win_t *w, uint32_t surfac steamcompmgr_win_t *keyboardFocusWindow = pCurrentFocus->inputFocusWindow; if ( gamescope::VirtualConnectorIsSingleOutput() && From 33fe6edd0d4e92f30be4f26e9397851182609dad Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 14:53:28 -0400 Subject: [PATCH 4/5] chore: stage gamescope-3.16.29-p5 --- tools/gamescope/release.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/gamescope/release.env b/tools/gamescope/release.env index af715c6712..55f3940d87 100644 --- a/tools/gamescope/release.env +++ b/tools/gamescope/release.env @@ -1,2 +1,2 @@ -GAMESCOPE_TAG=gamescope-3.16.29-p4 -GAMESCOPE_SHA256=e750fb34864bc2eb1160aeed29593e402bf9c8153fafd9fd18c77450bdd50574 +GAMESCOPE_TAG=gamescope-3.16.29-p5 +GAMESCOPE_SHA256=188144e5564e020d0bc485a1f4f90e1c5fd61d0d1d6dd29db21e8b019036a5c6 From 68ce64dea6a6b7898fbc5d592c4e415a9ad67029 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Thu, 1 Oct 2026 16:11:19 -0400 Subject: [PATCH 5/5] Keep secondary-library prefixes and Steam tools on private storage --- .../droiddeck/launcher/frontend/Library.kt | 7 +- .../launcher/session/SecondaryLibrary.kt | 94 +++++++++++++++++++ .../launcher/session/SessionService.kt | 9 +- .../launcher/session/SecondaryLibraryTest.kt | 76 +++++++++++++++ .../usr/local/bin/bannerlator-steam-compat | 10 +- 5 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/session/SecondaryLibraryTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt index 80b8091bee..f4952db752 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -5,6 +5,7 @@ import com.droiddeck.launcher.R import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.session.GameStorage import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.session.SecondaryLibrary import java.io.File /** @@ -84,7 +85,11 @@ object Library { /** Proton keeps each game's prefix below compatdata//pfx in a Steam library. */ fun protonPrefix(context: Context, appId: Long, preferredLibrary: File? = null): File? { val ids = listOf(appId.toString(), java.lang.Integer.toString(appId.toInt())).distinct() - val roots = (listOfNotNull(preferredLibrary) + steamLibraries(context).map { it.first }) + val secondary = GameStorage.effective(context)?.let { File(it.path) } + fun prefixRoot(root: File): File = if (secondary != null && root.canonicalPath == secondary.canonicalPath) + SecondaryLibrary.privateRoot(context.filesDir, root).takeIf { File(it, "steamapps/compatdata").isDirectory } ?: root + else root + val roots = (listOfNotNull(preferredLibrary) + steamLibraries(context).map { it.first }).map(::prefixRoot) .distinctBy { runCatching { it.canonicalPath }.getOrDefault(it.absolutePath) } return roots.asSequence() .flatMap { root -> ids.asSequence().map { id -> File(root, "steamapps/compatdata/$id/pfx") } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt b/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt new file mode 100644 index 0000000000..78760a5fba --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/SecondaryLibrary.kt @@ -0,0 +1,94 @@ +package com.droiddeck.launcher.session + +import java.io.File +import java.nio.file.Files +import java.nio.file.LinkOption.NOFOLLOW_LINKS +import java.nio.file.StandardCopyOption.COPY_ATTRIBUTES +import java.security.MessageDigest +import java.util.Locale + +/** Android shared storage cannot create the links in Wine prefixes or native Steam depots. */ +object SecondaryLibrary { + private val bootstrapTools = linkedMapOf( + "4185400" to "SteamLinuxRuntime_4-arm64", + "4427310" to "Proton Experimental (ARM64)", + "4628740" to "Proton 11.0 (ARM64)", + ) + + fun privateRoot(files: File, library: File): File { + val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray()) + .joinToString("") { "%02x".format(it.toInt() and 255) } + return File(files, "steam-libraries/$digest") + } + + /** Parent binds come first; the more specific private directories override them in PRoot. */ + fun binds(files: File, library: File): List { + val private = privateRoot(files, library) + val apps = File(library, "steamapps") + val tools = LinkedHashMap(bootstrapTools) + // Include other installed Proton/runtime versions, without routing ordinary game depots. + apps.listFiles()?.filter { it.name.matches(Regex("appmanifest_\\d+\\.acf")) }?.forEach { manifest -> + val text = manifest.readText() + val id = Regex("\"appid\"\\s+\"(\\d+)\"").find(text)?.groupValues?.get(1) + val dir = Regex("\"installdir\"\\s+\"([^\"]+)\"").find(text)?.groupValues?.get(1) + if (id != null && dir != null && File(dir).name == dir && + (dir.startsWith("Proton ") || dir.startsWith("SteamLinuxRuntime"))) tools[id] = dir + } + val overrides = ArrayList>() + for (name in listOf("compatdata", "shadercache")) { + val target = File(private, "steamapps/$name") + migrate(File(apps, name), target) + overrides.add(target to "steamapps/$name") + } + for ((id, dir) in tools) { + for (relative in listOf("steamapps/common/$dir", "steamapps/downloading/$id")) { + val target = File(private, relative) + migrate(File(library, relative), target) + // FUSE discarded the executable bits. Steam will restore the depot's exact modes + // on verification; its launchers must already be executable when importing it. + target.walkTopDown().filter { it.isFile }.forEach { it.setExecutable(true, true) } + overrides.add(target to relative) + // Steam normalizes depot install directories to lowercase on Android's + // case-insensitive shared storage. PRoot binds are case-sensitive, so both + // spellings must reach the same private directory during the commit. + val lower = relative.lowercase(Locale.ROOT) + if (lower != relative) overrides.add(target to lower) + } + } + return listOf("/mnt/droiddeck-sd", "/mnt/bannerlator-sd").flatMap { guest -> + listOf("${library.path}:$guest") + overrides.map { (host, relative) -> "${host.path}:$guest/$relative" } + } + } + + /** Copy once into a staging directory; retain the source and never merge over a live prefix. */ + private fun migrate(source: File, target: File) { + val migrated = File(target.parentFile, ".${target.name}.migrated") + if (target.isDirectory) { + if (!migrated.isFile) migrated.writeText(source.canonicalPath) + return + } + check(target.parentFile!!.isDirectory || target.parentFile!!.mkdirs()) { "cannot create ${target.parent}" } + if (!source.isDirectory || migrated.isFile) { + check(target.mkdirs()) { "cannot create $target" } + if (!migrated.isFile) migrated.writeText(source.canonicalPath) + return + } + val stage = File(target.parentFile, "${target.name}.migrating") + check(!stage.exists() || stage.deleteRecursively()) { "cannot clear $stage" } + check(stage.mkdirs()) { "cannot create $stage" } + try { + Files.walk(source.toPath()).use { paths -> + paths.forEach { path -> + val destination = stage.toPath().resolve(source.toPath().relativize(path)) + if (Files.isDirectory(path, NOFOLLOW_LINKS)) Files.createDirectories(destination) + else Files.copy(path, destination, NOFOLLOW_LINKS, COPY_ATTRIBUTES) + } + } + check(stage.renameTo(target)) { "cannot finish migration to $target" } + migrated.writeText(source.canonicalPath) + } catch (e: Exception) { + stage.deleteRecursively() + throw e + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 17eb197dd1..f9d798a7ff 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -736,11 +736,14 @@ class SessionService : Service() { val problem = GameStorage.prepare(library.path) if (problem == null) { File(LinuxRuntime.rootDir(this), "mnt/droiddeck-sd").mkdirs() - binds.add("${library.path}:/mnt/droiddeck-sd") // Links, prefixes and Steam entries made before the rename still name the old path. File(LinuxRuntime.rootDir(this), "mnt/bannerlator-sd").mkdirs() - binds.add("${library.path}:/mnt/bannerlator-sd") - Log.i(TAG, "game storage: ${library.path} -> /mnt/droiddeck-sd (\"${library.label}\")") + try { + binds.addAll(SecondaryLibrary.binds(filesDir, File(library.path))) + Log.i(TAG, "game storage: ${library.path} -> /mnt/droiddeck-sd (\"${library.label}\"); prefixes and native tools private") + } catch (e: Exception) { + Log.w(TAG, "game storage: private directories could not be prepared; internal only this session", e) + } } else { Log.w(TAG, "game storage: $problem; internal only this session") } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SecondaryLibraryTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SecondaryLibraryTest.kt new file mode 100644 index 0000000000..cdd553cffa --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/SecondaryLibraryTest.kt @@ -0,0 +1,76 @@ +package com.droiddeck.launcher.session + +import java.io.File +import java.nio.file.Files +import org.junit.Assert.* +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class SecondaryLibraryTest { + @get:Rule val tmp = TemporaryFolder() + + @Test fun gamesStaySharedButPrefixesAndNativeDownloadsArePrivate() { + val files = tmp.newFolder("files") + val library = tmp.newFolder("card") + File(library, "steamapps/common/Game").mkdirs() + val binds = SecondaryLibrary.binds(files, library) + val private = SecondaryLibrary.privateRoot(files, library) + for (guest in listOf("/mnt/droiddeck-sd", "/mnt/bannerlator-sd")) { + assertTrue(binds.contains("${library.path}:$guest")) + assertTrue(binds.contains("$private/steamapps/compatdata:$guest/steamapps/compatdata")) + assertTrue(binds.contains("$private/steamapps/downloading/4185400:$guest/steamapps/downloading/4185400")) + assertTrue(binds.contains("$private/steamapps/common/SteamLinuxRuntime_4-arm64:$guest/steamapps/common/steamlinuxruntime_4-arm64")) + assertFalse(binds.any { it.endsWith(":$guest/steamapps/common/Game") }) + } + } + + @Test fun migrationPreservesSavesLinksAndOriginalAndNeverOverwritesNewSaves() { + val files = tmp.newFolder("files") + val library = tmp.newFolder("card") + val save = File(library, "steamapps/compatdata/42/pfx/save.dat") + save.parentFile!!.mkdirs() + save.writeText("original") + Files.createSymbolicLink(File(save.parentFile, "link").toPath(), File("save.dat").toPath()) + SecondaryLibrary.binds(files, library) + val copied = File(SecondaryLibrary.privateRoot(files, library), "steamapps/compatdata/42/pfx/save.dat") + assertEquals("original", copied.readText()) + assertTrue(Files.isSymbolicLink(File(copied.parentFile, "link").toPath())) + copied.writeText("new save") + SecondaryLibrary.binds(files, library) + assertEquals("new save", copied.readText()) + assertEquals("original", save.readText()) + } + + @Test fun changingLibraryUsesADifferentPrivatePrefixDirectory() { + val files = tmp.newFolder("files") + assertNotEquals(SecondaryLibrary.privateRoot(files, tmp.newFolder("one")), + SecondaryLibrary.privateRoot(files, tmp.newFolder("two"))) + } + + @Test fun installedNativeToolVersionsAlsoGetPrivateStaging() { + val files = tmp.newFolder("files") + val library = tmp.newFolder("card") + val manifest = File(library, "steamapps/appmanifest_123.acf") + manifest.parentFile!!.mkdirs() + manifest.writeText("\"AppState\" { \"appid\" \"123\" \"installdir\" \"Proton 99.0 (ARM64)\" }") + assertTrue(SecondaryLibrary.binds(files, library).any { + it.endsWith(":/mnt/droiddeck-sd/steamapps/downloading/123") + }) + } + + @Test fun deletingAStagedDepotDoesNotRestoreTheOldSharedDownload() { + val files = tmp.newFolder("files") + val library = tmp.newFolder("card") + val stale = File(library, "steamapps/downloading/4185400/stale") + stale.parentFile!!.mkdirs() + stale.writeText("old download") + SecondaryLibrary.binds(files, library) + val target = File(SecondaryLibrary.privateRoot(files, library), "steamapps/downloading/4185400") + assertTrue(File(target, "stale").isFile) + target.deleteRecursively() + SecondaryLibrary.binds(files, library) + assertFalse(File(target, "stale").exists()) + assertTrue(stale.isFile) + } +} diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat index fb70b40e23..1a38c20b88 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat @@ -254,7 +254,8 @@ fi depot= best=0 for name in %s; do - candidate="$steam_root/steamapps/common/$name" + for library in "$steam_root" /mnt/droiddeck-sd; do + candidate="$library/steamapps/common/$name" [ -d "$candidate/files/bin-arm64" ] && [ -x "$candidate/proton" ] || continue build=0 read -r build _ 2>/dev/null < "$candidate/version" @@ -263,6 +264,7 @@ for name in %s; do depot=$candidate best=$build fi + done done if [ -n "$depot" ]; then bl_components "$depot" @@ -595,10 +597,10 @@ def depot_build(depot): def find_source(steam_root): """The newest ARM64 Proton depot the client has downloaded (the one the launcher runs), or None.""" - common = os.path.join(steam_root, "steamapps", "common") # bin-arm64 is what makes it the native build rather than the x86_64 one. - found = [os.path.join(common, name) for name in SOURCES - if os.path.isdir(os.path.join(common, name, "files", "bin-arm64"))] + found = [os.path.join(root, "steamapps", "common", name) + for root in (steam_root, "/mnt/droiddeck-sd") for name in SOURCES + if os.path.isdir(os.path.join(root, "steamapps", "common", name, "files", "bin-arm64"))] return max(found, key=depot_build) if found else None