mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(input): hide on physical controller use only and refresh the kit when the virtual controller changes
This commit is contained in:
1 parent
318d64f3d6
commit
e67c185f13
3 files changed
+32
-3
No files matched your search
@@ -878,6 +878,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
SessionState.deckPadListener = deckPadListener
|
||||
openDeckRing("activity created")
|
||||
bridge.setOnPlayerInput(::onPadInput)
|
||||
bridge.setOnPhysicalInput(::noteControllerUse)
|
||||
controllerInUse = PadBridge.anyControllerConnected() || SteamControllerBle.connected
|
||||
onScreenControls = OnScreenControls(this, bridge).also { controls ->
|
||||
controls.updateLayout(primaryInputLayout)
|
||||
@@ -1675,6 +1676,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setPadType(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.session.InputSysfsComponent.padTypeChanged(SessionPrefs.padType(id))
|
||||
padType = id
|
||||
refreshInputProfile()
|
||||
},
|
||||
backHold = backHold,
|
||||
onBackHold = { on ->
|
||||
@@ -3999,7 +4001,6 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
|
||||
private fun onPadInput() {
|
||||
noteControllerUse()
|
||||
if (inputUsesPointer && !pointerLocked) return
|
||||
lastPadInputMs = android.os.SystemClock.uptimeMillis()
|
||||
uiHandler.removeCallbacks(cursorHide)
|
||||
|
||||
@@ -107,6 +107,8 @@ public final class PadBridge {
|
||||
private volatile Runnable onPlayerInput;
|
||||
private Runnable onChordInput;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean playerInputPosted = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
private volatile Runnable onPhysicalInput;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean physicalInputPosted = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
|
||||
private static final long STATS_WINDOW_MS = 10_000;
|
||||
private int statButtons, statAxes, statOnScreen, statDropped;
|
||||
@@ -368,6 +370,20 @@ public final class PadBridge {
|
||||
onPlayerInput = listener;
|
||||
}
|
||||
|
||||
/** Input from a controller the player holds, never from the on-screen controls. */
|
||||
public void setOnPhysicalInput(Runnable listener) {
|
||||
onPhysicalInput = listener;
|
||||
}
|
||||
|
||||
private void notePhysicalInput() {
|
||||
Runnable listener = onPhysicalInput;
|
||||
if (listener == null || !physicalInputPosted.compareAndSet(false, true)) return;
|
||||
mainHandler.post(() -> {
|
||||
physicalInputPosted.set(false);
|
||||
listener.run();
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void setOnChordInput(Runnable listener) {
|
||||
onChordInput = listener;
|
||||
}
|
||||
@@ -433,7 +449,7 @@ public final class PadBridge {
|
||||
}
|
||||
noteDevice(device, slot);
|
||||
if (pressed && event.getRepeatCount() == 0 && !event.isCanceled()) noteChordInput(slot);
|
||||
if (pressed) notePlayerInput();
|
||||
if (pressed) { notePlayerInput(); notePhysicalInput(); }
|
||||
statButtons++;
|
||||
scheduleStats();
|
||||
publish(slot);
|
||||
@@ -521,7 +537,7 @@ public final class PadBridge {
|
||||
retainStick(slot, side, x, y);
|
||||
projectSticks(slot);
|
||||
if (chordStickInput) noteChordInput(slot);
|
||||
if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) notePlayerInput();
|
||||
if (Math.max(Math.abs(x), Math.abs(y)) > 0.5f) { notePlayerInput(); notePhysicalInput(); }
|
||||
publish(slot);
|
||||
InputTiming.end(timing);
|
||||
return true;
|
||||
@@ -563,6 +579,7 @@ public final class PadBridge {
|
||||
if (Math.max(Math.max(Math.abs(pad.leftX), Math.abs(pad.leftY)), Math.max(Math.abs(pad.rightX), Math.abs(pad.rightY))) > 0.5f
|
||||
|| lt > 0.5f || rt > 0.5f || pad.up || pad.right || pad.down || pad.left) {
|
||||
notePlayerInput();
|
||||
notePhysicalInput();
|
||||
}
|
||||
publish(slot);
|
||||
InputTiming.end(timing);
|
||||
|
||||
@@ -187,4 +187,15 @@ class InputSurfaceSourceTest {
|
||||
pad.update(0f, 0f)
|
||||
assertEquals("key:30:false", events.last())
|
||||
}
|
||||
|
||||
@Test fun onScreenInputNeverCountsAsAControllerInHand() {
|
||||
var physical = 0; var player = 0
|
||||
bridge.setOnPhysicalInput { physical++ }
|
||||
bridge.setOnPlayerInput { player++ }
|
||||
val stick = source(InputSurfaceElement(InputControl.LS, .1f, .1f, .3f, .3f, "legacy:ls", InputElementKind.STICK))
|
||||
stick.update(1f, 0f); stick.update(0f, 0f)
|
||||
org.robolectric.Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()
|
||||
assertEquals(0, physical)
|
||||
assertTrue(player > 0)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user