mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(input): only an on-screen left mouse button stops screen taps from clicking (#3008)
Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
c08952dff9
commit
7bf75af8a1
4 files changed
+47
-31
No files matched your search
@@ -5158,10 +5158,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var sessionTouchDown = false
|
||||
private var screenTapsClick = true
|
||||
|
||||
private fun onScreenMouseButtonShown(): Boolean = listOfNotNull(
|
||||
private fun onScreenLeftMouseButtonShown(): Boolean = listOfNotNull(
|
||||
onScreenControls?.inputSurface, bottomInputControls?.inputSurface, unfoldedPanel?.inputSurface, unfoldedDeckSurface,
|
||||
secondScreenPresentation?.controlsView, swappedInputSurface,
|
||||
).any { it.isShown && inputProfile.showsMouseButton(it.inputRole, it.shownElements, stockInputProfile) }
|
||||
).any { it.isShown && inputProfile.showsLeftMouseButton(it.inputRole, it.shownElements, stockInputProfile) }
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean = inSurfaceSpace(event) { handleTouch(event) }
|
||||
|
||||
@@ -5197,7 +5197,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val snapshot = fingerTouchSnapshot(uiBlocking)
|
||||
val route = com.droiddeck.launcher.input.TouchRouter.decide(snapshot)
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
screenTapsClick = !onScreenMouseButtonShown()
|
||||
screenTapsClick = !onScreenLeftMouseButtonShown()
|
||||
if (::touchpad.isInitialized) touchpad.clicks = screenTapsClick
|
||||
if (::scrollTouch.isInitialized) scrollTouch.clicks = screenTapsClick
|
||||
}
|
||||
|
||||
@@ -53,14 +53,14 @@ data class InputProfile(
|
||||
fun elementClickAction(role: InputRole, element: InputSurfaceElement): InputAction = clicks[role]?.get(element.id)
|
||||
?: defaultElementClick(element, elementAction(role, element.id, element.control)) { action(role, it) }
|
||||
|
||||
fun showsMouseButton(role: InputRole, shown: List<InputSurfaceElement>, stock: InputProfile): Boolean = shown.any { element ->
|
||||
fun showsLeftMouseButton(role: InputRole, shown: List<InputSurfaceElement>, stock: InputProfile): Boolean = shown.any { element ->
|
||||
val action = elementAction(role, element.id, element.control).takeIf {
|
||||
elements[role]?.get(element.id) != stock.elements[role]?.get(element.id) || it != stock.elementAction(role, element.id, element.control)
|
||||
}
|
||||
val click = elementClickAction(role, element).takeIf {
|
||||
clicks[role]?.get(element.id) != stock.clicks[role]?.get(element.id) || it != stock.elementClickAction(role, element)
|
||||
}
|
||||
listOfNotNull(action, click).any { it is InputAction.MouseButton && it.validFor(element.control) }
|
||||
listOfNotNull(action, click).any { it is InputAction.MouseButton && it.code == PointerGestures.BTN_LEFT }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -694,22 +694,22 @@ class InputLibraryTest {
|
||||
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)))
|
||||
assertFalse(library.compileActive(desktop, panel).showsLeftMouseButton(InputRole.SECONDARY, shown, library.compileStock(desktop, panel)))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun userBoundSecondScreenMouseButtonIsDetected() {
|
||||
@Test fun userBoundSecondScreenLeftMouseButtonIsDetected() {
|
||||
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)))
|
||||
assertTrue(bound.compileActive(desktop, grips).showsLeftMouseButton(InputRole.SECONDARY, listOf(button), bound.compileStock(desktop, grips)))
|
||||
assertFalse(bound.compileActive(desktop, grips).showsLeftMouseButton(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)))
|
||||
assertFalse(rebound.compileActive(true).showsLeftMouseButton(InputRole.SECONDARY, listOf(pad), rebound.compileStock(true)))
|
||||
}
|
||||
|
||||
@Test fun copiedStockPanelsKeepTapsClickingUntilAMouseButtonIsAdded() {
|
||||
@@ -720,13 +720,13 @@ class InputLibraryTest {
|
||||
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)))
|
||||
assertFalse(copied.compileActive(desktop).showsLeftMouseButton(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)))
|
||||
assertTrue(bound.compileActive(desktop).showsLeftMouseButton(InputRole.SECONDARY, layout.elements + added, bound.compileStock(desktop)))
|
||||
assertFalse(bound.compileActive(desktop).showsLeftMouseButton(InputRole.SECONDARY, layout.elements, bound.compileStock(desktop)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,57 +15,73 @@ class OnScreenMouseButtonTest {
|
||||
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 shownButtonBoundToTheLeftMouseButtonIsDetected() {
|
||||
assertTrue(profile(button.id to InputAction.MouseButton(272)).showsLeftMouseButton(InputRole.PRIMARY, listOf(stick, button), game))
|
||||
}
|
||||
|
||||
@Test fun rightOrMiddleMouseButtonAloneKeepsTapsClicking() {
|
||||
listOf(273, 274, 275, 276).forEach { code ->
|
||||
assertFalse(profile(button.id to InputAction.MouseButton(code)).showsLeftMouseButton(InputRole.PRIMARY, listOf(stick, button), game))
|
||||
val stickClick = profile(stick.id to InputAction.Native(), clicks = mapOf(stick.id to InputAction.MouseButton(code)))
|
||||
assertFalse(stickClick.showsLeftMouseButton(InputRole.PRIMARY, listOf(stick), game))
|
||||
assertFalse(game.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(code)).showsLeftMouseButton(InputRole.PRIMARY, listOf(legacyA), game))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun rightButtonNextToALeftButtonStillStopsTapClicks() {
|
||||
val right = InputSurfaceElement(InputControl.B, .7f, .6f, .1f, .1f, id = "custom:right")
|
||||
val both = profile(button.id to InputAction.MouseButton(272), right.id to InputAction.MouseButton(273))
|
||||
assertTrue(both.showsLeftMouseButton(InputRole.PRIMARY, listOf(button, right), game))
|
||||
assertFalse(both.showsLeftMouseButton(InputRole.PRIMARY, listOf(right), 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))
|
||||
assertTrue(profile.showsLeftMouseButton(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))
|
||||
assertTrue(profile.showsLeftMouseButton(InputRole.PRIMARY, listOf(legacyA), game))
|
||||
assertFalse(profile.showsLeftMouseButton(InputRole.SECONDARY, listOf(legacyA), game))
|
||||
}
|
||||
|
||||
@Test fun stockDesktopOverlayKeepsTapsClicking() {
|
||||
assertFalse(desktop.showsMouseButton(InputRole.PRIMARY, overlay, desktop))
|
||||
assertFalse(desktop.showsLeftMouseButton(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))
|
||||
assertTrue(rebound.showsLeftMouseButton(InputRole.PRIMARY, overlay, desktop))
|
||||
val stickClick = desktop.withBinding(InputRole.PRIMARY, InputControl.L3, InputAction.MouseButton(272))
|
||||
assertTrue(stickClick.showsLeftMouseButton(InputRole.PRIMARY, overlay, desktop))
|
||||
val middleStickClick = desktop.withBinding(InputRole.PRIMARY, InputControl.L3, InputAction.MouseButton(274))
|
||||
assertFalse(middleStickClick.showsLeftMouseButton(InputRole.PRIMARY, overlay, desktop))
|
||||
assertTrue(profile(button.id to InputAction.MouseButton(272), base = desktop).showsLeftMouseButton(InputRole.PRIMARY, overlay + button, desktop))
|
||||
}
|
||||
|
||||
@Test fun desktopBindingsOnAGameBaseProfileAreUserPicked() {
|
||||
val copied = desktop.copy(id = "custom")
|
||||
assertTrue(copied.showsMouseButton(InputRole.PRIMARY, overlay, game))
|
||||
assertTrue(copied.showsLeftMouseButton(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))
|
||||
assertFalse(profile.showsLeftMouseButton(InputRole.PRIMARY, listOf(stick, button), game))
|
||||
assertFalse(game.showsLeftMouseButton(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))
|
||||
assertFalse(profile(button.id to InputAction.MouseButton(272)).showsLeftMouseButton(InputRole.PRIMARY, listOf(stick), game))
|
||||
assertFalse(profile(button.id to InputAction.MouseButton(272)).showsLeftMouseButton(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))
|
||||
assertFalse(profile.showsLeftMouseButton(InputRole.PRIMARY, listOf(legacyA), game))
|
||||
}
|
||||
|
||||
@Test fun invalidMouseCodeDoesNotCount() {
|
||||
assertFalse(profile(button.id to InputAction.MouseButton(1)).showsMouseButton(InputRole.PRIMARY, listOf(button), game))
|
||||
assertFalse(profile(button.id to InputAction.MouseButton(1)).showsLeftMouseButton(InputRole.PRIMARY, listOf(button), game))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user