Add Back shortcuts for session menu and Steam QAM

This commit is contained in:
xXJsonDeruloXx committed 2026-09-23 17:16:02 -04:00
1 parent bd51571530
commit 3fa05f6c18
6 files changed
+74 -9

No files matched your search

@@ -169,6 +169,7 @@ class MainActivity : ComponentActivity() {
private var touchMode by mutableStateOf(SessionPrefs.TOUCH_AUTO)
private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL)
private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO)
private var backActionsInverted by mutableStateOf(false)
private var renderer by mutableStateOf("pixman")
private var gameStorage by mutableStateOf("")
private var storageOptions by mutableStateOf<List<Pair<String, String>>>(emptyList())
@@ -515,6 +516,7 @@ class MainActivity : ComponentActivity() {
touchMode = touchMode,
suspendPolicy = suspendPolicy,
oscMode = if (mode == SessionService.MODE_STEAM) oscMode else null,
backActionsInverted = backActionsInverted,
directAudio = if (mode == SessionService.MODE_STEAM) directAudio else null,
clientDirectAudio = clientDirectAudio,
mic = if (mode == SessionService.MODE_STEAM) mic else null,
@@ -546,6 +548,10 @@ class MainActivity : ComponentActivity() {
onTouch = { t -> SessionPrefs.setTouchMode(this, t); touchMode = t },
onSuspendPolicy = { policy -> SessionPrefs.setSuspendPolicy(this, mode, policy); suspendPolicy = policy },
onOsc = { o -> SessionPrefs.setOscMode(this, o); oscMode = o },
onBackActionsInverted = { inverted ->
SessionPrefs.setBackActionsInverted(this, inverted)
backActionsInverted = inverted
},
onDirectAudio = { on -> SessionPrefs.setDirectAudio(this, on); directAudio = on },
onClientDirectAudio = { on -> SessionPrefs.setClientDirectAudio(this, on); clientDirectAudio = on },
onMic = { on ->
@@ -641,6 +647,7 @@ class MainActivity : ComponentActivity() {
touchMode = SessionPrefs.touchMode(this)
suspendPolicy = SessionPrefs.suspendPolicy(this, mode)
oscMode = SessionPrefs.oscMode(this)
backActionsInverted = SessionPrefs.backActionsInverted(this)
directAudio = SessionPrefs.directAudio(this)
clientDirectAudio = SessionPrefs.clientDirectAudio(this)
mic = SessionPrefs.micEnabled(this)
@@ -85,9 +85,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var cursorVisible by mutableStateOf(false)
private val cursorHide = Runnable { cursorVisible = false }
private val uiHandler = Handler(Looper.getMainLooper())
private var pendingBackAction: Runnable? = null
// Compose reads these; the activity writes them.
private var drawerOpen by mutableStateOf(false)
private var backActionsInverted by mutableStateOf(false)
private var hudOn by mutableStateOf(true)
private var frameGenLabel by mutableStateOf("Off")
private var frameGenEngine by mutableStateOf(FrameGen.ENGINE_OFF)
@@ -200,10 +202,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
},
onKeyboard = { drawerOpen = false; keyboard?.toggle() },
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({
drawerOpen = false
padBridge?.triggerQam()
}) else null,
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
backActionsInverted = backActionsInverted,
onBackActionsInverted = { inverted ->
SessionPrefs.setBackActionsInverted(this@SessionActivity, inverted)
backActionsInverted = inverted
},
onOsc = { v -> SessionPrefs.setOscMode(this@SessionActivity, v); readPrefs(); updateOnScreenControls() },
onTouch = { v -> SessionPrefs.setTouchMode(this@SessionActivity, v); readPrefs() },
onShape = { v -> SessionPrefs.setShapeMode(this@SessionActivity, v); readPrefs() },
@@ -240,12 +244,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}
}
SessionState.endListener = endListener
// Back opens the drawer (and closes it again). Leaving the session running in the
// background and ending it are both actions in there, so neither can happen by accident
// from a button a game might also be reading.
// A single Back opens the session menu; two quick presses/swipes send the Steam QAM chord.
// The single action waits out the double-press window so the two actions stay distinct.
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
drawerOpen = !drawerOpen
routeBackAction()
}
})
watchSession()
@@ -264,6 +267,32 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}, 90)
}
private fun triggerSteamQam() {
drawerOpen = false
padBridge?.triggerQam()
}
private fun routeBackAction() {
pendingBackAction?.let { pending ->
uiHandler.removeCallbacks(pending)
pendingBackAction = null
performBackAction(double = true)
return
}
val pending = Runnable {
pendingBackAction = null
performBackAction(double = false)
}
pendingBackAction = pending
uiHandler.postDelayed(pending, android.view.ViewConfiguration.getDoubleTapTimeout().toLong())
}
private fun performBackAction(double: Boolean) {
val isSteam = SessionState.mode == SessionService.MODE_STEAM
val opensQam = isSteam && (double xor backActionsInverted)
if (opensQam) triggerSteamQam() else drawerOpen = !drawerOpen
}
private fun handleHomeGuideIntent(incoming: Intent?) {
if (incoming?.action != SessionService.ACTION_HOME_GUIDE) return
incoming.action = null
@@ -280,6 +309,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
fexPreset = SessionPrefs.fexPreset(this)
oscMode = SessionPrefs.oscMode(this)
shapeMode = SessionPrefs.shapeMode(this)
backActionsInverted = SessionPrefs.backActionsInverted(this)
}
// ── Compositor ──────────────────────────────────────────────────────────────────────────
@@ -957,6 +987,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
// Deliberately does NOT end the session: this activity can be destroyed while the user is
// in another app, and the whole point of the service is that Steam survives that.
watching = false
pendingBackAction?.let(uiHandler::removeCallbacks)
pendingBackAction = null
closeSecondScreen(reset = true)
if (::hud.isInitialized) hud.stop()
padBridge?.stop()
@@ -21,6 +21,13 @@ object SessionPrefs {
prefs(context).edit().putBoolean("hud", on).apply()
}
/** When enabled, a single Back opens Steam QAM and a double Back opens the session menu. */
fun backActionsInverted(context: Context): Boolean = prefs(context).getBoolean("backActionsInverted", false)
fun setBackActionsInverted(context: Context, inverted: Boolean) {
prefs(context).edit().putBoolean("backActionsInverted", inverted).apply()
}
const val TOUCH_AUTO = "auto"
const val TOUCH_PAD = "touchpad"
const val TOUCH_DIRECT = "direct"
@@ -46,6 +46,8 @@ class ModeSettings(
val suspendPolicy: String,
/** Steam only. */
val oscMode: String?,
/** Steam only: whether single and double Back actions are swapped. */
val backActionsInverted: Boolean = false,
val directAudio: Boolean?,
val clientDirectAudio: Boolean = false,
val mic: Boolean?,
@@ -91,6 +93,7 @@ class ModeSettingsActions(
val onTouch: (String) -> Unit,
val onSuspendPolicy: (String) -> Unit,
val onOsc: (String) -> Unit,
val onBackActionsInverted: (Boolean) -> Unit = {},
val onDirectAudio: (Boolean) -> Unit,
val onClientDirectAudio: (Boolean) -> Unit = {},
val onMic: (Boolean) -> Unit,
@@ -226,6 +229,12 @@ fun ModeSettingsPage(s: ModeSettings, a: ModeSettingsActions) {
), s.oscMode,
note = "Auto shows all controls without a controller. Steam + QAM shows only those buttons.", onPick = a.onOsc,
)
if (steam) ToggleRow(
host, "back-actions", "Invert Back actions",
if (s.backActionsInverted) "Back once opens Steam QAM; twice opens the session menu."
else "Back once opens the session menu; twice opens Steam QAM.",
s.backActionsInverted, onChange = a.onBackActionsInverted,
)
}
SettingsGroup("Session") {
ChoiceRow(
@@ -146,6 +146,7 @@ class DrawerActions(
val frameGenMultiplier: Int,
val lsfgReady: Boolean,
val oscMode: String,
val backActionsInverted: Boolean,
val touchMode: String,
val touchAuto: String,
val shapeMode: String,
@@ -159,6 +160,7 @@ class DrawerActions(
val onSteamMenu: (() -> Unit)?,
val onQam: (() -> Unit)?,
val onOsc: (String) -> Unit,
val onBackActionsInverted: (Boolean) -> Unit,
val onTouch: (String) -> Unit,
val onShape: (String) -> Unit,
val onFexPreset: (String) -> Unit,
@@ -296,6 +298,12 @@ fun SessionDrawer(open: Boolean, a: DrawerActions) {
listOf(SessionPrefs.OSC_AUTO to "Auto", SessionPrefs.OSC_ALWAYS to "Always", SessionPrefs.OSC_STEAM_QAM to "Steam + QAM", SessionPrefs.OSC_NEVER to "Never"), a.oscMode,
onPick = a.onOsc,
)
if (a.steam) ToggleRow(
host, "back-actions", "Invert Back actions",
if (a.backActionsInverted) "Back once opens Steam QAM; twice opens the session menu."
else "Back once opens the session menu; twice opens Steam QAM.",
a.backActionsInverted, onChange = a.onBackActionsInverted,
)
ActionRow("Keyboard", null, "Show") { host.open = null; a.onKeyboard() }
}