fix(input): screen taps move the pointer without clicking while an on-screen mouse button is shown (#2465)

* fix(input): screen taps move the pointer without clicking while an on-screen mouse button is shown

* fix(input): keep tap-to-click with the stock Desktop on-screen gamepad

Only mouse buttons the user bound, not the profile base's stock bindings, make screen taps pointer-only.

* fix(input): count mouse buttons on the second-screen and foldable panels

* fix(input): keep tap clicks off on the swapped panel, copied stock panels and the scroll layer

* fix(input): move the pointer before the desktop gesture buffer when an on-screen mouse button clicks

* fix(input): the on-screen button gate leaves uninitialized gestures alone

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
MaxsTechReviewandKurt Himebauch authored and GitHub committed 2026-11-17 11:21:32 -05:00
1 parent 0794f361ad
commit 7852098e63
12 files changed
+292 -10

No files matched your search

@@ -592,4 +592,45 @@ class InputLibraryTest {
assertEquals(old.preset(InputStockLayouts.TRACKPAD), upgraded.preset(InputStockLayouts.TRACKPAD))
assertEquals(InputStockLayouts.layouts().single { it.id == InputLibraries.DECK }.elements, upgraded.layouts.single { it.id == InputLibraries.DECK }.elements)
}
@Test fun stockSecondScreenPanelsKeepTapsClicking() {
val library = InputLibraries.read(context)
for (desktop in listOf(false, true)) for (panel in listOf(null, InputStockLayouts.TRACKPAD) + DeckPanel.entries.map { it.bindings }) {
val shown = library.panelLayout(desktop, panel)!!.elements
assertTrue(shown.isNotEmpty())
assertFalse(library.compileActive(desktop, panel).showsMouseButton(InputRole.SECONDARY, shown, library.compileStock(desktop, panel)))
}
}
@Test fun userBoundSecondScreenMouseButtonIsDetected() {
val stock = InputLibraries.read(context)
val grips = DeckPanel.GRIPS.bindings
val button = stock.panelLayout(false, grips)!!.elements.first { it.control.dimensions == 1 }
val bound = stock.withPreset(stock.preset(grips).copy(elements = mapOf(button.id to InputAction.MouseButton(272))))
for (desktop in listOf(false, true)) {
assertTrue(bound.compileActive(desktop, grips).showsMouseButton(InputRole.SECONDARY, listOf(button), bound.compileStock(desktop, grips)))
assertFalse(bound.compileActive(desktop, grips).showsMouseButton(InputRole.PRIMARY, listOf(button), bound.compileStock(desktop, grips)))
}
val pad = stock.panelLayout(true, InputStockLayouts.TRACKPAD)!!.elements.single()
val rebound = stock.withPreset(stock.preset(InputStockLayouts.TRACKPAD).let { it.copy(clicks = it.clicks + (pad.id to InputAction.MouseButton(273))) })
assertTrue(rebound.compileActive(true).showsMouseButton(InputRole.SECONDARY, listOf(pad), rebound.compileStock(true)))
}
@Test fun copiedStockPanelsKeepTapsClickingUntilAMouseButtonIsAdded() {
val stock = InputLibraries.read(context)
for (desktop in listOf(false, true)) {
val source = stock.panelLayout(desktop, null)!!
val copied = stock.useLayout(stock.activeId(desktop), InputRole.SECONDARY, source.id, shared = false)
val layout = copied.activeLayout(desktop, InputRole.SECONDARY)!!
assertNotEquals(source.id, layout.id)
assertEquals(source.id, layout.origin)
assertFalse(copied.compileActive(desktop).showsMouseButton(InputRole.SECONDARY, layout.elements, copied.compileStock(desktop)))
val added = InputSurfaceElement(InputControl.A, .4f, .4f, .1f, .1f, id = "custom:added")
val grown = copied.withLayout(layout.copy(elements = layout.elements + added))
val bindings = grown.activePart(desktop, InputRole.SECONDARY).bindings
val bound = grown.withPreset(grown.preset(bindings).let { it.copy(elements = it.elements + (added.id to InputAction.MouseButton(272))) })
assertTrue(bound.compileActive(desktop).showsMouseButton(InputRole.SECONDARY, layout.elements + added, bound.compileStock(desktop)))
assertFalse(bound.compileActive(desktop).showsMouseButton(InputRole.SECONDARY, layout.elements, bound.compileStock(desktop)))
}
}
}
@@ -0,0 +1,71 @@
package com.droiddeck.launcher.input
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class OnScreenMouseButtonTest {
private val button = InputSurfaceElement(InputControl.A, .8f, .6f, .1f, .1f, id = "custom:left")
private val stick = InputSurfaceElement(InputControl.LS, .1f, .6f, .2f, .3f, id = "custom:stick")
private val legacyA = InputSurfaceElement(InputControl.A, .8f, .6f, .1f, .1f)
private val game = InputProfile.defaults(InputProfile.GAME)
private val desktop = InputProfile.defaults(InputProfile.DESKTOP)
private val overlay = InputControl.entries.map { InputSurfaceElement(it, .1f, .1f, .1f, .1f) }
private fun profile(vararg elements: Pair<String, InputAction>, clicks: Map<String, InputAction> = emptyMap(), base: InputProfile = game) =
base.copy(elements = mapOf(InputRole.PRIMARY to elements.toMap()), clicks = mapOf(InputRole.PRIMARY to clicks))
@Test fun shownButtonBoundToAMouseButtonIsDetected() {
listOf(272, 273, 274).forEach { code ->
assertTrue(profile(button.id to InputAction.MouseButton(code)).showsMouseButton(InputRole.PRIMARY, listOf(stick, button), game))
}
}
@Test fun stickClickBoundToAMouseButtonIsDetected() {
val profile = profile(stick.id to InputAction.Native(), clicks = mapOf(stick.id to InputAction.MouseButton(272)))
assertTrue(profile.showsMouseButton(InputRole.PRIMARY, listOf(stick), game))
}
@Test fun legacyButtonUsesItsRoleBinding() {
val profile = game.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(272))
assertTrue(profile.showsMouseButton(InputRole.PRIMARY, listOf(legacyA), game))
assertFalse(profile.showsMouseButton(InputRole.SECONDARY, listOf(legacyA), game))
}
@Test fun stockDesktopOverlayKeepsTapsClicking() {
assertFalse(desktop.showsMouseButton(InputRole.PRIMARY, overlay, desktop))
}
@Test fun userBoundMouseButtonInDesktopIsDetected() {
val rebound = desktop.withBinding(InputRole.PRIMARY, InputControl.X, InputAction.MouseButton(272))
assertTrue(rebound.showsMouseButton(InputRole.PRIMARY, overlay, desktop))
val stickClick = desktop.withBinding(InputRole.PRIMARY, InputControl.L3, InputAction.MouseButton(274))
assertTrue(stickClick.showsMouseButton(InputRole.PRIMARY, overlay, desktop))
assertTrue(profile(button.id to InputAction.MouseButton(272), base = desktop).showsMouseButton(InputRole.PRIMARY, overlay + button, desktop))
}
@Test fun desktopBindingsOnAGameBaseProfileAreUserPicked() {
val copied = desktop.copy(id = "custom")
assertTrue(copied.showsMouseButton(InputRole.PRIMARY, overlay, game))
}
@Test fun layoutWithoutAMouseButtonKeepsTapsClicking() {
val profile = profile(button.id to InputAction.Keys(listOf(57)), stick.id to InputAction.Pointer())
assertFalse(profile.showsMouseButton(InputRole.PRIMARY, listOf(stick, button), game))
assertFalse(game.showsMouseButton(InputRole.PRIMARY, listOf(legacyA, stick) + overlay, game))
}
@Test fun hiddenMouseButtonDoesNotCount() {
assertFalse(profile(button.id to InputAction.MouseButton(272)).showsMouseButton(InputRole.PRIMARY, listOf(stick), game))
assertFalse(profile(button.id to InputAction.MouseButton(272)).showsMouseButton(InputRole.PRIMARY, emptyList(), game))
}
@Test fun physicalMouseBindingsDoNotCount() {
val profile = game.withBinding(InputRole.PHYSICAL, InputControl.A, InputAction.MouseButton(272))
assertFalse(profile.showsMouseButton(InputRole.PRIMARY, listOf(legacyA), game))
}
@Test fun invalidMouseCodeDoesNotCount() {
assertFalse(profile(button.id to InputAction.MouseButton(1)).showsMouseButton(InputRole.PRIMARY, listOf(button), game))
}
}
@@ -131,6 +131,50 @@ class ScrollTouchGesturesTest {
assertEquals(listOf("move 400,300"), events)
}
@Test fun tapsAndHoldsDoNotClickWhileClicksAreOff() {
gestures.clicks = false
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
advance(80)
touch(MotionEvent.ACTION_UP, 400f, 300f)
advance(100)
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
advance(600)
touch(MotionEvent.ACTION_UP, 402f, 301f)
advance(100)
assertEquals(listOf("move 400,300", "move 400,300"), events)
}
@Test fun holdThenMoveScrollsWhileClicksAreOff() {
gestures.clicks = false
touch(MotionEvent.ACTION_DOWN, 400f, 800f)
advance(600)
touch(MotionEvent.ACTION_MOVE, 402f, 500f)
advance(200)
touch(MotionEvent.ACTION_UP, 402f, 500f)
advance(100)
assertEquals(300f, scrolledY, 0.01f)
assertEquals(listOf("move 400,800"), events)
}
@Test fun turningClicksOffReleasesAClickInFlight() {
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
advance(80)
touch(MotionEvent.ACTION_UP, 400f, 300f)
gestures.clicks = false
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
advance(80)
touch(MotionEvent.ACTION_UP, 400f, 300f)
advance(100)
assertEquals(listOf("move 400,300", "left down", "left up", "move 400,300"), events)
events.clear()
gestures.clicks = true
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
advance(80)
touch(MotionEvent.ACTION_UP, 400f, 300f)
advance(100)
assertEquals(listOf("move 400,300", "left down", "left up"), events)
}
@Test fun aSecondFingerDoesNotJumpTheScroll() {
touch(MotionEvent.ACTION_DOWN, 400f, 900f)
advance(100)
@@ -262,6 +262,75 @@ class TouchpadGesturesTest {
assertFalse(events.contains("left down"))
}
@Test fun tapsDoNotClickWhileClicksAreOff() {
touchpad.clicks = false
tap()
advance(20)
tap()
advance(TouchTiming.HOLD_MS + 100)
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(TouchTiming.HOLD_MS + 100)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(200)
assertFalse(events.any { it.endsWith(" down") })
}
@Test fun twoFingerTapDoesNotClickWhileClicksAreOff() {
touchpad.clicks = false
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(60)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(200)
assertFalse(events.any { it.endsWith(" down") })
}
@Test fun pointerStillMovesWhileClicksAreOff() {
touchpad.clicks = false
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_MOVE, 0, 1 to (440f to 300f))
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (440f to 300f))
assertTrue(events.contains("move"))
assertTrue(touchpad.x > 960f)
assertFalse(events.any { it.endsWith(" down") })
}
@Test fun tapsClickAgainOnceClicksAreBackOn() {
touchpad.clicks = false
tap()
advance(400)
touchpad.clicks = true
tap()
advance(200)
assertEquals(listOf("left down", "left up"), events)
}
@Test fun aTapWhileClicksWereOffDoesNotStartADragOnceTheyAreBackOn() {
touchpad.clicks = false
tap()
advance(20)
touchpad.clicks = true
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
assertEquals(emptyList<String>(), events)
advance(80)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(200)
assertEquals(listOf("left down", "left up"), events)
}
@Test fun doubleTapStillDragsWhileClicksStayOn() {
tap()
advance(20)
touchpad.clicks = true
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
assertEquals(listOf("left down", "left up", "left down"), events)
}
private fun tap() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(80)