mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 04:25:38 +00:00
fix(input): keep stock Desktop tap-to-click and cover direct and scroll touch routes
Only mouse buttons that differ from the shipped bindings count as user-picked. Direct touch moves the pointer instead of tapping and the scroll layer stops clicking while such a button is shown.
This commit is contained in:
1 parent
8c3d6cfaad
commit
f6e109ef61
6 files changed
+78
-10
No files matched your search
@@ -4046,7 +4046,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) gesturePointerReady = false
|
||||
touchscreenGestures.onTouch(event)
|
||||
}
|
||||
com.droiddeck.launcher.input.TouchRouter.Route.SCROLL -> scrollTouch.onTouch(event)
|
||||
com.droiddeck.launcher.input.TouchRouter.Route.SCROLL -> {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) scrollTouch.tapClicks = !onScreenMouseButtonShown()
|
||||
scrollTouch.onTouch(event)
|
||||
}
|
||||
else -> {
|
||||
if (com.droiddeck.launcher.input.TouchRouter.steamKeyboardZone(snapshot)) {
|
||||
val wasActive = threeFingerTap.active && event.actionMasked != MotionEvent.ACTION_DOWN
|
||||
@@ -4104,6 +4107,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
showCursor(cx, cy)
|
||||
}
|
||||
|
||||
private var directTouchMovesOnly = false
|
||||
|
||||
private fun dispatchDirectTouch(event: MotionEvent): Boolean {
|
||||
val rect = drawnRect() ?: return false
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN)
|
||||
@@ -4116,6 +4121,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) ignoreGameTouch = false
|
||||
return true
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
directTouchMovesOnly = !programLocksPointer() && onScreenMouseButtonShown()
|
||||
if (directTouchMovesOnly) {
|
||||
directTouchHold.cancel()
|
||||
WaylandCompositor.nativeSendTouch(3, -1, 0, 0)
|
||||
}
|
||||
}
|
||||
if (directTouchMovesOnly) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) directTouchMovesOnly = false
|
||||
else movePointer(event.x, event.y)
|
||||
return true
|
||||
}
|
||||
if (SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event)) return true
|
||||
return forwardTouch(event, rect)
|
||||
}
|
||||
|
||||
@@ -50,8 +50,13 @@ data class InputProfile(
|
||||
fun elementAction(role: InputRole, id: String, control: InputControl): InputAction =
|
||||
elements[role]?.get(id) ?: if (id == "legacy:${control.id}") action(role, control) else InputAction.Disabled
|
||||
|
||||
fun hasMouseButton(role: InputRole, elements: List<InputSurfaceElement>) = elements.any {
|
||||
(it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER) && elementAction(role, it.id, it.control) is InputAction.MouseButton
|
||||
fun hasMouseButton(role: InputRole, elements: List<InputSurfaceElement>): Boolean {
|
||||
val stock = defaults(id)
|
||||
return elements.any {
|
||||
val action = elementAction(role, it.id, it.control)
|
||||
(it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER) && action is InputAction.MouseButton &&
|
||||
action != stock.elementAction(role, it.id, it.control)
|
||||
}
|
||||
}
|
||||
|
||||
fun elementClickAction(role: InputRole, element: InputSurfaceElement): InputAction = clicks[role]?.get(element.id)
|
||||
|
||||
@@ -34,6 +34,7 @@ class ScrollTouchGestures(
|
||||
private var movedAt = 0L
|
||||
private var scrolling = false
|
||||
private var vertical = true
|
||||
var tapClicks = true
|
||||
private var held = false
|
||||
private var dragging = false
|
||||
private var stoppedFling = false
|
||||
@@ -129,7 +130,7 @@ class ScrollTouchGestures(
|
||||
private fun sample(x: Float, y: Float, t: Long) {
|
||||
if (!scrolling && !dragging && hypot(x - startX, y - startY) > slopPx) {
|
||||
handler.removeCallbacks(longPress)
|
||||
if (held) {
|
||||
if (held && tapClicks) {
|
||||
dragging = true
|
||||
listener.onButton(PointerGestures.BTN_LEFT, true)
|
||||
} else {
|
||||
@@ -152,6 +153,7 @@ class ScrollTouchGestures(
|
||||
}
|
||||
|
||||
private fun click(button: Int) {
|
||||
if (!tapClicks) return
|
||||
releaseClick()
|
||||
listener.onButton(button, true)
|
||||
clicked = button
|
||||
|
||||
@@ -13,10 +13,17 @@ class InputProfileMouseButtonTest {
|
||||
assertFalse(InputProfile.defaults(InputProfile.GAME).hasMouseButton(InputRole.PRIMARY, listOf(a, trigger, trackpad)))
|
||||
}
|
||||
|
||||
@Test fun desktopDefaultsBindMouseButtonsToButtonsAndTriggers() {
|
||||
@Test fun stockDesktopBindingsDoNotCount() {
|
||||
val desktop = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
assertTrue(desktop.hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
assertTrue(desktop.hasMouseButton(InputRole.PRIMARY, listOf(trigger)))
|
||||
assertFalse(desktop.hasMouseButton(InputRole.PRIMARY, listOf(a, trigger)))
|
||||
}
|
||||
|
||||
@Test fun reboundDesktopButtonAndGameBaseMouseBindingsCount() {
|
||||
val desktop = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
assertTrue(desktop.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274)).hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
assertFalse(desktop.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.Keys(listOf(28))).hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
assertTrue(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.PRIMARY, InputControl.RT, InputAction.MouseButton(272))
|
||||
.hasMouseButton(InputRole.PRIMARY, listOf(trigger)))
|
||||
}
|
||||
|
||||
@Test fun trackpadsAndKeyBindingsDoNotCount() {
|
||||
|
||||
@@ -48,6 +48,31 @@ class ScrollTouchGesturesTest {
|
||||
assertEquals(listOf("move 400,300", "left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun tapsAndHoldsPressNothingWhileTapClicksAreOff() {
|
||||
gestures.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(80)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(100)
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(700)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,300", "move 400,300", "long press"), events)
|
||||
}
|
||||
|
||||
@Test fun holdThenMoveScrollsInsteadOfDraggingWhileTapClicksAreOff() {
|
||||
gestures.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 800f)
|
||||
advance(700)
|
||||
touch(MotionEvent.ACTION_MOVE, 403f, 600f)
|
||||
advance(100)
|
||||
touch(MotionEvent.ACTION_UP, 403f, 600f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,800", "long press"), events)
|
||||
assertTrue(scrolledY > 0f)
|
||||
}
|
||||
|
||||
@Test fun draggingScrollsWithTheFingerAndNeverClicks() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 800f)
|
||||
advance(200)
|
||||
|
||||
@@ -70,7 +70,7 @@ class SessionTouchRoutingTest {
|
||||
|
||||
@Test fun pinnedMouseButtonSuppressesTapsAfterSteamTouchIsHiddenForTheKeyboard() {
|
||||
val controls = shownControls(button.copy(alwaysShown = true))
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "steamTouchInUse\$delegate").value = true
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "pcKeyboardOpen\$delegate").value = true
|
||||
invoke("updateOnScreenControls")
|
||||
@@ -81,7 +81,7 @@ class SessionTouchRoutingTest {
|
||||
|
||||
@Test fun visibleSteamTouchKeepsTapClicksAndGameBindingsHaveNoMouseButton() {
|
||||
shownControls(button)
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
assertFalse(mouseButtonShown())
|
||||
steam.visibility = View.GONE
|
||||
assertTrue(mouseButtonShown())
|
||||
@@ -91,7 +91,7 @@ class SessionTouchRoutingTest {
|
||||
|
||||
@Test fun mouseButtonOnTheDeckSurfaceSuppressesTapsOnlyWhileItIsShown() {
|
||||
steam.visibility = View.GONE
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
val deck = InputSurfaceView(activity, null, listOf(button), InputRole.PRIMARY)
|
||||
field("unfoldedDeckSurface", deck)
|
||||
assertTrue(mouseButtonShown())
|
||||
@@ -102,6 +102,18 @@ class SessionTouchRoutingTest {
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
private val userMouseButtonProfile = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274))
|
||||
|
||||
@Test fun stockDesktopOverlayKeepsTapClicks() {
|
||||
steam.visibility = View.GONE
|
||||
shownControls(button)
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
assertFalse(mouseButtonShown())
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
assertTrue(mouseButtonShown())
|
||||
}
|
||||
|
||||
private val button = InputSurfaceElement(InputControl.A, .7f, .3f, .2f, .3f)
|
||||
|
||||
private fun shownControls(vararg elements: InputSurfaceElement) = OnScreenControls(activity, null).apply {
|
||||
|
||||
Reference in new issue
Block a user