mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(input): suppress two-finger tap clicks, count swapped-screen controls and re-anchor locked swipes
This commit is contained in:
1 parent
5c971344d1
commit
ba50192bfe
5 files changed
+59
-4
No files matched your search
@@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Any?>(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<Boolean>(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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user