mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Steam's touch controller as on-screen controls (beta) (#431)
* feat: Steam's touch controller as on-screen controls (beta) * fix: Steam touch controls appear once the session makes the device; tidier default layout * fix: Steam touch layout decoding, saved layouts and new sessions * docs: Steam's touch controls * feat: Steam's touch icons, labels and colours on the touch controls; pick and save them like Steam * feat: Steam touch icon picker as in-session panels; layout colour; docs * Give each physical controller its own player slot Every controller fed the one exported pad, so two pads played as one. The first controller keeps slot 0 (the Deck in a Steam session); further ones get slots 1-3 as separate Xbox 360 pads, created on first input and removed on disconnect. In Deck mode only the Steam client sees those pads and hands them to games through Steam Input. Rumble follows the slot it names. * feat: Steam Link's touch menu, per-game input modes, action set editing, add/copy/paste, oval controls, paste control * feat: Steam touch controls drawn as Steam Link draws them; Steam Link's touch menu and layout tray * feat: Steam touch controls in DroidDeck's style, D-mark guide button, shake to hide * refactor: Steam touch controls become an On-screen controls choice instead of a second dropdown --------- Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
1 parent
a6d15bcd0b
commit
0da45e53cb
23 files changed
+4160
-94
No files matched your search
@@ -0,0 +1,118 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class SteamTouchBindingsTest {
|
||||
private val config = """
|
||||
"controller_mappings"
|
||||
{
|
||||
"version" "3"
|
||||
"controller_type" "controller_mobile_touch"
|
||||
"group"
|
||||
{
|
||||
"id" "0"
|
||||
"mode" "four_buttons"
|
||||
"inputs"
|
||||
{
|
||||
"button_a"
|
||||
{
|
||||
"activators"
|
||||
{
|
||||
"Full_Press"
|
||||
{
|
||||
"bindings"
|
||||
{
|
||||
"binding" "xinput_button A, , "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"button_b"
|
||||
{
|
||||
"activators"
|
||||
{
|
||||
"Full_Press"
|
||||
{
|
||||
"bindings"
|
||||
{
|
||||
"binding" "key_press ESCAPE, Pause, ghost_050_menu_0020.png, #FFFFFF #AD0000"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"group"
|
||||
{
|
||||
"id" "9"
|
||||
"mode" "dpad"
|
||||
"inputs"
|
||||
{
|
||||
"dpad_north"
|
||||
{
|
||||
"activators"
|
||||
{
|
||||
"Full_Press"
|
||||
{
|
||||
"bindings"
|
||||
{
|
||||
"binding" "xinput_button DPAD_UP, , "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"preset"
|
||||
{
|
||||
"id" "0"
|
||||
"name" "Default"
|
||||
"group_source_bindings"
|
||||
{
|
||||
"0" "button_diamond active"
|
||||
"9" "dpad active"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
private val mappings = KeyValues.parse(config).child("controller_mappings")!!
|
||||
|
||||
@Test
|
||||
fun parsesAndComposesSteamsFormat() {
|
||||
val b = SteamTouchBindings.parse("key_press ESCAPE, Pause, ghost_050_menu_0020.png, #FFFFFF #AD0000")
|
||||
assertEquals("key_press ESCAPE", b.action)
|
||||
assertEquals("Pause", b.label)
|
||||
assertEquals("ghost_050_menu_0020.png", b.icon)
|
||||
assertEquals("#FFFFFF", b.foreground)
|
||||
assertEquals("#AD0000", b.background)
|
||||
assertEquals("key_press ESCAPE, Pause, ghost_050_menu_0020.png, #FFFFFF #AD0000", b.compose())
|
||||
assertEquals("xinput_button A, , ", SteamTouchBindings.parse("xinput_button A, , ").compose())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun findsEachControlsBinding() {
|
||||
val b = SteamTouchBindings.refsFor(mappings, SteamTouchConfig.B, 0).single()!!
|
||||
assertEquals(SteamTouchBindings.Ref("0", "button_b"), b)
|
||||
assertEquals("ghost_050_menu_0020.png", SteamTouchBindings.bindingAt(mappings, b)!!.icon)
|
||||
val dpad = SteamTouchBindings.refsFor(mappings, SteamTouchConfig.DPAD, 0)
|
||||
assertEquals(4, dpad.size)
|
||||
assertEquals("xinput_button DPAD_UP", SteamTouchBindings.bindingAt(mappings, dpad[0]!!)!!.action)
|
||||
assertNull(SteamTouchBindings.refsFor(mappings, SteamTouchConfig.BUMPER_LEFT, 0).single())
|
||||
assertEquals("Esc", SteamTouchBindings.glyph(SteamTouchBindings.parse("key_press ESCAPE, , ")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rewritesOnlyThatBinding() {
|
||||
val ref = SteamTouchBindings.Ref("0", "button_a")
|
||||
val out = SteamTouchBindings.rewrite(config, ref) { it.copy(label = "Jump", icon = "ghost_045_move_0400.png", foreground = "#232323", background = "#E4E4E4") }
|
||||
assertNotNull(out)
|
||||
assertEquals(config.replace("\"xinput_button A, , \"", "\"xinput_button A, Jump, ghost_045_move_0400.png, #232323 #E4E4E4\""), out)
|
||||
val reparsed = KeyValues.parse(out!!).child("controller_mappings")!!
|
||||
assertEquals("Jump", SteamTouchBindings.bindingAt(reparsed, ref)!!.label)
|
||||
assertNull(SteamTouchBindings.rewrite(config, SteamTouchBindings.Ref("5", "button_a")) { it })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class SteamTouchConfigTest {
|
||||
// A layout DroidDeck saved for Geometry Wars on the Thor, as Steam keeps it.
|
||||
private val saved = "0aec0310012218080010011d0000703d255555d53d2d0000803f350000803f2218080110011d6666fe3e255555d53d2d0000803f350000803f2218080210011dba490c3e255c8f423f2d0000803f350000803f2218080410011d9a99593f255c8f423f2d0000803f350000803f2218080510011d8fc2353f25ae47613f2d0000803f350000803f2218080610011d2b87163e25d7a3f03e2d0000803f350000803f2218080710011dba49003f25f958053f2d293ab23f35293ab23f2218080810011d9a99683f25d227dd3e2d0000803f350000803f2218080910011d9a99483f25d227dd3e2d0000803f350000803f2218080a10011d9a99583f254444a43e2d0000803f350000803f2218080b10011d6666ce3e255555d53d2d0000803f350000803f2218080c10011d3333173f255555d53d2d0000803f350000803f2218080d10011d0ad7233e2585eb513e2d0000803f350000803f2218080e10011d3d0a573f2585eb513e2d0000803f350000803f2218080f10011d8fc2753d2585eb513e2d0000803f350000803f2218081010011dd7a3703f2585eb513e2d0000803f350000803f2218081c10011d0000713f255555d53d2d0000803f350000803f2218080310001de17a943e25ae47613f2d0000803f350000803f2a140d0000803f150000803f1d0000803f25cdcccc3e1002"
|
||||
|
||||
@Test
|
||||
fun decodesSavedLayout() {
|
||||
val layouts = SteamTouchConfig.decodeLayouts(SteamTouchConfig.hexToBytes(saved))
|
||||
assertEquals(1, layouts.layouts.size)
|
||||
val layout = layouts.forActionSet(1)!!
|
||||
val a = layout.elements.first { it.type == SteamTouchConfig.A }
|
||||
assertEquals(0.501f, a.x, 0.002f)
|
||||
assertEquals(1.39f, a.xScale, 0.01f)
|
||||
assertFalse(layout.elements.first { it.type == SteamTouchConfig.JOYSTICK_LEFT_BUTTON }.visible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roundTrips() {
|
||||
val bytes = SteamTouchConfig.hexToBytes(saved)
|
||||
assertEquals(saved, SteamTouchConfig.bytesToHex(SteamTouchConfig.encodeLayouts(SteamTouchConfig.decodeLayouts(bytes))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appliesLayoutToElements() {
|
||||
val layouts = SteamTouchConfig.decodeLayouts(SteamTouchConfig.hexToBytes(saved))
|
||||
val all = (0..31).toSet()
|
||||
val config = SteamTouchConfig.Config(null, null, layouts, mapOf(0 to all))
|
||||
val shown = SteamTouchConfig.elementsFor(config, 0, emptyList())
|
||||
val a = shown.first { it.type == SteamTouchConfig.A }
|
||||
assertEquals(0.501f, a.x, 0.002f)
|
||||
assertTrue(shown.none { it.type == SteamTouchConfig.JOYSTICK_LEFT_BUTTON })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun optionsRoundTripAndKeepTheRest() {
|
||||
val layouts = SteamTouchConfig.decodeLayouts(SteamTouchConfig.hexToBytes(saved))
|
||||
assertEquals(SteamTouchConfig.INPUT_CONTROLLER, layouts.options.inputMode)
|
||||
val next = SteamTouchConfig.Options(SteamTouchConfig.INPUT_BOTH, SteamTouchConfig.MOUSE_RELATIVE, 1.75f)
|
||||
val rest = next.encodeInto(layouts.rest)
|
||||
assertEquals(next, SteamTouchConfig.Options.decode(rest))
|
||||
val again = SteamTouchConfig.decodeLayouts(SteamTouchConfig.encodeLayouts(SteamTouchConfig.Layouts(layouts.layouts, rest)))
|
||||
assertEquals(next, again.options)
|
||||
assertEquals(layouts.layouts.size, again.layouts.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listsActionSets() {
|
||||
val kv = KeyValues.parse("""
|
||||
"controller_mappings"
|
||||
{
|
||||
"actions"
|
||||
{
|
||||
"Default" { "title" "Desktop" }
|
||||
"Preset_1000001" { "title" "Gamepad" }
|
||||
}
|
||||
"preset" { "id" "0" "name" "Default" }
|
||||
"preset" { "id" "1" "name" "Preset_1000001" }
|
||||
}
|
||||
""").child("controller_mappings")
|
||||
val config = SteamTouchConfig.Config(null, null, null, emptyMap(), kv)
|
||||
assertEquals(listOf(1 to "Desktop", 2 to "Gamepad"), SteamTouchConfig.actionSets(config))
|
||||
}
|
||||
}
|
||||
@@ -115,16 +115,41 @@ class RumbleComponentTest {
|
||||
assertFalse(pad.vibrating)
|
||||
}
|
||||
|
||||
@After fun clearActiveController() { activeController(PadBridge.NO_CONTROLLER) }
|
||||
|
||||
private fun activeController(id: Int) {
|
||||
PadBridge::class.java.getDeclaredField("activeControllerId").apply { isAccessible = true }.setInt(null, id)
|
||||
@Test fun eachPlayerSlotRumblesItsOwnControllerAndVirtualPadsUseTheLastActive() {
|
||||
val first = FakeMotors()
|
||||
val second = FakeMotors()
|
||||
rumble.controllerMotors = { id -> if (id == PAD_ID) first else if (id == SECOND_PAD_ID) second else null }
|
||||
activeController(PAD_ID)
|
||||
activeController(SECOND_PAD_ID, slot = 1)
|
||||
effect(strong = 100, weak = 0, slot = 1)
|
||||
assertEquals(listOf(Triple(100, 0, 5000L)), second.played)
|
||||
assertTrue(first.played.isEmpty())
|
||||
effect(strong = 200, weak = 0)
|
||||
assertEquals(listOf(Triple(200, 0, 5000L)), first.played)
|
||||
assertTrue("one player's effect ended another's", second.vibrating)
|
||||
effect(strong = 0, weak = 0, slot = 1)
|
||||
assertFalse(second.vibrating)
|
||||
assertTrue(first.vibrating)
|
||||
effect(strong = 300, weak = 0, slot = 16)
|
||||
assertEquals(Triple(300, 0, 5000L), second.played.last())
|
||||
assertFalse(shadowOf(vibrator).isVibrating)
|
||||
}
|
||||
|
||||
private fun effect(strong: Int = 65535, weak: Int = 65535) {
|
||||
@After fun clearActiveController() {
|
||||
for (slot in 0 until PadBridge.SLOTS) activeController(PadBridge.NO_CONTROLLER, slot)
|
||||
}
|
||||
|
||||
private fun activeController(id: Int, slot: Int = 0) {
|
||||
PadBridge::class.java.getDeclaredField("activeControllerId").apply { isAccessible = true }.setInt(null, id)
|
||||
val slots = PadBridge::class.java.getDeclaredField("slotControllers").apply { isAccessible = true }.get(null)
|
||||
(slots as java.util.concurrent.atomic.AtomicIntegerArray).set(slot, id)
|
||||
}
|
||||
|
||||
private fun effect(strong: Int = 65535, weak: Int = 65535, slot: Int = 0) {
|
||||
// Inject a decoded force-feedback packet; transport is outside these tests.
|
||||
RumbleComponent::class.java.getDeclaredMethod("buzz", Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType)
|
||||
.apply { isAccessible = true }.invoke(rumble, strong, weak, 5000)
|
||||
val int = Int::class.javaPrimitiveType
|
||||
RumbleComponent::class.java.getDeclaredMethod("buzz", int, int, int, int)
|
||||
.apply { isAccessible = true }.invoke(rumble, strong, weak, 5000, slot)
|
||||
}
|
||||
|
||||
private class FakeMotors : RumbleComponent.Motors {
|
||||
@@ -135,7 +160,10 @@ class RumbleComponentTest {
|
||||
override fun cancel() { vibrating = false }
|
||||
}
|
||||
|
||||
private companion object { const val PAD_ID = 7 }
|
||||
private companion object {
|
||||
const val PAD_ID = 7
|
||||
const val SECOND_PAD_ID = 8
|
||||
}
|
||||
|
||||
@Implements(LocalServerSocket::class)
|
||||
class NoPacketsSocket {
|
||||
|
||||
Reference in new issue
Block a user