diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 3b5166bf5a..ce682e467b 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -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(null) + private var directInput by mutableStateOf(null) private var quickButtons by mutableStateOf>(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), diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt index 711a50eca3..914afb96e0 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironment.kt @@ -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? = diff --git a/app/src/main/java/com/droiddeck/launcher/session/DirectInputSwitch.kt b/app/src/main/java/com/droiddeck/launcher/session/DirectInputSwitch.kt new file mode 100644 index 0000000000..1b2105cbc1 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/session/DirectInputSwitch.kt @@ -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() + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index fb6d3503f8..82b4ec8e2d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1249,6 +1249,7 @@ class SessionService : Service() { } private fun addControllerEnvironment(guest: MutableList, fakeInputDir: File, sessionDir: File) { + DirectInputSwitch.clear(this) FakeInputWriter.prepareRingSlots(fakeInputDir, 5) val builtinPad = SessionPrefs.builtinPad(this) val hiddenPad = SessionState.mode == MODE_STEAM && !builtinPad && diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 6e843c212d..2b30ff8d9c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -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")) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ae5278bcf8..3d484765b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1505,6 +1505,7 @@ Button size Adaptive sticks Game vibration + Direct input Redmagic Air Triggers Open Use Air Triggers