From ba50192bfe2d58cce5000fb1d1c77cda019601f6 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:17:03 +0000 Subject: [PATCH] fix(input): suppress two-finger tap clicks, count swapped-screen controls and re-anchor locked swipes --- .../com/droiddeck/launcher/SessionActivity.kt | 11 +++++-- .../launcher/input/TwoFingerGestures.kt | 4 ++- .../launcher/ui/SecondScreenPresentation.kt | 2 +- .../input/SessionGestureRoutingTest.kt | 29 +++++++++++++++++++ .../launcher/input/TwoFingerGesturesTest.kt | 17 +++++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 0702a6a67e..e55263db5d 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -4089,7 +4089,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { val primary = listOfNotNull(unfoldedPanel, bottomInputControls, onScreenControls) .filter { it.visibility == View.VISIBLE }.map { it.shownElements() } + listOfNotNull(unfoldedDeckSurface?.takeIf { it.visibility == View.VISIBLE }?.shownElements()) - val secondary = secondScreenPresentation?.shownControlElements().orEmpty() + val secondary = secondScreenPresentation?.shownControlElements().orEmpty() + + swappedControls?.takeIf { it.isShown }?.shownElements().orEmpty() return primary.any { inputProfile.hasMouseButton(InputRole.PRIMARY, it) } || inputProfile.hasMouseButton(InputRole.SECONDARY, secondary) } @@ -4111,6 +4112,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } private var directTouchTapsOff = false + private var swappedControls: com.droiddeck.launcher.ui.InputSurfaceView? = null private fun moveDirectPointer(x: Float, y: Float) { if (pointerLocked) gestureOutput.moveTo(x, y) else movePointer(x, y) @@ -4130,6 +4132,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } if (event.actionMasked == MotionEvent.ACTION_DOWN) { directTouchTapsOff = onScreenMouseButtonShown() + if (::twoFingerGestures.isInitialized) twoFingerGestures.tapClicks = !directTouchTapsOff if (directTouchTapsOff && !programLocksPointer()) { gesturePointerReady = false directTouchHold.cancel() @@ -4137,6 +4140,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } } if (directTouchTapsOff && !programLocksPointer()) { + lockedSwipeX = event.x + lockedSwipeY = event.y val handled = SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event) if (!handled && event.actionMasked != MotionEvent.ACTION_UP && event.actionMasked != MotionEvent.ACTION_CANCEL) moveDirectPointer(event.x, event.y) @@ -5217,7 +5222,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { androidx.compose.runtime.key(profileLayout) { androidx.compose.ui.viewinterop.AndroidView( factory = { context -> com.droiddeck.launcher.ui.InputSurfaceView(context, padBridge, profileLayout?.elements.orEmpty(), - surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()) }, + surfaceStyle = profileLayout?.style ?: com.droiddeck.launcher.input.InputSurfaceStyle()) + .also { swappedControls = it } }, + onRelease = { if (swappedControls === it) swappedControls = null }, modifier = Modifier.fillMaxWidth().weight(1f), ) } diff --git a/app/src/main/java/com/droiddeck/launcher/input/TwoFingerGestures.kt b/app/src/main/java/com/droiddeck/launcher/input/TwoFingerGestures.kt index 9507728b25..b1b0a0d7cf 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/TwoFingerGestures.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/TwoFingerGestures.kt @@ -18,6 +18,8 @@ class TwoFingerGestures(private val slopPx: Float, private val listener: Listene private enum class State { IDLE, PENDING, CANDIDATE, TAPPED, HELD, SCROLLING, PASSING } + var tapClicks = true + private val handler = Handler(Looper.getMainLooper()) private var state = State.IDLE private var x = 0f @@ -151,7 +153,7 @@ class TwoFingerGestures(private val slopPx: Float, private val listener: Listene when (was) { State.TAPPED -> { listener.cancelTouch() - listener.rightClick(x, y) + if (tapClicks) listener.rightClick(x, y) return true } State.SCROLLING, State.HELD -> return true diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt b/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt index f86f397cba..235994471b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SecondScreenPresentation.kt @@ -239,7 +239,7 @@ class SecondScreenPresentation( return super.dispatchGenericMotionEvent(event) } - fun shownControlElements() = controlsView?.takeIf { it.visibility == View.VISIBLE }?.shownElements().orEmpty() + fun shownControlElements() = controlsView?.takeIf { isShowing && it.isShown }?.shownElements().orEmpty() fun refreshControls() { if (!created || !currentMode.controls) return diff --git a/app/src/test/java/com/droiddeck/launcher/input/SessionGestureRoutingTest.kt b/app/src/test/java/com/droiddeck/launcher/input/SessionGestureRoutingTest.kt index 897a710705..4fc4f7e9a8 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/SessionGestureRoutingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/SessionGestureRoutingTest.kt @@ -268,6 +268,35 @@ class SessionGestureRoutingTest { assertEquals(1, directTouches.size) } + @Test fun directTouchDownDetectsAShownMouseButtonAndSwitchesSuppressionPerStream() { + prepare(SessionPrefs.TOUCH_DIRECT) + SessionState.outputSize = 1000 to 600 + val controls = OnScreenControls(activity, null).apply { + updateLayout(SavedInputLayout("test", "Test", listOf(InputSurfaceElement(InputControl.A, .7f, .3f, .2f, .3f)), aspect = 1000f / 600f)) + measure(android.view.View.MeasureSpec.makeMeasureSpec(1000, android.view.View.MeasureSpec.EXACTLY), + android.view.View.MeasureSpec.makeMeasureSpec(600, android.view.View.MeasureSpec.EXACTLY)) + layout(0, 0, 1000, 600) + visibility = android.view.View.VISIBLE + } + setField("onScreenControls", controls) + fun stream(profile: InputProfile): Boolean { + setField("inputProfile", profile) + val now = SystemClock.uptimeMillis() + var duringStream = false + for (action in listOf(MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP)) { + val event = MotionEvent.obtain(now, now, action, 300f, 300f, 0) + try { ReflectionHelpers.callInstanceMethod(activity, "dispatchDirectTouch", + ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event)) } finally { event.recycle() } + if (action == MotionEvent.ACTION_DOWN) duringStream = ReflectionHelpers.getField(activity, "directTouchTapsOff") + } + assertFalse(ReflectionHelpers.getField(activity, "directTouchTapsOff")) + return duringStream + } + assertFalse(stream(InputProfile.defaults(InputProfile.DESKTOP))) + assertTrue(stream(InputProfile.defaults(InputProfile.DESKTOP) + .withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274)))) + } + private fun tapThreeFingers(expectSteamGesture: Boolean) { val down = SystemClock.uptimeMillis() fun send(action: Int, index: Int, count: Int) { diff --git a/app/src/test/java/com/droiddeck/launcher/input/TwoFingerGesturesTest.kt b/app/src/test/java/com/droiddeck/launcher/input/TwoFingerGesturesTest.kt index ee39500c36..2f4536cbe4 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/TwoFingerGesturesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/TwoFingerGesturesTest.kt @@ -39,6 +39,23 @@ class TwoFingerGesturesTest { assertEquals(listOf("cancel", "right 400.0,300.0"), calls) } + @Test fun tapClicksOffSwallowsTheTapButKeepsHoldAndScroll() { + gestures.tapClicks = false + touch(MotionEvent.ACTION_DOWN, 0, a) + time += 20 + touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b) + time += 80 + assertTrue(touch(MotionEvent.ACTION_POINTER_UP, 1, a, b)) + assertTrue(touch(MotionEvent.ACTION_UP, 0, a)) + assertEquals(listOf("cancel"), calls) + calls.clear() + touch(MotionEvent.ACTION_DOWN, 0, a) + time += 20 + touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b) + shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(TwoFingerGestures.HOLD_MS + 10)) + assertEquals(listOf("cancel", "right 400.0,300.0"), calls) + } + @Test fun holdRightClicksOnce() { touch(MotionEvent.ACTION_DOWN, 0, a) time += 20