mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix: preserve input lifecycle and system actions
Keep unused pad rings closed during profile and enable changes. Route Steam menu and VR stick-switch pulses independently of primary bindings, preserving physical holds and cancelling stale releases. Seed replacement routes with retained source state and require held controls to return to neutral. Add nine regressions and document validation: 2,239 JVM tests and the debug APK build pass; device validation remains pending.
This commit is contained in:
1 parent
d202233beb
commit
1dae4bf8ee
9 files changed
+279
-19
No files matched your search
@@ -1105,10 +1105,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
private fun sendSteamGuide() {
|
||||
drawerOpen = false
|
||||
padBridge?.applyTouch { state -> state.press(com.droiddeck.launcher.input.PadState.GUIDE, true) }
|
||||
uiHandler.postDelayed({
|
||||
padBridge?.applyTouch { state -> state.press(com.droiddeck.launcher.input.PadState.GUIDE, false) }
|
||||
}, 90)
|
||||
padBridge?.triggerSteamMenu()
|
||||
}
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
@@ -1151,12 +1148,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
/** The SteamVR driver switches pad sticks between hands and game on both stick clicks together. */
|
||||
private fun switchVrSticks() {
|
||||
val chord = { down: Boolean -> padBridge?.applyTouch { state ->
|
||||
state.press(com.droiddeck.launcher.input.PadState.L3, down)
|
||||
state.press(com.droiddeck.launcher.input.PadState.R3, down)
|
||||
} }
|
||||
chord(true)
|
||||
uiHandler.postDelayed({ chord(false) }, 120)
|
||||
padBridge?.triggerVrStickSwitch()
|
||||
}
|
||||
|
||||
private fun triggerSteamQam() {
|
||||
|
||||
@@ -16,6 +16,7 @@ object DeckControls {
|
||||
|
||||
@Synchronized
|
||||
fun setRouter(next: InputRouter?) {
|
||||
if (router === next) return
|
||||
for (source in sources) source.closeRoutes()
|
||||
router = next
|
||||
for (source in sources) source.configure()
|
||||
@@ -61,7 +62,11 @@ object DeckControls {
|
||||
internal val axes = ShortArray(4)
|
||||
|
||||
internal fun configure() {
|
||||
routes = router?.let { r -> Array(8) { r.channel(role, controls[it]) } }
|
||||
routes = router?.let { r -> Array(8) { i ->
|
||||
r.channel(role, controls[i]).also { it.awaitNeutral(x[i], y[i], touched[i]) }
|
||||
} }
|
||||
mask = 0
|
||||
axes.fill(0)
|
||||
}
|
||||
|
||||
private fun attach() {
|
||||
|
||||
@@ -48,8 +48,9 @@ class InputRouter(private val output: InputOutput) {
|
||||
moving = false
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
@Synchronized
|
||||
fun pad(role: InputRole): PadSource = PadSource(role).also { pads.add(it) }
|
||||
fun pad(role: InputRole, retained: PadState? = null): PadSource = PadSource(role, retained).also { pads.add(it) }
|
||||
|
||||
@Synchronized
|
||||
fun channel(role: InputRole, control: InputControl, fixedAction: InputAction? = null): Channel = Channel(role, control, fixedAction).also {
|
||||
@@ -128,6 +129,11 @@ class InputRouter(private val output: InputOutput) {
|
||||
x = value; y = second; contact = touching
|
||||
}
|
||||
|
||||
internal fun awaitNeutral(value: Float, second: Float, touching: Boolean) = synchronized(this@InputRouter) {
|
||||
observe(value, second, touching)
|
||||
suspend()
|
||||
}
|
||||
|
||||
internal fun nativeIdentity(): Boolean = enabled && !blocked && (action as? InputAction.Native)?.target == null && action is InputAction.Native
|
||||
|
||||
internal fun suspend() {
|
||||
@@ -218,14 +224,20 @@ class InputRouter(private val output: InputOutput) {
|
||||
}
|
||||
}
|
||||
|
||||
inner class PadSource internal constructor(role: InputRole) {
|
||||
inner class PadSource internal constructor(role: InputRole, retained: PadState?) {
|
||||
private val routes = Array(InputControl.padControls.size) { channel(role, InputControl.padControls[it]) }
|
||||
private val result = PadState()
|
||||
private var last: PadState? = null
|
||||
private var identity = true
|
||||
private var nativeCandidate = true
|
||||
|
||||
init { refreshIdentity() }
|
||||
init {
|
||||
last = retained
|
||||
if (retained != null) for (route in routes) {
|
||||
route.awaitNeutral(retained.value(route.control), retained.secondValue(route.control), false)
|
||||
}
|
||||
refreshIdentity()
|
||||
}
|
||||
|
||||
internal fun refreshIdentity() {
|
||||
nativeCandidate = routes.all { (it.action as? InputAction.Native)?.target == null && it.action is InputAction.Native }
|
||||
|
||||
@@ -80,6 +80,8 @@ public final class PadBridge {
|
||||
private boolean qamTapPressed;
|
||||
private boolean guideTapPressed;
|
||||
private int guideTapGeneration;
|
||||
private boolean vrStickTapPressed;
|
||||
private int vrStickTapGeneration;
|
||||
private boolean routedQamPressed;
|
||||
private int qamChordGeneration;
|
||||
private volatile Runnable onPlayerInput;
|
||||
@@ -129,8 +131,10 @@ public final class PadBridge {
|
||||
for (InputRouter.PadSource route : physicalRoutes) if (route != null) route.close();
|
||||
for (TouchSource source : touchSources.values()) if (source.route != null) source.route.close();
|
||||
inputRouter = router;
|
||||
for (int slot = 0; slot < SLOTS; slot++) physicalRoutes[slot] = router == null ? null : router.pad(InputRole.PHYSICAL);
|
||||
for (TouchSource source : touchSources.values()) source.route = router == null ? null : router.pad(source.role);
|
||||
for (int slot = 0; slot < SLOTS; slot++) physicalRoutes[slot] = router == null ? null : router.pad(InputRole.PHYSICAL, stateFor(slot));
|
||||
for (TouchSource source : touchSources.values()) source.route = router == null ? null : router.pad(source.role, source.raw);
|
||||
if (open) publish();
|
||||
for (int slot = 1; slot < SLOTS; slot++) if (playerWriters[slot] != null) publish(slot);
|
||||
}
|
||||
|
||||
public synchronized boolean hasInputRouter() { return inputRouter != null; }
|
||||
@@ -138,14 +142,14 @@ public final class PadBridge {
|
||||
public synchronized void setInputProfile(InputProfile profile) {
|
||||
if (inputRouter == null) return;
|
||||
inputRouter.setProfile(profile);
|
||||
publish();
|
||||
if (open) publish();
|
||||
for (int slot = 1; slot < SLOTS; slot++) if (playerWriters[slot] != null) publish(slot);
|
||||
}
|
||||
|
||||
public synchronized void setInputEnabled(boolean enabled) {
|
||||
if (inputRouter == null) return;
|
||||
inputRouter.setEnabled(enabled);
|
||||
publish();
|
||||
if (open) publish();
|
||||
for (int slot = 1; slot < SLOTS; slot++) if (playerWriters[slot] != null) publish(slot);
|
||||
DeckControls.INSTANCE.refresh();
|
||||
}
|
||||
@@ -181,6 +185,8 @@ public final class PadBridge {
|
||||
qamTapPressed = false;
|
||||
guideTapPressed = false;
|
||||
guideTapGeneration++;
|
||||
vrStickTapPressed = false;
|
||||
vrStickTapGeneration++;
|
||||
qamChordActive = false;
|
||||
chordButtonPressed = false;
|
||||
qamChordGeneration++;
|
||||
@@ -200,6 +206,8 @@ public final class PadBridge {
|
||||
public synchronized void stop() {
|
||||
guideTapPressed = false;
|
||||
guideTapGeneration++;
|
||||
vrStickTapPressed = false;
|
||||
vrStickTapGeneration++;
|
||||
if (inputRouter != null) inputRouter.releaseAll();
|
||||
for (TouchSource source : touchSources.values()) if (source.route != null) source.route.close();
|
||||
touchSources.clear();
|
||||
@@ -522,6 +530,8 @@ public final class PadBridge {
|
||||
|
||||
public synchronized void releaseAll() {
|
||||
guideTapGeneration++;
|
||||
vrStickTapPressed = false;
|
||||
vrStickTapGeneration++;
|
||||
routedQamPressed = false;
|
||||
systemGuidePressed = false;
|
||||
systemQamPressed = false;
|
||||
@@ -580,6 +590,20 @@ public final class PadBridge {
|
||||
}, 90);
|
||||
}
|
||||
|
||||
public synchronized void triggerVrStickSwitch() {
|
||||
if (!builtinPad || vrStickTapPressed) return;
|
||||
vrStickTapPressed = true;
|
||||
int generation = ++vrStickTapGeneration;
|
||||
publish();
|
||||
chordHandler.postDelayed(() -> {
|
||||
synchronized (PadBridge.this) {
|
||||
if (generation != vrStickTapGeneration) return;
|
||||
vrStickTapPressed = false;
|
||||
publish();
|
||||
}
|
||||
}, 120);
|
||||
}
|
||||
|
||||
private synchronized void releaseQamTap(int generation) {
|
||||
if (generation != qamChordGeneration || !qamTapPressed) return;
|
||||
qamTapPressed = false;
|
||||
@@ -794,7 +818,7 @@ public final class PadBridge {
|
||||
statDropped++;
|
||||
return;
|
||||
}
|
||||
if (!guide && !qam && (!routedQam || nativeQam())) {
|
||||
if (!guide && !qam && !vrStickTapPressed && (!routedQam || nativeQam())) {
|
||||
writer.writePad(output);
|
||||
return;
|
||||
}
|
||||
@@ -803,6 +827,10 @@ public final class PadBridge {
|
||||
if (guide) effectiveState.press(PadState.GUIDE, true);
|
||||
if (qam) effectiveState.press(PadState.QAM, true);
|
||||
if (chordButtonPressed) effectiveState.press(chordButton, true);
|
||||
if (vrStickTapPressed) {
|
||||
effectiveState.press(PadState.L3, true);
|
||||
effectiveState.press(PadState.R3, true);
|
||||
}
|
||||
writer.writePad(effectiveState);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user