From b29a5ef8aa1207c9c4f306d6e9c6a166fc0aef31 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:19:02 -0500 Subject: [PATCH] feat(input): both sticks and both trackpads for Steam kits in portrait --- .../launcher/input/GamepadGeometry.kt | 23 ++++++++++++++++--- .../com/droiddeck/launcher/input/KitLayout.kt | 14 +++++++---- .../droiddeck/launcher/input/KitLayoutTest.kt | 7 +++--- .../launcher/input/OnScreenLayoutTest.kt | 3 ++- .../launcher/ui/GamepadGeometryTest.kt | 16 +++++++++++-- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt b/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt index 428995efe..d29064b78 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt @@ -9,6 +9,7 @@ object GamepadGeometry { VIEW, STEAM, QAM, MENU, PANELS, L4, L5, R5, R4, + LEFT_TOUCH, RIGHT_TOUCH, } data class Box(val cx: Float, val cy: Float, val width: Float, val height: Float) { @@ -26,10 +27,11 @@ object GamepadGeometry { fun tall(w: Float, h: Float): Boolean = h >= w * 0.45f - fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = true, upright: Boolean = false): Map { + fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = true, upright: Boolean = false, + trackpads: Boolean = false): Map { if (w <= 0f || h <= 0f) return emptyMap() if (upright || portraitDock && h >= w * 0.6f && w >= 300 * density && h >= 300 * density) { - return portraitLayout(w, h, density, grips) + return portraitLayout(w, h, density, grips, trackpads) } val pad = 8 * density val buttonH = 40 * density @@ -96,7 +98,7 @@ object GamepadGeometry { * The panel under a portrait game: shoulders with View and Menu across the top, the back grips under them when the kit has * them, then the d-pad and face buttons and, along the bottom edge, the sticks or trackpads, each as large as the panel allows. */ - private fun portraitLayout(w: Float, h: Float, density: Float, grips: Boolean): Map { + private fun portraitLayout(w: Float, h: Float, density: Float, grips: Boolean, trackpads: Boolean): Map { val pad = 8 * density val gap = 8 * density val buttonH = 44 * density @@ -114,6 +116,21 @@ object GamepadGeometry { areaTop += gripH + gap } val area = h - pad - areaTop - gap + if (trackpads) { + val second = min(w * 0.42f, area * 0.5f) + val rowH = area - second + val col = (w - 2 * pad - 3 * gap) / 4f + val stick = min(col, rowH) + val rowY = h - pad - rowH / 2f + val secondY = areaTop + second / 2f + boxes[Slot.LEFT_SECOND] = Box(w * 0.25f, secondY, second, second) + boxes[Slot.RIGHT_SECOND] = Box(w * 0.75f, secondY, second, second) + boxes[Slot.LEFT_TOUCH] = Box(pad + col / 2f, rowY, col, rowH) + boxes[Slot.LEFT_MAIN] = Box(pad + col * 1.5f + gap, rowY, stick, stick) + boxes[Slot.RIGHT_MAIN] = Box(w - pad - col * 1.5f - gap, rowY, stick, stick) + boxes[Slot.RIGHT_TOUCH] = Box(w - pad - col / 2f, rowY, col, rowH) + return boxes + } val main = min(w * 0.46f, area * 0.53f) val second = min(w * 0.42f, area - main) val secondY = areaTop + second / 2f diff --git a/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt b/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt index 3d7e5f915..d8dcf7fb9 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt @@ -118,7 +118,7 @@ object KitLayout { val inner = (w - safe.left - safe.right).coerceAtLeast(1f) val area = (min(h * .6f, inner * 1.15f) * scale).coerceAtMost(h - safe.top - safe.bottom - row).coerceAtLeast(1f) val top = h - safe.bottom - row - area - val pad = dock(context, kit, inner.toInt(), area.toInt(), true, InputControl.LS, if (kit.steam) InputControl.RIGHT_PAD else InputControl.RS, upright = true).map { e -> + val pad = dock(context, kit, inner.toInt(), area.toInt(), true, InputControl.LS, InputControl.RS, upright = true).map { e -> e.copy(x = (safe.left + e.x * inner) / w, y = (top + e.y * area) / h, width = e.width * inner / w, height = e.height * area / h, floating = e.kind == InputElementKind.STICK) } @@ -154,7 +154,8 @@ object KitLayout { fun dock(context: Context, kit: PadKit, width: Int, height: Int, portrait: Boolean, left: InputControl, right: InputControl, upright: Boolean = false): List { val w = width.toFloat(); val h = height.toFloat() - val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright) + val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright, + trackpads = kit.steam) val placed = mutableListOf() fun put(control: InputControl, box: GamepadGeometry.Box?, shape: InputButtonShape, id: String = "legacy:${control.id}", kind: InputElementKind = InputElementKind.from(control), name: String = kit.name(control)) { @@ -162,8 +163,13 @@ object KitLayout { placed += InputSurfaceElement(control, b.left / w, b.top / h, b.width / w, b.height / h, id, kind, name, floating = false, buttonShape = shape).bounded() } fun square(box: GamepadGeometry.Box?) = box?.let { val side = min(it.width, it.height); GamepadGeometry.Box(it.cx, it.cy, side, side) } - val leftMain = if (kit.steam || left != InputControl.LEFT_PAD) left else InputControl.LS - val rightMain = if (kit.steam || right != InputControl.RIGHT_PAD) right else InputControl.RS + val four = GamepadGeometry.Slot.LEFT_TOUCH in boxes + val leftMain = if (four || !kit.steam && left == InputControl.LEFT_PAD) InputControl.LS else left + val rightMain = if (four || !kit.steam && right == InputControl.RIGHT_PAD) InputControl.RS else right + if (four) { + put(InputControl.LEFT_PAD, boxes[GamepadGeometry.Slot.LEFT_TOUCH], InputButtonShape.ROUNDED) + put(InputControl.RIGHT_PAD, boxes[GamepadGeometry.Slot.RIGHT_TOUCH], InputButtonShape.ROUNDED) + } put(leftMain, square(boxes[GamepadGeometry.Slot.LEFT_MAIN]), InputButtonShape.CIRCLE) put(InputControl.LS, square(boxes[GamepadGeometry.Slot.LEFT_SECOND]), InputButtonShape.ROUNDED, DPAD_ID, InputElementKind.DPAD, "D-pad") put(rightMain, square(boxes[GamepadGeometry.Slot.RIGHT_MAIN]), InputButtonShape.CIRCLE) diff --git a/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt b/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt index f64aec385..b39dd6321 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt @@ -220,7 +220,8 @@ class KitLayoutTest { assertTrue("$kit $w x $h", bottomRow.any { it.id == KitLayout.KEYBOARD_ID } && bottomRow.any { it.control == InputControl.QAM }) assertTrue("$kit $w x $h", bottomRow.minOf { it.x } * w >= 52 * density - .5f) val stick = elements.first { it.id == "legacy:ls" } - assertTrue("$kit $w x $h", stick.width * w >= w * .3f) + assertTrue("$kit $w x $h", stick.width * w >= w * if (kit.steam) .2f else .3f) + assertTrue("$kit $w x $h", elements.any { it.id == "legacy:rs" }) } } @@ -244,8 +245,8 @@ class KitLayoutTest { @Test fun onlySteamKitsPutTrackpadsInTheDockedStrip() { for (kit in PadKit.entries) { val placed = KitLayout.dock(context, kit, 1080, 1300, true, InputControl.LS, InputControl.RIGHT_PAD).map { it.control } - assertEquals(kit.toString(), kit.steam, InputControl.RIGHT_PAD in placed) - assertEquals(kit.toString(), !kit.steam, InputControl.RS in placed) + assertEquals(kit.toString(), kit.steam, InputControl.RIGHT_PAD in placed && InputControl.LEFT_PAD in placed) + assertTrue(kit.toString(), InputControl.RS in placed && InputControl.LS in placed) } } diff --git a/app/src/test/java/com/droiddeck/launcher/input/OnScreenLayoutTest.kt b/app/src/test/java/com/droiddeck/launcher/input/OnScreenLayoutTest.kt index e07362e25..31bd54aa0 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/OnScreenLayoutTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/OnScreenLayoutTest.kt @@ -141,7 +141,8 @@ class OnScreenLayoutTest { for ((size, portrait) in listOf((2208 to 800) to false, (1080 to 1300) to true)) { val (w, h) = size val placed = OnScreenLayout.elements(context, gamepad(), w, h, Rect(), dock = OnScreenLayout.Dock(portrait, grips = true)) - val boxes = GamepadGeometry.layout(w.toFloat(), h.toFloat(), density, portrait) + val steam = PadKit.current(context).steam + val boxes = GamepadGeometry.layout(w.toFloat(), h.toFloat(), density, portrait, grips = steam, trackpads = steam) val ls = placed.first { it.id == "legacy:ls" } val box = boxes.getValue(GamepadGeometry.Slot.LEFT_MAIN) assertEquals(box.left, ls.x * w, 1f) diff --git a/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt index 360af6f63..72e566cd3 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/GamepadGeometryTest.kt @@ -38,7 +38,7 @@ class GamepadGeometryTest { @Test fun everyControlIsPlacedAndPanelsOnlyWhenUpright() { for (panel in panels) { val upright = panel.height > panel.width - val expected = Slot.values().toSet() - grips - if (upright) emptySet() else setOf(Slot.PANELS) + val expected = Slot.values().toSet() - grips - setOf(Slot.LEFT_TOUCH, Slot.RIGHT_TOUCH) - if (upright) emptySet() else setOf(Slot.PANELS) assertEquals(panel.name, expected, boxes(panel).keys) } } @@ -94,7 +94,7 @@ class GamepadGeometryTest { @Test fun portraitDockPlacesAllControlsWithinThePanel() { for (panel in portraitPanels) { val b = portraitBoxes(panel) - assertEquals(panel.name, Slot.values().toSet() - setOf(Slot.STEAM, Slot.QAM, Slot.PANELS), b.keys) + assertEquals(panel.name, Slot.values().toSet() - setOf(Slot.STEAM, Slot.QAM, Slot.PANELS, Slot.LEFT_TOUCH, Slot.RIGHT_TOUCH), b.keys) for ((slot, box) in b) { val where = "${panel.name}: $slot $box" assertTrue(where, box.left >= 0f && box.top >= 0f) @@ -161,4 +161,16 @@ class GamepadGeometryTest { GamepadGeometry.layout(width, height, density, portraitDock = true)) } } + + @Test fun aPortraitDockWithTrackpadsPutsThemOutsideBothSticksWithoutOverlap() { + for (panel in portraitPanels) { + val b = GamepadGeometry.layout(panel.width.toFloat(), panel.controlsHeight.toFloat(), panel.density, portraitDock = true, trackpads = true) + val row = listOf(Slot.LEFT_TOUCH, Slot.LEFT_MAIN, Slot.RIGHT_MAIN, Slot.RIGHT_TOUCH) + assertEquals(panel.name, row, row.sortedBy { b.getValue(it).cx }) + val placed = b.entries.toList() + for (i in placed.indices) for (j in i + 1 until placed.size) + assertFalse("${panel.name}: ${placed[i].key} overlaps ${placed[j].key}", placed[i].value.overlaps(placed[j].value)) + for ((slot, box) in b) assertTrue("${panel.name}: $slot", box.bottom <= panel.controlsHeight + .5f && box.right <= panel.width + .5f) + } + } }