mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(session): the frame limit without Steam holds the game in gamescope, not only the screen
This commit is contained in:
1 parent
e3b1b60914
commit
6d3bdc42f7
5 files changed
+157
-35
No files matched your search
@@ -122,6 +122,7 @@ import com.droiddeck.launcher.session.GameProfileFollowState
|
||||
import com.droiddeck.launcher.session.GameProfileInventoryCache
|
||||
import com.droiddeck.launcher.session.GameProfileRefreshState
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.GamescopeConvarSync
|
||||
import com.droiddeck.launcher.session.SessionEvents
|
||||
import com.droiddeck.launcher.session.SessionArtifacts
|
||||
import com.droiddeck.launcher.session.SessionLogShare
|
||||
@@ -351,13 +352,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var steamImportAnswered: String? = null
|
||||
private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_CLICK)
|
||||
private var relativeMouseMode by mutableIntStateOf(0)
|
||||
@Volatile private var appliedRelativeMouseMode: Int? = null
|
||||
private val agentReadyListener: () -> Unit = {
|
||||
relativeMouseRetries = 0
|
||||
requestRelativeMouse()
|
||||
appliedOverlayPlanes = null
|
||||
overlayPlanesRetries = 0
|
||||
requestOverlayPlanes()
|
||||
relativeMouse.restart()
|
||||
overlayPlanes.applied = null
|
||||
overlayPlanes.restart()
|
||||
gamescopeFrameLimit.applied = null
|
||||
gamescopeFrameLimit.restart()
|
||||
}
|
||||
private val appTextFocus get() = wowChat.request != null
|
||||
private val wowChat by lazy { com.droiddeck.launcher.ui.WowChat(this, ::sendWowChat, ::cancelWowChat, ::readGameField) }
|
||||
@@ -1716,6 +1716,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
fpsLimit = fps
|
||||
SessionPrefs.saveFpsLimit(this@SessionActivity, fpsLimitKey(), fps)
|
||||
applyOutputPacing()
|
||||
gamescopeFrameLimit.restart()
|
||||
},
|
||||
cornerTap = cornerTap,
|
||||
onCornerTap = { on -> SessionPrefs.setDrawerCornerTap(this@SessionActivity, on); cornerTap = on },
|
||||
@@ -3930,21 +3931,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private val gamescopeConvarRequests = java.util.concurrent.Executors.newSingleThreadExecutor { runnable ->
|
||||
Thread(runnable, "gamescope-convar").apply { isDaemon = true }
|
||||
}
|
||||
@Volatile private var desiredRelativeMouseMode = 0
|
||||
private fun gamescopeConvar(name: String, applied: Int?, wanted: () -> Int?) = GamescopeConvarSync(
|
||||
name, wanted,
|
||||
execute = { runCatching { gamescopeConvarRequests.execute(it) } },
|
||||
retryLater = { uiHandler.postDelayed(it, 2_000) },
|
||||
set = { convar, value -> AgentGuest.setGamescopeConvar(this, convar, value) },
|
||||
maxRetries = RELATIVE_MOUSE_MAX_RETRIES,
|
||||
applied = applied,
|
||||
)
|
||||
|
||||
@Volatile private var relativeMouseRetries = 0
|
||||
@Volatile private var desiredRelativeMouseMode = 0
|
||||
private val relativeMouse = gamescopeConvar("relative_mouse", null, ::relativeMouseConvar)
|
||||
|
||||
private fun setRelativeMouse(mode: Int) {
|
||||
desiredRelativeMouseMode = mode
|
||||
relativeMouseRetries = 0
|
||||
requestRelativeMouse()
|
||||
relativeMouse.restart()
|
||||
}
|
||||
|
||||
private fun requestRelativeMouse() {
|
||||
runCatching { gamescopeConvarRequests.execute { applyRelativeMouse() } }
|
||||
}
|
||||
private fun requestRelativeMouse() = relativeMouse.request()
|
||||
|
||||
private fun applyRelativeMouse() {
|
||||
private fun relativeMouseConvar(): Int {
|
||||
val wanted = desiredRelativeMouseMode
|
||||
val touchpadRoute = com.droiddeck.launcher.input.TouchRouter.decide(com.droiddeck.launcher.input.TouchRouter.Snapshot(
|
||||
uiBlocking = false,
|
||||
@@ -3953,16 +3959,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
steamSession = SessionState.mode == SessionService.MODE_STEAM,
|
||||
steamDesktopUi = SessionState.steamUi == "desktop",
|
||||
)) == com.droiddeck.launcher.input.TouchRouter.Route.TOUCHPAD
|
||||
val mode = com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, mouseAttached(), touchpadRoute)
|
||||
if (appliedRelativeMouseMode == mode) return
|
||||
if (AgentGuest.setGamescopeConvar(this, "relative_mouse", mode)) appliedRelativeMouseMode = mode
|
||||
else if (relativeMouseRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestRelativeMouse() }, 2_000)
|
||||
if (desiredRelativeMouseMode != wanted) requestRelativeMouse()
|
||||
return com.droiddeck.launcher.input.TouchGestureConfig.gamescopeRelativeMouse(wanted, mouseAttached(), touchpadRoute)
|
||||
}
|
||||
|
||||
@Volatile private var desiredOverlayPlanes = -1
|
||||
@Volatile private var appliedOverlayPlanes: Int? = -1
|
||||
@Volatile private var overlayPlanesRetries = 0
|
||||
private val overlayPlanes = gamescopeConvar("wayland_overlay_planes", -1) { desiredOverlayPlanes }
|
||||
private val gamescopeFrameLimit = gamescopeConvar("debug_set_fps_limit", null) {
|
||||
SessionPrefs.gamescopeFrameLimit(noSteamSession(), SessionState.fpsLimit)
|
||||
}
|
||||
@Volatile private var guestRefresh = 0
|
||||
@Volatile private var guestFrameRate = 0
|
||||
private var pacedFrameGenMode: FrameGen.Mode? = null
|
||||
@@ -3991,20 +3995,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private val overlayPlanesListener = WaylandCompositor.OverlayPlanesListener { planes ->
|
||||
desiredOverlayPlanes = planes
|
||||
overlayPlanesRetries = 0
|
||||
requestOverlayPlanes()
|
||||
}
|
||||
|
||||
private fun requestOverlayPlanes() {
|
||||
runCatching { gamescopeConvarRequests.execute { applyOverlayPlanes() } }
|
||||
}
|
||||
|
||||
private fun applyOverlayPlanes() {
|
||||
val wanted = desiredOverlayPlanes
|
||||
if (appliedOverlayPlanes == wanted) return
|
||||
if (AgentGuest.setGamescopeConvar(this, "wayland_overlay_planes", wanted)) appliedOverlayPlanes = wanted
|
||||
else if (overlayPlanesRetries++ < RELATIVE_MOUSE_MAX_RETRIES) uiHandler.postDelayed({ requestOverlayPlanes() }, 2_000)
|
||||
if (desiredOverlayPlanes != wanted) requestOverlayPlanes()
|
||||
overlayPlanes.restart()
|
||||
}
|
||||
|
||||
private fun refreshGestureConfig() {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
internal class GamescopeConvarSync(
|
||||
private val name: String,
|
||||
private val wanted: () -> Int?,
|
||||
private val execute: (Runnable) -> Unit,
|
||||
private val retryLater: (Runnable) -> Unit,
|
||||
private val set: (String, Int) -> Boolean,
|
||||
private val maxRetries: Int,
|
||||
@Volatile var applied: Int? = null,
|
||||
) {
|
||||
@Volatile private var retries = 0
|
||||
|
||||
fun request() {
|
||||
execute(Runnable { send() })
|
||||
}
|
||||
|
||||
fun restart() {
|
||||
retries = 0
|
||||
request()
|
||||
}
|
||||
|
||||
private fun send() {
|
||||
val value = wanted() ?: return
|
||||
if (applied == value) return
|
||||
if (set(name, value)) applied = value
|
||||
else if (retries++ < maxRetries) retryLater(Runnable { request() })
|
||||
if (wanted() != value) request()
|
||||
}
|
||||
}
|
||||
@@ -1720,6 +1720,9 @@ object SessionPrefs {
|
||||
return if (pip && mirrorRefreshLimit <= 0 && (limit <= 0 || limit > PIP_FPS)) PIP_FPS else limit
|
||||
}
|
||||
|
||||
fun gamescopeFrameLimit(noSteamSession: Boolean, sessionLimit: Int): Int? =
|
||||
if (noSteamSession) sessionLimit.coerceAtLeast(0) else null
|
||||
|
||||
val upscalerChoices = listOf(
|
||||
2 to "Nearest", 0 to "Linear", 4 to "AMD FSR 1", 3 to "Snapdragon GSR",
|
||||
8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only",
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class GamescopeConvarSyncTest {
|
||||
private var wanted: Int? = 0
|
||||
private var accept = true
|
||||
private val sent = mutableListOf<Pair<String, Int>>()
|
||||
private val retries = mutableListOf<Runnable>()
|
||||
|
||||
private fun sync(applied: Int? = null) = GamescopeConvarSync(
|
||||
"debug_set_fps_limit", { wanted },
|
||||
execute = { it.run() },
|
||||
retryLater = { retries += it },
|
||||
set = { name, value -> sent += name to value; accept },
|
||||
maxRetries = 2,
|
||||
applied = applied,
|
||||
)
|
||||
|
||||
@Test fun aNewValueIsSentOnce() {
|
||||
val sync = sync()
|
||||
wanted = 60
|
||||
sync.restart()
|
||||
sync.request()
|
||||
assertEquals(listOf("debug_set_fps_limit" to 60), sent)
|
||||
assertEquals(60, sync.applied)
|
||||
}
|
||||
|
||||
@Test fun theValueGamescopeAlreadyHasIsNotSent() {
|
||||
wanted = -1
|
||||
sync(applied = -1).restart()
|
||||
assertEquals(emptyList<Pair<String, Int>>(), sent)
|
||||
}
|
||||
|
||||
@Test fun nothingIsSentWhileTheConvarIsNotOurs() {
|
||||
wanted = null
|
||||
val sync = sync()
|
||||
sync.restart()
|
||||
assertEquals(emptyList<Pair<String, Int>>(), sent)
|
||||
assertNull(sync.applied)
|
||||
}
|
||||
|
||||
@Test fun aRefusedValueIsRetriedAFewTimesThenLeft() {
|
||||
accept = false
|
||||
wanted = 60
|
||||
sync().restart()
|
||||
while (retries.isNotEmpty()) retries.removeAt(0).run()
|
||||
assertEquals(3, sent.size)
|
||||
}
|
||||
|
||||
@Test fun aRestartRetriesAgainAfterTheAgentComesBack() {
|
||||
accept = false
|
||||
wanted = 60
|
||||
val sync = sync()
|
||||
sync.restart()
|
||||
while (retries.isNotEmpty()) retries.removeAt(0).run()
|
||||
accept = true
|
||||
sync.restart()
|
||||
assertEquals(4, sent.size)
|
||||
assertEquals(60, sync.applied)
|
||||
}
|
||||
|
||||
@Test fun forgettingTheAppliedValueSendsItAgain() {
|
||||
wanted = 60
|
||||
val sync = sync()
|
||||
sync.restart()
|
||||
sync.applied = null
|
||||
sync.restart()
|
||||
assertEquals(listOf("debug_set_fps_limit" to 60, "debug_set_fps_limit" to 60), sent)
|
||||
}
|
||||
|
||||
@Test fun clearingTheLimitIsSent() {
|
||||
wanted = 60
|
||||
val sync = sync()
|
||||
sync.restart()
|
||||
wanted = 0
|
||||
sync.restart()
|
||||
assertEquals(listOf("debug_set_fps_limit" to 60, "debug_set_fps_limit" to 0), sent)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class OutputPacingTest {
|
||||
@@ -30,4 +31,19 @@ class OutputPacingTest {
|
||||
@Test fun mirroringKeepsTheGlassesRate() {
|
||||
assertEquals(60, SessionPrefs.compositorFpsLimit(60))
|
||||
}
|
||||
|
||||
@Test fun nonSteamLimitHoldsTheGameInGamescope() {
|
||||
assertEquals(60, SessionPrefs.gamescopeFrameLimit(true, 60))
|
||||
assertEquals(45, SessionPrefs.gamescopeFrameLimit(true, 45))
|
||||
}
|
||||
|
||||
@Test fun nonSteamSessionWithoutALimitClearsGamescopesLimit() {
|
||||
assertEquals(0, SessionPrefs.gamescopeFrameLimit(true, 0))
|
||||
assertEquals(0, SessionPrefs.gamescopeFrameLimit(true, SessionPrefs.FPS_UNPACED))
|
||||
}
|
||||
|
||||
@Test fun steamSessionsLeaveGamescopesLimitToSteam() {
|
||||
assertNull(SessionPrefs.gamescopeFrameLimit(false, 60))
|
||||
assertNull(SessionPrefs.gamescopeFrameLimit(false, 0))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user