Fix screen effects profile switching

This commit is contained in:
EnzoDLofi committed 2026-11-13 23:23:18 -04:00
1 parent 9bd407c4c5
commit cfb52ded61
2 files changed
+76 -17

No files matched your search

@@ -1388,19 +1388,46 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
onHudReset = { hudConfig = DroidDeckHudConfig.reset(this@SessionActivity); hud.applyConfig() },
onHudExport = { exportHudDiagnostics() },
onUpscaler = { m ->
SessionPrefs.setUpscaler(this@SessionActivity, m); upscaler = m
WaylandCompositor.nativeSetUpscaler(m)
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(effects, m)?.name)
SessionPrefs.setUpscaler(this@SessionActivity, m)
val activeProfileId =
SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity)
val activeEffects =
SessionPrefs.screenEffects(this@SessionActivity, activeProfileId)
val activeUpscaler =
SessionPrefs.screenEffectsUpscaler(this@SessionActivity, activeProfileId)
if ((effectsEditorTarget ?: screenEffectsTarget) == SCREEN_EFFECTS_TARGET_AUTO) {
effects = activeEffects
upscaler = activeUpscaler
}
WaylandCompositor.nativeSetUpscaler(activeUpscaler)
WaylandCompositor.nativeSetLookName(
ScreenEffectLooks.match(activeEffects, activeUpscaler)?.name
)
activeEffects.push(activeUpscaler)
},
onPresetUpscaler = { m ->
val target = effectsEditorTarget ?: screenEffectsTarget
val profileId = screenEffectsProfileIdForTarget(target)
SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m)
if (target == screenEffectsTarget) {
upscaler = m
if (screenEffectsTargetAppliesToLiveOutput(target)) {
WaylandCompositor.nativeSetUpscaler(m)
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(effects, m)?.name)
val activeProfileId = if (target == SCREEN_EFFECTS_TARGET_AUTO) {
SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity)
} else null
if (activeProfileId != null && activeProfileId != effectsEditorProfileId) {
Log.w(TAG, "Screen effects profile changed while editing; discarding stale upscaler edit")
observedScreenEffectsProfileId = activeProfileId
val activeEffects = SessionPrefs.screenEffects(this@SessionActivity, activeProfileId)
effects = activeEffects
activeEffects.push(upscaler)
} else {
val profileId = screenEffectsProfileIdForTarget(target)
SessionPrefs.setScreenEffectsUpscaler(this@SessionActivity, profileId, m)
if (target == screenEffectsTarget) {
upscaler = m
if (screenEffectsTargetAppliesToLiveOutput(target)) {
WaylandCompositor.nativeSetUpscaler(m)
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(effects, m)?.name)
}
}
}
},
@@ -1516,7 +1516,7 @@ class SessionService : Service() {
return
}
val accepted = gameId!!
if (pendingSteamGameId == null) pendingSteamPreviousGameId = SessionState.gameId
if (pendingSteamPreviousGameId == null) pendingSteamPreviousGameId = SessionState.gameId
if (pendingSteamGameId != null) Log.i(TAG, "replacing a queued game launch with $accepted")
pendingSteamGameExitWatchToken = ++gameExitWatchToken
SessionState.gameId = accepted
@@ -1582,15 +1582,19 @@ class SessionService : Service() {
return
}
pendingSteamGameId = null
pendingSteamPreviousGameId = null
pendingSteamGameGeneration = -1
pendingSteamGameExitWatchToken = -1
SessionEvents.record("steam.game_launch_requested", mapOf("gameId" to gameId, "generation" to gen))
watchGameExit(gameId, gen, exitWatchToken)
watchGameExit(gameId, gen, exitWatchToken, pendingSteamPreviousGameId)
Log.i(TAG, "queued Steam game $gameId for the running client")
}
private fun watchGameExit(gameId: String, gen: Int, token: Int) {
private fun watchGameExit(
gameId: String,
gen: Int,
token: Int,
previousGameId: String? = null
) {
Thread({
val startBy = android.os.SystemClock.elapsedRealtime() + GAME_START_TIMEOUT_MS
var seen = false
@@ -1598,13 +1602,41 @@ class SessionService : Service() {
while (token == gameExitWatchToken && gen == sessionGen && SessionState.running && !SessionState.stopRequested) {
val now = android.os.SystemClock.elapsedRealtime()
if (steamGameRunning(gameId)) {
if (!seen) Log.i(TAG, "game $gameId started; tracking its exit")
if (!seen) {
Log.i(TAG, "game $gameId started; tracking its exit")
mainHandler.post {
if (token == gameExitWatchToken && gen == sessionGen &&
pendingSteamPreviousGameId == previousGameId) {
pendingSteamPreviousGameId = null
}
}
}
seen = true
goneSince = 0L
} else if (!seen) {
if (now > startBy) {
Log.i(TAG, "game $gameId did not start; clearing its screen effects profile")
mainHandler.post { clearActiveScreenEffectsProfile(gameId, gen, token) }
mainHandler.post {
if (token != gameExitWatchToken || gen != sessionGen ||
!SessionState.running || SessionState.stopRequested) {
return@post
}
if (previousGameId != null && steamGameRunning(previousGameId)) {
Log.w(TAG, "game $gameId did not start; restoring previous game $previousGameId")
SessionState.gameId = previousGameId
val previousProfileId =
SessionPrefs.screenEffectsProfileId(MODE_STEAM, previousGameId, null)
SessionPrefs.setActiveScreenEffectsProfile(this@SessionService, previousProfileId)
SessionPrefs.screenEffects(this@SessionService, previousProfileId)
.push(SessionPrefs.screenEffectsUpscaler(this@SessionService, previousProfileId))
pendingSteamPreviousGameId = null
watchGameExit(previousGameId, gen, token)
} else {
Log.i(TAG, "game $gameId did not start; clearing its screen effects profile")
pendingSteamPreviousGameId = null
clearActiveScreenEffectsProfile(gameId, gen, token)
}
}
return@Thread
}
} else if (goneSince == 0L) {