feat(session): Direct input switch for dd-directinput in the in-game controller settings

A game that runs with dd-directinput (DroidDeck-Bionic, Start without Steam) shows a
Direct input switch under Controller > Device settings. It writes dd-directinput's mode
file, so the running game moves between the pad state and Wine's own xinput at once, and
saves the choice for the game (DD_DIRECTINPUT=0 = start in pass-through). The switch is
shown only while the mode file exists; a session deletes it at start, so only a launch
that uses dd-directinput brings it back.
This commit is contained in:
The412Banner committed 2026-12-06 01:58:09 -05:00
1 parent 13f4babcd0
commit 3f9a79c67c
6 files changed
+73 -2

No files matched your search

@@ -185,6 +185,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private var unfoldedControls by mutableStateOf(false)
private var unfoldedControlsWithController by mutableStateOf(false)
private var adaptiveSticks by mutableStateOf<Boolean?>(null)
private var directInput by mutableStateOf<Boolean?>(null)
private var quickButtons by mutableStateOf<Map<InputCommand, Boolean>>(emptyMap())
private var picturePosition by mutableStateOf("center")
@@ -586,6 +587,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
drawerLayerOpen = false
drawerPinned = false
if (value) {
directInput = com.droiddeck.launcher.session.DirectInputSwitch.state(this)
releaseHeldKeys()
drawerXr = com.droiddeck.launcher.session.xr.XrPanels.showMenu()
drawerDocked = !drawerXr && dockDrawer() && openDockedMenu()
@@ -2140,6 +2142,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
primaryInputLayout?.let { com.droiddeck.launcher.input.InputLibraries.setAdaptiveSticks(this@SessionActivity, it.id, on) }
refreshInputProfile()
},
directInput = directInput,
onDirectInput = { on ->
com.droiddeck.launcher.session.DirectInputSwitch.set(this@SessionActivity, on)
directInput = on
},
showFloatingSteamControls = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad && unfoldedPanel == null &&
oscMode != SessionPrefs.OSC_NEVER && oscMode != SessionPrefs.OSC_STEAM_QAM &&
!steamTouchInUse && OnScreenLayout.supportsFloatingSteamControls(padType, primaryInputLayout),
@@ -50,6 +50,17 @@ object GameEnvironment {
return withScopeValue(config, scope, NO_STEAM, if (on) "1" else null)
}
/** dd-directinput on DroidDeck-Bionic: "0" starts the game in pass-through (Wine's own xinput); unset = the pad state. */
const val DIRECT_INPUT = "DD_DIRECTINPUT"
fun gameDirectInput(config: Config, scope: String): Boolean =
scope.isEmpty() || config.games[scope]?.get(DIRECT_INPUT) != "0"
fun withGameDirectInput(config: Config, scope: String, on: Boolean): Config {
require(scope.isNotEmpty() && validScope(scope))
return withScopeValue(config, scope, DIRECT_INPUT, if (on) null else "0")
}
const val GAME_RESOLUTION = "DROIDDECK_GAME_RESOLUTION"
fun gameResolution(config: Config, scope: String): GameResolution.Choice? =
@@ -0,0 +1,43 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
/**
* dd-directinput's mode file. DroidDeck-Bionic's launch.sh writes it beside the controller folder when a game set to start
* without Steam reads XInput through dd-directinput; the game's DLLs read it while it runs ('1' the pad state, '0' Wine's own
* xinput). No file = the session's game does not use dd-directinput.
*/
object DirectInputSwitch {
const val FILE = "dd-directinput.mode"
fun file(context: Context): File = File(LinuxRuntime.sessionRoot(context), "dev/$FILE")
/** The running game's mode, or null when it does not use dd-directinput. */
fun state(context: Context): Boolean? = runCatching {
when (file(context).takeIf { it.isFile }?.readText()?.trim()) {
"1" -> true
"0" -> false
else -> null
}
}.getOrNull()
/** Switches the running game now and remembers the choice for its next start. */
fun set(context: Context, on: Boolean) {
val app = context.applicationContext
Thread {
runCatching { file(app).takeIf { it.isFile }?.writeText(if (on) "1\n" else "0\n") }
val scope = NoSteamLaunch.scopeOf(SessionState.program, SessionState.programArgs) { NoSteamLaunch.battleNetTitleScope(app, it) }
if (!scope.isNullOrEmpty() && GameEnvironment.validScope(scope)) runCatching {
GameEnvironmentStore.save(app, GameEnvironment.withGameDirectInput(GameEnvironmentStore.read(app), scope, on))
}
}.start()
}
/** A session starts without the file: only a launch that uses dd-directinput writes it again. */
fun clear(context: Context) {
file(context).delete()
}
}
@@ -1249,6 +1249,7 @@ class SessionService : Service() {
}
private fun addControllerEnvironment(guest: MutableList<String>, fakeInputDir: File, sessionDir: File) {
DirectInputSwitch.clear(this)
FakeInputWriter.prepareRingSlots(fakeInputDir, 5)
val builtinPad = SessionPrefs.builtinPad(this)
val hiddenPad = SessionState.mode == MODE_STEAM && !builtinPad &&
@@ -414,6 +414,9 @@ class DrawerActions(
val unfoldedControls: Boolean? = null,
val adaptiveSticks: Boolean? = null,
val onAdaptiveSticks: (Boolean) -> Unit = {},
/** dd-directinput's mode for the running game; null = the game does not use it. */
val directInput: Boolean? = null,
val onDirectInput: (Boolean) -> Unit = {},
val showFloatingSteamControls: Boolean = false,
val oscRearButtons: Boolean = false,
val oscTrackpads: Boolean = false,
@@ -792,10 +795,12 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected:
val rumbleLabel = stringResource(R.string.ctrl_rumble)
val airTriggers = a.airTriggers
val airTriggersLabel = stringResource(R.string.air_triggers_title)
if (a.padType != null || c != null || airTriggers != null) SettingsGroup(
val directInputLabel = stringResource(R.string.ctrl_direct_input)
if (a.padType != null || c != null || airTriggers != null || a.directInput != null) SettingsGroup(
stringResource(R.string.input_device_settings), key = "controller-pad", tag = padTag,
detail = summary(a.padType?.let { padTypes.labelOf(it) }, c?.let { "$rumbleLabel ${if (it.rumble) on else off}" },
airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" }),
airTriggers?.let { "$airTriggersLabel ${if (it.enabled) on else off}" },
a.directInput?.let { "$directInputLabel ${if (it) on else off}" }),
) {
a.padType?.let { type ->
ChoiceRow(host, "pad-type", stringResource(R.string.input_virtual_controller), stringResource(R.string.input_virtual_controller_hint),
@@ -804,6 +809,9 @@ private fun DrawerControllerPage(host: MenuHost, a: DrawerActions, padConnected:
c?.let {
ToggleRow(host, "rumble", rumbleLabel, null, it.rumble, chipModifier = track("rumble"), onChange = a.onRumble)
}
a.directInput?.let {
ToggleRow(host, "direct-input", directInputLabel, null, it, chipModifier = track("direct-input"), onChange = a.onDirectInput)
}
airTriggers?.let {
ActionRow(airTriggersLabel, if (it.enabled) on else off, stringResource(R.string.air_triggers_open), onAirTriggers,
modifier = track("air-triggers"))
+1
View File
@@ -1505,6 +1505,7 @@
<string name="ctrl_size">Button size</string>
<string name="ctrl_adaptive">Adaptive sticks</string>
<string name="ctrl_rumble">Game vibration</string>
<string name="ctrl_direct_input">Direct input</string>
<string name="air_triggers_title">Redmagic Air Triggers</string>
<string name="air_triggers_open">Open</string>
<string name="air_triggers_use">Use Air Triggers</string>