fix(input): preserve control visibility and routing

This commit is contained in:
Kurt Himebauch committed 2026-11-20 07:48:12 -05:00
1 parent 7c2955b058
commit 97e0251e6a
9 files changed
+103 -26

No files matched your search

@@ -30,6 +30,11 @@ class OnScreenControlPrefsTest {
session.edit().putString("osc", saved).commit()
assertEquals(saved, mode, SessionPrefs.oscMode(context))
}
session.edit().putString("osc", SessionPrefs.OSC_STEAM_TOUCH).commit()
assertEquals(SessionPrefs.OSC_ALWAYS, SessionPrefs.oscMode(context, steamSession = true))
SessionPrefs.setOscMode(context, SessionPrefs.OSC_AUTO)
assertEquals(SessionPrefs.OSC_AUTO, SessionPrefs.oscMode(context, steamSession = true))
assertTrue(SessionPrefs.steamTouchLayout(context))
}
@Test fun theOldSteamTouchModeBecomesTheSteamLayoutUntilChanged() {
@@ -24,7 +24,8 @@ class PhysicalInputBindingsTest {
override fun command(command: InputCommand) { events += command.name }
override fun requestMotion() {}
})
private val bindings = PhysicalInputBindings(router)
private val presses = ArrayList<Int>()
private val bindings = PhysicalInputBindings(router) { presses += it.deviceId }
private fun device(id: Int): InputDevice {
val device = InputDeviceBuilder.newBuilder().setId(id).setName("Thor extra keys").setDescriptor("keys-$id")
@@ -55,6 +56,7 @@ class PhysicalInputBindingsTest {
assertEquals(listOf("29 true", "30 true", "30 false", "29 false"), events)
bindings.onKey(event(device.id, true), true)
assertEquals("28 true", events.last())
assertEquals(listOf(device.id, device.id), presses)
}
@Test fun releasesRemainConsumedAfterOpeningMenuAndVirtualKeysAreUntouched() {
@@ -25,6 +25,7 @@ import java.util.UUID
@Config(sdk = [34], manifest = Config.NONE, shadows = [SteamControllerBleTest.Writer::class])
class SteamControllerBleTest {
private val keys = ArrayList<Pair<Int, Boolean>>()
private var presses = 0
private val router = InputRouter(object : InputOutput {
override fun key(code: Int, down: Boolean) { keys += code to down }
override fun button(code: Int, down: Boolean) {}
@@ -42,7 +43,7 @@ class SteamControllerBleTest {
Writer.features = 0
router.setProfile(InputProfile.defaults(InputProfile.GAME)
.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.Keys(listOf(57))))
controller = SteamControllerBle(RuntimeEnvironment.getApplication(), router)
controller = SteamControllerBle(RuntimeEnvironment.getApplication(), router) { presses++ }
handler = ReflectionHelpers.getField(controller, "handler")
shadowOf(handler.looper).pause()
controller.start()
@@ -60,6 +61,23 @@ class SteamControllerBleTest {
drain(handler.looper)
}
@Test fun newInputNotifiesOncePerPressOrStickDeflection() {
subscribe(controller)
val held = ByteArray(45).apply { this[1] = 1 }
val stick = held.copyOf().apply { this[10] = 80 }
state(ByteArray(45))
assertEquals(0, presses)
state(held)
state(held)
assertEquals(1, presses)
state(stick)
state(stick)
assertEquals(2, presses)
state(ByteArray(45))
state(held)
assertEquals(3, presses)
}
@Test fun stopReleasesAndDetachesInputBeforeQueuedCallbacksCanPublish() {
state(ByteArray(45).apply { this[1] = 1 })
assertEquals(listOf(57 to true), keys)