Fix per-game screen effects tracking

This commit is contained in:
EnzoDLofi committed 2026-11-13 22:16:13 -04:00
1 parent a14dd3049d
commit 2938c63d2c
4 files changed
+63 -20

No files matched your search

@@ -983,8 +983,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
isFocusableInTouchMode = true
defaultFocusHighlightEnabled = false
setContent {
val effectsEditorProfileId = androidx.compose.runtime.remember(drawerOpen) {
if (drawerOpen) currentScreenEffectsProfileId() else null
val activeEffectsProfileId = currentScreenEffectsProfileId()
val effectsEditorProfileId = if (drawerOpen) activeEffectsProfileId else null
androidx.compose.runtime.LaunchedEffect(effectsEditorProfileId) {
if (effectsEditorProfileId != null &&
SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity) == effectsEditorProfileId) {
effects = SessionPrefs.screenEffects(this@SessionActivity, effectsEditorProfileId)
}
}
val uiPointer = appUiOwnsPointer()
androidx.compose.runtime.SideEffect {
@@ -3758,8 +3763,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
},
menu = {
DroidDeckTheme {
val effectsEditorProfileId = androidx.compose.runtime.remember(drawerOpen, drawerPinned) {
if (drawerOpen || drawerPinned) currentScreenEffectsProfileId() else null
val activeEffectsProfileId = currentScreenEffectsProfileId()
val effectsEditorProfileId =
if (drawerOpen || drawerPinned) activeEffectsProfileId else null
androidx.compose.runtime.LaunchedEffect(effectsEditorProfileId) {
if (effectsEditorProfileId != null &&
SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity) == effectsEditorProfileId) {
effects = SessionPrefs.screenEffects(this@SessionActivity, effectsEditorProfileId)
}
}
SessionMenu(docked = true, effectsEditorProfileId = effectsEditorProfileId)
}
@@ -1595,7 +1595,7 @@ class SessionService : Service() {
var goneSince = 0L
while (token == gameExitWatchToken && gen == sessionGen && SessionState.running && !SessionState.stopRequested) {
val now = android.os.SystemClock.elapsedRealtime()
if (steamGameRunning()) {
if (steamGameRunning(gameId)) {
if (!seen) Log.i(TAG, "game $gameId started; tracking its exit")
seen = true
goneSince = 0L
@@ -1637,7 +1637,8 @@ class SessionService : Service() {
Log.i(TAG, "game $gameId closed: asking the client to exit and returning to the launcher")
}
private fun steamGameRunning(): Boolean = SteamGameProcess.running()
private fun steamGameRunning(gameId: String): Boolean =
SteamGameProcess.running(gameId)
private fun resumeSession(panelVisible: Boolean = true) {
if (SessionState.suspended) SessionState.resumeRequested = true
@@ -3,16 +3,41 @@ package com.droiddeck.launcher.session
import java.io.File
object SteamGameProcess {
// Compatibilidade com telas que precisam detectar qualquer jogo Steam.
fun matches(cmdline: ByteArray): Boolean {
val args = String(cmdline).split('\u0000')
return args.indices.any { i ->
args[i] == "waitforexitandrun" ||
(args[i] == "SteamLaunch" &&
args.getOrNull(i + 1)?.startsWith("AppId=") == true)
}
}
fun running(): Boolean =
File("/proc").listFiles()?.any { p ->
p.name.all(Char::isDigit) &&
runCatching { File(p, "cmdline").readBytes() }
.getOrNull()?.let(::matches) == true
} == true
fun matches(cmdline: ByteArray, gameId: String): Boolean {
if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return false
val args = String(cmdline).split('\u0000')
for (i in args.indices) {
if (args[i] == "waitforexitandrun") return true
if (args[i] == "SteamLaunch" && args.getOrNull(i + 1)?.startsWith("AppId=") == true) return true
if (args[i] == "SteamLaunch") {
val appId = args.getOrNull(i + 1)
?.takeIf { it.startsWith("AppId=") }
?.removePrefix("AppId=")
if (appId == gameId) return true
}
if (args[i] == "-applaunch" && args.getOrNull(i + 1) == gameId) return true
}
return false
}
fun running(proc: File = File("/proc")): Boolean = proc.listFiles()?.any { p ->
p.name.all(Char::isDigit) && runCatching { File(p, "cmdline").readBytes() }.getOrNull()?.let(::matches) == true
} == true
fun running(gameId: String, proc: File = File("/proc")): Boolean =
proc.listFiles()?.any { p ->
p.name.all(Char::isDigit) &&
runCatching { File(p, "cmdline").readBytes() }
.getOrNull()?.let { matches(it, gameId) } == true
} == true
}
@@ -13,17 +13,21 @@ class SteamGameProcessTest {
private fun cmdline(vararg args: String) = args.joinToString("\u0000", postfix = "\u0000").toByteArray()
@Test fun theSessionsOwnSearchesAreNotAGame() {
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]")))
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch")))
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch AppId=976310( |$)")))
assertFalse(SteamGameProcess.matches(cmdline("sh", "-c", "pgrep -f 'proton waitforexitandrun'")))
assertFalse(SteamGameProcess.matches(cmdline("/usr/bin/steam", "steam://rungameid/976310")))
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch AppId=976310( |$)"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("sh", "-c", "pgrep -f 'proton waitforexitandrun'"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("/usr/bin/steam", "steam://rungameid/976310"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("reaper", "SteamLaunch", "AppId=976310"), ""))
assertFalse(SteamGameProcess.matches(cmdline("reaper", "SteamLaunch", "AppId=976310"), "abc"))
}
@Test fun steamsReaperAndProtonAreAGame() {
assertTrue(SteamGameProcess.matches(cmdline("/root/.local/share/Steam/steamrtarm64/reaper", "SteamLaunch", "AppId=976310", "--",
"/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe")))
assertTrue(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe")))
"/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe"), "976310"))
assertFalse(SteamGameProcess.matches(cmdline("/root/.local/share/Steam/steamrtarm64/reaper", "SteamLaunch", "AppId=976310", "--",
"/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe"), "123"))
assertFalse(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe"), "976310"))
}
@Test fun runningLooksAtEveryProcess() {
@@ -31,8 +35,10 @@ class SteamGameProcessTest {
fun process(pid: String, vararg args: String) = File(proc, pid).apply { mkdirs() }.resolve("cmdline").writeBytes(cmdline(*args))
process("100", "pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]")
process("self", "reaper", "SteamLaunch", "AppId=1")
assertFalse(SteamGameProcess.running(proc))
assertFalse(SteamGameProcess.running("976310", proc))
assertTrue(SteamGameProcess.running("1", proc))
process("200", "reaper", "SteamLaunch", "AppId=976310", "--", "proton", "waitforexitandrun", "MK11.exe")
assertTrue(SteamGameProcess.running(proc))
assertTrue(SteamGameProcess.running("976310", proc))
assertFalse(SteamGameProcess.running("123", proc))
}
}