From d46bd4a0c34b6f68abef004f47c019b0196f858a Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 19 Sep 2026 14:59:12 -0400 Subject: [PATCH] Start a session on every Play, not only on the compositor's first start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The compositor lives for the whole process, so the second Play after a session had ended re-attached the Surface, started nothing, and left the loading panel counting up over a dead session — it looked like a login that never came. The service now starts whenever no session is running; the compositor's one-shot first-frame notice is re-armed for the new session, or the panel would never leave; and whatever the previous session left behind (gamescopereaper, the session script, a dead client's helpers, the audio server) is killed first, since it is our uid and still holds the socket the new one needs. --- app/src/main/cpp/waylandcomp/src/vk_present.c | 6 ++++ .../cpp/waylandcomp/src/waylandcomp_jni.c | 7 +++++ .../com/steamdeck/launcher/SessionActivity.kt | 13 ++++++--- .../launcher/session/SessionService.kt | 29 +++++++++++++++++++ .../launcher/wayland/CompositorHost.kt | 8 +++++ .../launcher/wayland/WaylandCompositor.java | 4 +++ 6 files changed, 63 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index c760081162..920238215d 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -1805,6 +1805,12 @@ int vkp_surface_rotation_degrees(void) { ANativeWindow *vkp_window(void) { return g_window; } +/* A new session under a compositor that has already presented: arm the one-shot again so the + * next drawn frame reports, or the app would show its loading panel over the new client for good. */ +void vkp_reset_first_frame(void) { + g_first_frame_done = 0; +} + void vkp_signal_first_frame(void) { if (g_first_frame_done) return; g_first_frame_done = 1; diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index 28fa2a84ca..00684b07ed 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -346,6 +346,13 @@ Java_com_steamdeck_launcher_wayland_WaylandCompositor_nativeSetOutputRefreshRate } /* The container's screen size for the advertised wl_output mode. Set before the compositor starts. */ +extern void vkp_reset_first_frame(void); +JNIEXPORT void JNICALL +Java_com_steamdeck_launcher_wayland_WaylandCompositor_nativeResetFirstFrame(JNIEnv *env, jclass clazz) { + (void)env; (void)clazz; + vkp_reset_first_frame(); +} + JNIEXPORT void JNICALL Java_com_steamdeck_launcher_wayland_WaylandCompositor_nativeSetOutputSize(JNIEnv *env, jclass clazz, jint w, jint h) { g_output_w = w > 0 ? w : 0; diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index a96619aedc..c01aece3f1 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -108,14 +108,19 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { val size = outputSize() SessionState.outputSize = size SessionState.refreshHz = refreshHz() - val first = CompositorHost.startOrAttach( + CompositorHost.startOrAttach( holder.surface, runtimeDir.path, driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) }, applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(), ) - // The service owns everything below the compositor, and starting it is idempotent: coming - // back to a running session just re-attaches the Surface above. - if (first) SessionService.start(this) + // The service owns everything below the compositor. It is started whenever no session is + // running — NOT only when the compositor was just started: the compositor lives for the + // whole process, so the second Play after a session ended used to re-attach the Surface, + // start nothing, and leave the loading panel counting up over a dead session. + if (!SessionState.running) { + CompositorHost.newSession() + SessionService.start(this) + } } override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {} 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 8fe8554309..068754741a 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt @@ -79,6 +79,7 @@ class SessionService : Service() { val root = LinuxRuntime.rootDir(this) val sessionRoot = LinuxRuntime.sessionRoot(this).apply { mkdirs() } val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() } + killStragglers() SessionFiles.stage(this, root) val logDir = SessionFiles.logDirectory(this) @@ -174,6 +175,31 @@ class SessionService : Service() { Log.i(TAG, "session pid $sessionPid, log ${sessionLog.path}") } + /** + * proot's --kill-on-exit takes its tracees down, but a session that died from the inside + * (the client asserting, Xwayland going) leaves gamescopereaper and the session script + * behind, still holding the Wayland socket and the audio server the next session needs. They + * are our uid, so they are ours to kill. + */ + private fun killStragglers() { + val me = android.os.Process.myPid() + val procs = File("/proc").listFiles { f -> f.name.all { it.isDigit() } } ?: return + var killed = 0 + for (proc in procs) { + val pid = proc.name.toIntOrNull() ?: continue + if (pid == me) continue + val cmdline = try { + File(proc, "cmdline").readBytes().toString(Charsets.UTF_8).replace('\u0000', ' ') + } catch (e: Exception) { + continue + } + if (STRAGGLERS.none { cmdline.contains(it) }) continue + android.os.Process.killProcess(pid) + killed++ + } + if (killed > 0) Log.w(TAG, "killed $killed leftover process(es) of a previous session") + } + private fun stopSession(status: Int) { if (!SessionState.running) return SessionState.running = false @@ -301,6 +327,9 @@ class SessionService : Service() { private const val CHANNEL_ID = "session" private const val NOTIFICATION_ID = 1001 const val ACTION_STOP = "com.steamdeck.launcher.STOP_SESSION" + /** Command lines that can only belong to a session of ours. */ + private val STRAGGLERS = listOf("bannerlator-session", "gamescope", "Xwayland", "steamrtarm64", + "steamwebhelper", "linuxfs/opt/android-host/proot", "pulseaudio/libpulseaudio.so") private const val NO_PAD_SWITCH = "Download/steamdeck-no-pad" private const val PAD_LOG_SWITCH = "Download/steamdeck-pad-log" diff --git a/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt b/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt index 98f701423a..fa311957c1 100644 --- a/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt +++ b/app/src/main/java/com/steamdeck/launcher/wayland/CompositorHost.kt @@ -70,5 +70,13 @@ object CompositorHost { vsyncRunning = false } + /** + * A new session behind a compositor that has already presented: the first-frame notice is + * one-shot in native code, so it is re-armed here or the loading panel would never leave. + */ + fun newSession() { + if (started) WaylandCompositor.nativeResetFirstFrame() + } + val isStarted: Boolean get() = started } diff --git a/app/src/main/java/com/steamdeck/launcher/wayland/WaylandCompositor.java b/app/src/main/java/com/steamdeck/launcher/wayland/WaylandCompositor.java index 5dc52c08b7..d4e77cc6fc 100644 --- a/app/src/main/java/com/steamdeck/launcher/wayland/WaylandCompositor.java +++ b/app/src/main/java/com/steamdeck/launcher/wayland/WaylandCompositor.java @@ -240,6 +240,10 @@ public final class WaylandCompositor { * list stops at the desktop size, as the X server's does on X11. Set before the compositor starts. */ public static native void nativeSetOutputSize(int width, int height); + /** Re-arms the one-shot first-frame notice, for a new session under a compositor that has + * already presented a previous one. */ + public static native void nativeResetFirstFrame(); + // ── HDR10 output, round 1 (waylandcomp/src/banner_color.h, wl_color_mgmt.c) ───────────────── // Opt-in: BANNER_WAYLAND_HDR=1 in the container's or shortcut's env vars. The compositor offers // games HDR10 (wp_color_manager_v1 + 10-bit buffers, frames tagged BT2020_PQ on the game's own