From 318d64f3d6bcfec2550e0b9f91b096bdcd2a279a Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:04:00 -0500 Subject: [PATCH] fix(input): keep Steam grips on a small portrait pad and fit the bottom row --- .../launcher/input/GamepadGeometry.kt | 4 ++-- .../com/droiddeck/launcher/input/KitLayout.kt | 21 ++++++++++++------- .../droiddeck/launcher/input/KitLayoutTest.kt | 13 ++++++++++++ 3 files changed, 28 insertions(+), 10 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 e8e16d712..428995efe 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/GamepadGeometry.kt @@ -26,9 +26,9 @@ 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): Map { + fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = true, upright: Boolean = false): Map { if (w <= 0f || h <= 0f) return emptyMap() - if (portraitDock && h >= w * 0.6f && w >= 300 * density && h >= 300 * density) { + if (upright || portraitDock && h >= w * 0.6f && w >= 300 * density && h >= 300 * density) { return portraitLayout(w, h, density, grips) } val pad = 8 * density 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 560b22010..3d7e5f915 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/KitLayout.kt @@ -118,13 +118,18 @@ 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).map { e -> + 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 -> 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) } val specs = specs(kit) fun spec(control: InputControl, id: String = "legacy:${control.id}") = specs.firstOrNull { it.control == control && it.id == id } - val size = BUTTON_DP * density + val gap = GAP_DP * density + val leftRow = listOfNotNull(spec(InputControl.A, KEYBOARD_ID), spec(InputControl.GUIDE).takeIf { kit.steam }, spec(InputControl.L3)) + val rightRow = listOfNotNull(spec(InputControl.QAM), spec(InputControl.GUIDE).takeIf { !kit.steam }, spec(InputControl.R3)) + val start = safe.left + CORNER_DP * density + val span = (w - safe.right - gap - start - gap * (leftRow.size + rightRow.size - 1)).coerceAtLeast(1f) + val size = min(BUTTON_DP * density, span / (leftRow + rightRow).sumOf { (it.hw / it.hh).toDouble() }.toFloat()) val cy = h - safe.bottom - row / 2f val placed = mutableListOf() fun put(s: Spec, cx: Float) { @@ -132,14 +137,13 @@ object KitLayout { placed += InputSurfaceElement(s.control, (cx - bw / 2) / w, (cy - size / 2) / h, bw / w, size / h, s.id, s.kind, if (s.name == s.control.label) kit.name(s.control) else s.name, buttonShape = s.shape, icon = s.icon) } - val gap = GAP_DP * density - var left = safe.left + CORNER_DP * density - for (s in listOfNotNull(spec(InputControl.A, KEYBOARD_ID), spec(InputControl.GUIDE).takeIf { kit.steam }, spec(InputControl.L3))) { + var left = start + for (s in leftRow) { val bw = size * s.hw / s.hh put(s, left + bw / 2); left += bw + gap } var right = w - safe.right - gap - for (s in listOfNotNull(spec(InputControl.QAM), spec(InputControl.GUIDE).takeIf { !kit.steam }, spec(InputControl.R3))) { + for (s in rightRow) { val bw = size * s.hw / s.hh put(s, right - bw / 2); right -= bw + gap } @@ -147,9 +151,10 @@ object KitLayout { } /** Controls for the panel below the game, in [GamepadGeometry]'s slots. */ - fun dock(context: Context, kit: PadKit, width: Int, height: Int, portrait: Boolean, left: InputControl, right: InputControl): List { + 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) + val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright) 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)) { 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 35bf1f28b..f64aec385 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/KitLayoutTest.kt @@ -248,4 +248,17 @@ class KitLayoutTest { assertEquals(kit.toString(), !kit.steam, InputControl.RS in placed) } } + + @Test fun aSmallerPortraitPadKeepsTheGripsAndANarrowBottomRowNeverOverlaps() { + val grips = setOf("legacy:l4", "legacy:l5", "legacy:r4", "legacy:r5") + for (scale in listOf(.8f, 1f)) { + val ids = KitLayout.elements(context, PadKit.STEAM_DECK, 720, 1280, scale = scale).map { it.id } + assertTrue("$scale", ids.containsAll(grips)) + } + for (kit in PadKit.entries) { + val (w, h) = 720 to 1280 + val elements = KitLayout.elements(context, kit, w, h, Rect(120, 0, 0, 0)) + assertEquals(kit.toString(), emptyList>(), overlapping(elements, w, h)) + } + } }