mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
fix(input): keep direct-touch hold, two-finger forwarding and long-press right click while taps are suppressed
This commit is contained in:
1 parent
9e719bdfa4
commit
6415661bc1
8 files changed
+105
-84
No files matched your search
@@ -884,8 +884,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
scrollRestY = 0f
|
||||
}
|
||||
override fun replay(event: MotionEvent) {
|
||||
if (directTouchTapsOff && !programLocksPointer()) moveDirectPointer(event.x, event.y)
|
||||
else drawnRect()?.let { forwardTouch(event, it) }
|
||||
drawnRect()?.let { forwardTouch(event, it) }
|
||||
}
|
||||
override fun rightClick(x: Float, y: Float) {
|
||||
pointerListener.onLongPress()
|
||||
@@ -4871,13 +4870,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
showCursor(cx, cy)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
private fun dispatchDirectTouch(event: MotionEvent): Boolean {
|
||||
val rect = drawnRect() ?: return false
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN)
|
||||
@@ -4892,32 +4886,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
return true
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
directTouchTapsOff = onScreenMouseButtonShown()
|
||||
if (::twoFingerGestures.isInitialized) twoFingerGestures.tapClicks = !directTouchTapsOff
|
||||
if (directTouchTapsOff && !programLocksPointer()) {
|
||||
gesturePointerReady = false
|
||||
directTouchHold.cancel()
|
||||
WaylandCompositor.nativeSendTouch(3, -1, 0, 0)
|
||||
}
|
||||
}
|
||||
if (directTouchTapsOff && !programLocksPointer()) {
|
||||
anchorLockedSwipe(event)
|
||||
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)
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) directTouchTapsOff = false
|
||||
return true
|
||||
val tapClicks = !onScreenMouseButtonShown()
|
||||
directTouchHold.tapClicks = tapClicks
|
||||
twoFingerGestures.tapClicks = tapClicks
|
||||
}
|
||||
if (SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event)) return true
|
||||
val forwarded = forwardTouch(event, rect)
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) directTouchTapsOff = false
|
||||
return forwarded
|
||||
}
|
||||
|
||||
private fun anchorLockedSwipe(event: MotionEvent) {
|
||||
val anchor = if (event.actionMasked == MotionEvent.ACTION_POINTER_UP && event.actionIndex == 0 && event.pointerCount > 1) 1 else 0
|
||||
lockedSwipeX = event.getX(anchor)
|
||||
lockedSwipeY = event.getY(anchor)
|
||||
return forwardTouch(event, rect)
|
||||
}
|
||||
|
||||
private fun forwardTouch(event: MotionEvent, rect: android.graphics.RectF): Boolean {
|
||||
@@ -4925,7 +4899,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
val swipeY = lockedSwipeY
|
||||
if (programLocksPointer() && event.actionMasked == MotionEvent.ACTION_MOVE && !lockedSwipeUsed &&
|
||||
abs(event.x - swipeX) <= touchSlop && abs(event.y - swipeY) <= touchSlop) return true
|
||||
anchorLockedSwipe(event)
|
||||
val anchor = if (event.actionMasked == MotionEvent.ACTION_POINTER_UP && event.actionIndex == 0 && event.pointerCount > 1) 1 else 0
|
||||
lockedSwipeX = event.getX(anchor)
|
||||
lockedSwipeY = event.getY(anchor)
|
||||
if ((event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) && lockedSwipeUsed) {
|
||||
lockedSwipeUsed = false
|
||||
directTouchHold.cancel()
|
||||
@@ -4948,7 +4924,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!directTouchTapsOff) directTouchHold.onTouch(event)
|
||||
directTouchHold.onTouch(event)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class DirectTouchHold(
|
||||
private var downId = 0
|
||||
private var delayMs = 0L
|
||||
private var holdBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK
|
||||
var tapClicks = true
|
||||
private var forwarded = false
|
||||
private var held = false
|
||||
private var pressing = false
|
||||
@@ -88,8 +89,8 @@ class DirectTouchHold(
|
||||
downX = event.x
|
||||
downY = event.y
|
||||
downId = event.getPointerId(0)
|
||||
if (holdBehavior == TouchGestureConfig.MOUSE_BEHAVIOR_NONE) forwardDown()
|
||||
else handler.postDelayed(hold, delayMs)
|
||||
if (holdBehavior != TouchGestureConfig.MOUSE_BEHAVIOR_NONE) handler.postDelayed(hold, delayMs)
|
||||
else if (tapClicks) forwardDown()
|
||||
return true
|
||||
}
|
||||
if (held) {
|
||||
@@ -121,6 +122,7 @@ class DirectTouchHold(
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
handler.removeCallbacks(hold)
|
||||
if (!forwarded && !tapClicks) return true
|
||||
if (!forwarded) forwardDown()
|
||||
upX = event.x
|
||||
upY = event.y
|
||||
|
||||
@@ -113,7 +113,7 @@ class ScrollTouchGestures(
|
||||
}
|
||||
dragging -> listener.onButton(PointerGestures.BTN_LEFT, false)
|
||||
held -> click(PointerGestures.BTN_RIGHT)
|
||||
!stoppedFling -> click(PointerGestures.BTN_LEFT)
|
||||
!stoppedFling && tapClicks -> click(PointerGestures.BTN_LEFT)
|
||||
}
|
||||
dragging = false
|
||||
held = false
|
||||
@@ -153,7 +153,6 @@ class ScrollTouchGestures(
|
||||
}
|
||||
|
||||
private fun click(button: Int) {
|
||||
if (!tapClicks) return
|
||||
releaseClick()
|
||||
listener.onButton(button, true)
|
||||
clicked = button
|
||||
|
||||
@@ -158,7 +158,10 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
fun shownElements() = customLayout
|
||||
fun shownElements(): List<InputSurfaceElement> {
|
||||
val canvas = customCanvas ?: return customLayout
|
||||
return customLayout.filterIndexed { index, _ -> (canvas.getChildAt(index) as? StickView)?.drawn != false }
|
||||
}
|
||||
|
||||
fun releaseInputs() {
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
@@ -516,6 +519,8 @@ class InputSurfaceView(
|
||||
|
||||
val adaptive get() = adaptive(element)
|
||||
|
||||
val drawn get() = !hideWhenIdle || touching
|
||||
|
||||
fun reach() = min(width, height) * if (classic(element)) CLASSIC_REACH else PANEL_REACH
|
||||
|
||||
fun captures(x: Float, y: Float): Boolean {
|
||||
@@ -532,7 +537,7 @@ class InputSurfaceView(
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (hideWhenIdle && !touching) return
|
||||
if (!drawn) return
|
||||
val cx = if (touching) originX else centreX()
|
||||
val cy = if (touching) originY else height / 2f
|
||||
val color = tint
|
||||
|
||||
@@ -67,6 +67,54 @@ class DirectTouchHoldTest {
|
||||
assertEquals("up 0 at 60.0,30.0", touches.last())
|
||||
}
|
||||
|
||||
@Test fun tapForwardsNothingWhileTapClicksAreOff() {
|
||||
hold.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
touch(MotionEvent.ACTION_UP, 50f)
|
||||
advance(100)
|
||||
assertTrue(touches.isEmpty())
|
||||
assertTrue(buttons.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun holdStillRightClicksWhileTapClicksAreOff() {
|
||||
hold.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(550)
|
||||
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
advance(100)
|
||||
assertTrue(touches.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun dragAndSecondFingerStillForwardWhileTapClicksAreOff() {
|
||||
hold.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
touch(MotionEvent.ACTION_MOVE, 60f)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "move 0 at 60.0,30.0"), touches)
|
||||
touch(MotionEvent.ACTION_UP, 60f)
|
||||
advance(50)
|
||||
touches.clear()
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN, 60f)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "down 0 at 60.0,30.0"), touches)
|
||||
touch(MotionEvent.ACTION_UP, 60f)
|
||||
}
|
||||
|
||||
@Test fun noneBehaviorWaitsForMovementWhileTapClicksAreOff() {
|
||||
hold.configure(TouchGestureConfig(directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_NONE))
|
||||
hold.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
assertTrue(touches.isEmpty())
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
advance(100)
|
||||
assertTrue(touches.isEmpty())
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
touch(MotionEvent.ACTION_MOVE, 60f)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "move 0 at 60.0,30.0"), touches)
|
||||
touch(MotionEvent.ACTION_UP, 60f)
|
||||
}
|
||||
|
||||
@Test fun dragForwardsTheTouchOnceItMoves() {
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
touch(MotionEvent.ACTION_MOVE, 60f)
|
||||
|
||||
@@ -48,7 +48,7 @@ class ScrollTouchGesturesTest {
|
||||
assertEquals(listOf("move 400,300", "left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun tapsAndHoldsPressNothingWhileTapClicksAreOff() {
|
||||
@Test fun tapsPressNothingButLongPressStillRightClicksWhileTapClicksAreOff() {
|
||||
gestures.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(80)
|
||||
@@ -58,7 +58,7 @@ class ScrollTouchGesturesTest {
|
||||
advance(700)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,300", "move 400,300", "long press"), events)
|
||||
assertEquals(listOf("move 400,300", "move 400,300", "long press", "right down", "right up"), events)
|
||||
}
|
||||
|
||||
@Test fun holdThenMoveStillDragsWhileTapClicksAreOff() {
|
||||
|
||||
@@ -228,6 +228,14 @@ class SessionGestureRoutingTest {
|
||||
override fun cancel() {}
|
||||
}).also { it.configure(config) }
|
||||
setField("directTouchHold", directHold)
|
||||
setField("twoFingerGestures", TwoFingerGestures(16f, object : TwoFingerGestures.Listener {
|
||||
override fun cancelTouch() {}
|
||||
override fun replay(event: MotionEvent) {}
|
||||
override fun rightClick(x: Float, y: Float) {}
|
||||
override fun scrollStart(x: Float, y: Float) {}
|
||||
override fun scroll(dx: Float, dy: Float) {}
|
||||
override fun scrollEnd() {}
|
||||
}))
|
||||
launcherScroll = ScrollTouchGestures(8f, 50f, object : ScrollTouchGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) { scrollPositions += x to y }
|
||||
override fun onButton(button: Int, pressed: Boolean) {}
|
||||
@@ -237,7 +245,7 @@ class SessionGestureRoutingTest {
|
||||
setField("scrollTouch", launcherScroll)
|
||||
}
|
||||
|
||||
@Test fun pointerLockedTapsAreDroppedWhileMouseButtonsAreShownAndSwipesStillAim() {
|
||||
@Test fun pointerLockedTapsAreDroppedWhileTapClicksAreOffButHoldAndSwipesStillWork() {
|
||||
prepare(SessionPrefs.TOUCH_DIRECT)
|
||||
setField("pointerLocked", true)
|
||||
SessionState.outputSize = 1000 to 600
|
||||
@@ -254,16 +262,20 @@ class SessionGestureRoutingTest {
|
||||
forward(MotionEvent.ACTION_UP, 300f, 300f)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(200))
|
||||
}
|
||||
setField("directTouchTapsOff", true)
|
||||
directHold.tapClicks = false
|
||||
tap()
|
||||
assertTrue(directTouches.isEmpty())
|
||||
assertTrue(directButtons.isEmpty())
|
||||
forward(MotionEvent.ACTION_DOWN, 300f, 300f)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(700))
|
||||
assertEquals(listOf(PointerGestures.BTN_RIGHT to true, PointerGestures.BTN_RIGHT to false), directButtons)
|
||||
forward(MotionEvent.ACTION_UP, 300f, 300f)
|
||||
CompositorShadow.sceneInputs = 0
|
||||
forward(MotionEvent.ACTION_DOWN, 300f, 300f)
|
||||
forward(MotionEvent.ACTION_MOVE, 400f, 300f)
|
||||
assertTrue(CompositorShadow.sceneInputs > 0)
|
||||
forward(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
setField("directTouchTapsOff", false)
|
||||
directHold.tapClicks = true
|
||||
tap()
|
||||
assertEquals(1, directTouches.size)
|
||||
}
|
||||
@@ -279,55 +291,22 @@ class SessionGestureRoutingTest {
|
||||
visibility = android.view.View.VISIBLE
|
||||
}
|
||||
setField("onScreenControls", controls)
|
||||
fun stream(profile: InputProfile): Boolean {
|
||||
fun tapWith(profile: InputProfile): Int {
|
||||
setField("inputProfile", profile)
|
||||
directTouches.clear()
|
||||
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
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(200))
|
||||
return directTouches.size
|
||||
}
|
||||
assertFalse(stream(InputProfile.defaults(InputProfile.DESKTOP)))
|
||||
assertTrue(stream(InputProfile.defaults(InputProfile.DESKTOP)
|
||||
assertEquals(1, tapWith(InputProfile.defaults(InputProfile.DESKTOP)))
|
||||
assertEquals(0, tapWith(InputProfile.defaults(InputProfile.DESKTOP)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274))))
|
||||
}
|
||||
|
||||
@Test fun lockedSwipeAnchorsToTheRemainingFingerWhenPointerZeroLiftsDuringSuppressedStream() {
|
||||
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)
|
||||
setField("inputProfile", InputProfile.defaults(InputProfile.DESKTOP)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274)))
|
||||
val down = SystemClock.uptimeMillis()
|
||||
fun send(action: Int, index: Int, xs: List<Float>) {
|
||||
val properties = Array(xs.size) { MotionEvent.PointerProperties().apply { id = it; toolType = MotionEvent.TOOL_TYPE_FINGER } }
|
||||
val coordinates = Array(xs.size) { MotionEvent.PointerCoords().apply { x = xs[it]; y = 300f; pressure = 1f } }
|
||||
val event = MotionEvent.obtain(down, SystemClock.uptimeMillis(), action or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT),
|
||||
xs.size, properties, coordinates, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
|
||||
try { ReflectionHelpers.callInstanceMethod<Any?>(activity, "dispatchDirectTouch",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event)) } finally { event.recycle() }
|
||||
}
|
||||
send(MotionEvent.ACTION_DOWN, 0, listOf(100f))
|
||||
send(MotionEvent.ACTION_POINTER_DOWN, 1, listOf(100f, 500f))
|
||||
send(MotionEvent.ACTION_POINTER_UP, 0, listOf(100f, 500f))
|
||||
assertEquals(500f, ReflectionHelpers.getField<Float>(activity, "lockedSwipeX"))
|
||||
setField("directTouchTapsOff", false)
|
||||
setField("pointerLocked", true)
|
||||
CompositorShadow.sceneInputs = 0
|
||||
send(MotionEvent.ACTION_MOVE, 0, listOf(500f))
|
||||
assertEquals(0, CompositorShadow.sceneInputs)
|
||||
assertEquals(1, tapWith(InputProfile.defaults(InputProfile.DESKTOP)))
|
||||
}
|
||||
|
||||
private fun tapThreeFingers(expectSteamGesture: Boolean) {
|
||||
|
||||
@@ -229,6 +229,18 @@ class InputSurfaceTouchTest {
|
||||
assertFalse(view.takesTouchAt(815f, 300f))
|
||||
}
|
||||
|
||||
@Test fun shownElementsSkipSticksThatHideWhileIdleUntilTouched() {
|
||||
val hidden = InputSurfaceElement(InputControl.LS, .3f, .3f, .2f, .4f, hideWhenIdle = true)
|
||||
show(a, hidden, b)
|
||||
assertEquals(listOf(a.id, b.id), view.shownElements().map { it.id })
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (50f to 300f))
|
||||
assertEquals(listOf(a.id, hidden.id, b.id), view.shownElements().map { it.id })
|
||||
touch(MotionEvent.ACTION_UP, 1 to (50f to 300f))
|
||||
assertEquals(listOf(a.id, b.id), view.shownElements().map { it.id })
|
||||
show(a, hidden.copy(hideWhenIdle = false), b)
|
||||
assertEquals(listOf(a.id, hidden.id, b.id), view.shownElements().map { it.id })
|
||||
}
|
||||
|
||||
private fun element(root: View, id: String): View = descendants(root).first { (it.tag as? InputSurfaceElement)?.id == id }
|
||||
private fun centre(target: View): Pair<Float, Float> {
|
||||
var x = target.width / 2f
|
||||
|
||||
Reference in new issue
Block a user