From 668e02fa17d72ee2a84dd59bc29c2d3f5a540768 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:40:57 -0500 Subject: [PATCH] fix(input): refuse layout files over 64 controls on the original importer too --- .../java/com/droiddeck/launcher/input/InputLayoutFile.kt | 3 ++- .../com/droiddeck/launcher/input/WinlatorLayoutsTest.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/input/InputLayoutFile.kt b/app/src/main/java/com/droiddeck/launcher/input/InputLayoutFile.kt index e98782dd5f..828151654c 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/InputLayoutFile.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/InputLayoutFile.kt @@ -105,11 +105,12 @@ internal object InputLayoutFile { else -> 4f * snap * scale } fun coordinate(name: String) = element.optDouble(name, .5).toFloat().takeIf { it.isFinite() }?.coerceIn(0f, 1f) ?: .5f + // A layout holds 64 controls; a file with more is refused rather than cut short. + if (keys.size == 64) return null keys += LegacyScreenKey(codes, coordinate("x"), coordinate("y"), (sizePx / density).roundToInt().coerceIn(24, 140).toFloat(), text = element.optString("text").trim().take(24), opacity = element.optDouble("opacity", 1.0).toFloat().takeIf { it.isFinite() }?.coerceIn(.2f, 1f) ?: 1f, shape = shape, toggle = element.optBoolean("toggleSwitch")) - if (keys.size == 64) break } return keys } diff --git a/app/src/test/java/com/droiddeck/launcher/input/WinlatorLayoutsTest.kt b/app/src/test/java/com/droiddeck/launcher/input/WinlatorLayoutsTest.kt index 1961e957e6..70cffc7ee5 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/WinlatorLayoutsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/WinlatorLayoutsTest.kt @@ -159,6 +159,15 @@ class WinlatorLayoutsTest { assertEquals(52, layout.elements.size) } + @Test fun aFileWithoutCursorSpeedOver64ControlsIsRefusedByTheOtherImporter() { + val buttons = (0 until 65).joinToString(",") { """{"type":"BUTTON","shape":"CIRCLE","bindings":["KEY_A"],"scale":0.5,"x":0.5,"y":0.5}""" } + val raw = """{"name":"Many","elements":[$buttons]}""" + assertFalse(WinlatorLayouts.isIcp(raw)) + assertNull(InputLayoutFile.import(context, raw, "Many", InputLayoutScreen.MAIN, InputSurfaceStyle(), 1920, 1080, 2f)) + val sixtyFour = """{"name":"Fits","elements":[${(0 until 64).joinToString(",") { """{"type":"BUTTON","bindings":["KEY_A"],"x":0.5,"y":0.5}""" }}]}""" + assertEquals(64, InputLayoutFile.import(context, sixtyFour, "Fits", InputLayoutScreen.MAIN, InputSurfaceStyle(), 1920, 1080, 2f)!!.first.elements.size) + } + @Test fun aKeyboardTrackpadKeepsItsKeys() { val raw = """{"cursorSpeed":1,"elements":[{"type":"TRACKPAD","shape":"CIRCLE","bindings":["KEY_W","KEY_D","KEY_S","KEY_A"],"scale":1,"x":0.5,"y":0.5}]}""" val (layout, bindings) = WinlatorLayouts.import(raw, "x", InputLayoutScreen.MAIN, 1920, 1080)!!