mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00a11444d1 | ||
|
|
6f04166dbd | ||
|
|
7394f69b81 | ||
|
|
6415661bc1 | ||
|
|
9e719bdfa4 | ||
|
|
865c54ee08 | ||
|
|
ba50192bfe | ||
|
|
5c971344d1 | ||
|
|
a2a7adc83d | ||
|
|
f6e109ef61 | ||
|
|
8c3d6cfaad | ||
|
|
9cb876e1e4 | ||
|
|
0d06d3d1d6 |
No files matched your search
@@ -4730,7 +4730,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
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
|
||||
@@ -4753,6 +4756,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun onScreenMouseButtonShown(): Boolean {
|
||||
if (steamTouchControls?.visibility == View.VISIBLE) return false
|
||||
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() +
|
||||
swappedControls?.takeIf { it.isShown }?.shownElements().orEmpty()
|
||||
return primary.any { inputProfile.hasMouseButton(InputRole.PRIMARY, it) } ||
|
||||
inputProfile.hasMouseButton(InputRole.SECONDARY, secondary)
|
||||
}
|
||||
|
||||
private fun uiBlocksTouch(): Boolean =
|
||||
drawerOpen || achievementsOpen || gestureSettingsOpen || inputSettingsOpen || pipUi || SessionState.suspended
|
||||
|
||||
@@ -4773,6 +4787,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
touchpad.desktop = SessionState.mode == SessionService.MODE_DESKTOP
|
||||
touchpad.tapClicks = !onScreenMouseButtonShown()
|
||||
placeTouchpadAtGuest(rect)
|
||||
}
|
||||
return touchpad.onTouch(event)
|
||||
@@ -4855,6 +4870,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
showCursor(cx, cy)
|
||||
}
|
||||
|
||||
private var swappedControls: com.droiddeck.launcher.ui.InputSurfaceView? = null
|
||||
|
||||
private fun dispatchDirectTouch(event: MotionEvent): Boolean {
|
||||
val rect = drawnRect() ?: return false
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN)
|
||||
@@ -4868,6 +4885,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) ignoreGameTouch = false
|
||||
return true
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
val tapClicks = !onScreenMouseButtonShown()
|
||||
directTouchHold.tapClicks = tapClicks
|
||||
twoFingerGestures.tapClicks = tapClicks
|
||||
}
|
||||
if (SessionState.mode == SessionService.MODE_DESKTOP && twoFingerGestures.onTouch(event)) return true
|
||||
return forwardTouch(event, rect)
|
||||
}
|
||||
@@ -4895,7 +4917,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
return true
|
||||
}
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
if (!pointerLocked) showCursor(event.x.coerceIn(rect.left, rect.right), event.y.coerceIn(rect.top, rect.bottom))
|
||||
if (!pointerLocked) {
|
||||
val x = event.x.coerceIn(rect.left, rect.right)
|
||||
val y = event.y.coerceIn(rect.top, rect.bottom)
|
||||
if (directTouchHold.tapClicks) showCursor(x, y) else movePointer(x, y)
|
||||
}
|
||||
if (WaylandCompositor.nativeFocusTakesTouch()) {
|
||||
listOf(PointerGestures.BTN_LEFT, PointerGestures.BTN_RIGHT, PointerGestures.BTN_MIDDLE).forEach {
|
||||
heldButtons.set(1, it, false)
|
||||
@@ -5993,7 +6019,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
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),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -94,9 +94,11 @@ data class InputLibrary(
|
||||
fun panelPart(isDesktop: Boolean, panel: String?): InputPart =
|
||||
panel?.let { id -> bindings.firstOrNull { it.id == id } }?.let { InputPart(it.id, it.layoutId) } ?: activePart(isDesktop, InputRole.SECONDARY)
|
||||
fun panelLayout(isDesktop: Boolean, panel: String?) = panelPart(isDesktop, panel).layout?.let { id -> layouts.firstOrNull { it.id == id } }
|
||||
fun compileActive(isDesktop: Boolean, panel: String? = null): InputProfile = compileParts(activeId(isDesktop), InputRole.entries.associateWith {
|
||||
preset(if (it == InputRole.SECONDARY) panelPart(isDesktop, panel).bindings else activePart(isDesktop, it).bindings)
|
||||
})
|
||||
fun compileActive(isDesktop: Boolean, panel: String? = null): InputProfile = activeId(isDesktop).let { id ->
|
||||
compileParts(id, InputRole.entries.associateWith {
|
||||
preset(if (it == InputRole.SECONDARY) panelPart(isDesktop, panel).bindings else activePart(isDesktop, it).bindings)
|
||||
}, profile(id).base)
|
||||
}
|
||||
|
||||
fun saveSelection(isDesktop: Boolean, name: String, id: String = newInputId()): InputLibrary {
|
||||
val current = profile(activeId(isDesktop))
|
||||
@@ -109,14 +111,14 @@ data class InputLibrary(
|
||||
fun compile(id: String): InputProfile {
|
||||
val profile = profile(id)
|
||||
val parts = InputRole.entries.associateWith { preset(profile.binding(it)) }
|
||||
return compileParts(id, parts)
|
||||
return compileParts(id, parts, profile.base)
|
||||
}
|
||||
|
||||
private fun compileParts(id: String, parts: Map<InputRole, SavedInputBindings>): InputProfile {
|
||||
return InputProfile(id, parts.mapValues { it.value.controls }.filterValues { it.isNotEmpty() },
|
||||
parts.getValue(InputRole.PHYSICAL).keys,
|
||||
parts.mapValues { it.value.elements }.filterValues { it.isNotEmpty() },
|
||||
parts.mapValues { it.value.clicks }.filterValues { it.isNotEmpty() })
|
||||
private fun compileParts(id: String, parts: Map<InputRole, SavedInputBindings>, base: String): InputProfile {
|
||||
return InputProfile(id, base = base, bindings = parts.mapValues { it.value.controls }.filterValues { it.isNotEmpty() },
|
||||
keys = parts.getValue(InputRole.PHYSICAL).keys,
|
||||
elements = parts.mapValues { it.value.elements }.filterValues { it.isNotEmpty() },
|
||||
clicks = parts.mapValues { it.value.clicks }.filterValues { it.isNotEmpty() })
|
||||
}
|
||||
|
||||
fun usersOfBindings(id: String) = profiles.filter { p -> p.parts.values.any { it.bindings == id } }
|
||||
|
||||
@@ -36,6 +36,7 @@ sealed interface InputAction {
|
||||
|
||||
data class InputProfile(
|
||||
val id: String,
|
||||
val base: String = id,
|
||||
val bindings: Map<InputRole, Map<InputControl, InputAction>> = emptyMap(),
|
||||
val keys: List<PhysicalInputBinding> = emptyList(),
|
||||
val elements: Map<InputRole, Map<String, InputAction>> = emptyMap(),
|
||||
@@ -50,6 +51,16 @@ 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>): Boolean {
|
||||
val stock = defaults(base)
|
||||
fun chosen(action: InputAction, shipped: InputAction) = action is InputAction.MouseButton && action != shipped
|
||||
return elements.any {
|
||||
val pressable = it.kind == InputElementKind.BUTTON || it.kind == InputElementKind.TRIGGER
|
||||
pressable && chosen(elementAction(role, it.id, it.control), stock.elementAction(role, it.id, it.control)) ||
|
||||
it.hasClick && chosen(elementClickAction(role, it), stock.elementClickAction(role, it))
|
||||
}
|
||||
}
|
||||
|
||||
fun elementClickAction(role: InputRole, element: InputSurfaceElement): InputAction = clicks[role]?.get(element.id)
|
||||
?: defaultElementClick(element, elementAction(role, element.id, element.control)) { action(role, it) }
|
||||
|
||||
@@ -72,7 +83,7 @@ data class InputProfile(
|
||||
InputControl.LEFT_PAD to InputAction.Scroll(), InputControl.RIGHT_PAD to InputAction.Pointer(),
|
||||
InputControl.LEFT_CLICK to InputAction.MouseButton(273), InputControl.RIGHT_CLICK to InputAction.MouseButton(272),
|
||||
)
|
||||
return InputProfile(DESKTOP, InputRole.entries.associateWith { desktop })
|
||||
return InputProfile(DESKTOP, bindings = InputRole.entries.associateWith { desktop })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
}
|
||||
}
|
||||
|
||||
fun shownElements() = surface.shownElements()
|
||||
|
||||
private fun render() {
|
||||
val elements = placed()
|
||||
surface.updateCustomLayout(when {
|
||||
|
||||
@@ -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
|
||||
@@ -112,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
|
||||
|
||||
@@ -17,6 +17,11 @@ class TouchpadGestures(
|
||||
var bounds: android.graphics.RectF = android.graphics.RectF(0f, 0f, 1f, 1f)
|
||||
var sensitivity = 1.15f
|
||||
var desktop = false
|
||||
var tapClicks = true
|
||||
set(value) {
|
||||
field = value
|
||||
if (!value) lastTapAt = 0L
|
||||
}
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var lastX = 0f
|
||||
@@ -55,6 +60,7 @@ class TouchpadGestures(
|
||||
private val clickUp = Runnable { releaseClick() }
|
||||
|
||||
private fun click(button: Int) {
|
||||
if (!tapClicks) return
|
||||
releaseClick()
|
||||
listener.onButton(button, true, x, y)
|
||||
clicked = button
|
||||
@@ -108,7 +114,7 @@ class TouchpadGestures(
|
||||
travelled = 0f; held = false; twoFingers = false; scrolled = false; secondWasTap = false
|
||||
fingers = 1; pinching = false
|
||||
anchorId = event.getPointerId(0); moverId = -1; holdDrag = false; scrollLocked = false
|
||||
if (event.eventTime - lastTapAt < TouchTiming.DOUBLE_TAP_MS) {
|
||||
if (tapClicks && event.eventTime - lastTapAt < TouchTiming.DOUBLE_TAP_MS) {
|
||||
dragging = true
|
||||
listener.onButton(PointerGestures.BTN_LEFT, true, x, y)
|
||||
} else {
|
||||
@@ -262,7 +268,7 @@ class TouchpadGestures(
|
||||
}
|
||||
!cancelled && travelled <= slopPx && event.eventTime - downAt < TouchTiming.TAP_MS -> {
|
||||
click(PointerGestures.BTN_LEFT)
|
||||
lastTapAt = event.eventTime
|
||||
if (tapClicks) lastTapAt = event.eventTime
|
||||
}
|
||||
}
|
||||
dragging = false; held = false; twoFingers = false
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -158,6 +158,11 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
val cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)
|
||||
@@ -514,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 {
|
||||
@@ -530,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
|
||||
|
||||
@@ -239,6 +239,8 @@ class SecondScreenPresentation(
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
fun shownControlElements() = controlsView?.takeIf { isShowing && it.isShown }?.shownElements().orEmpty()
|
||||
|
||||
fun refreshControls() {
|
||||
if (!created || !currentMode.controls) return
|
||||
val controls = controlsView ?: return
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.view.MotionEvent
|
||||
|
||||
internal fun inertTwoFingerGestures() = 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() {}
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class InputProfileMouseButtonTest {
|
||||
private val a = InputSurfaceElement(InputControl.A, 0f, 0f, .2f, .2f)
|
||||
private val trackpad = InputSurfaceElement(InputControl.RIGHT_PAD, 0f, 0f, .5f, .5f)
|
||||
private val trigger = InputSurfaceElement(InputControl.RT, 0f, 0f, .2f, .2f)
|
||||
|
||||
@Test fun gameDefaultsHaveNoMouseButton() {
|
||||
assertFalse(InputProfile.defaults(InputProfile.GAME).hasMouseButton(InputRole.PRIMARY, listOf(a, trigger, trackpad)))
|
||||
}
|
||||
|
||||
@Test fun stockDesktopBindingsDoNotCount() {
|
||||
val desktop = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
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() {
|
||||
val desktop = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
assertFalse(desktop.hasMouseButton(InputRole.PRIMARY, listOf(trackpad)))
|
||||
assertFalse(InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.PRIMARY, InputControl.A, InputAction.Keys(listOf(28)))
|
||||
.hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
}
|
||||
|
||||
@Test fun customElementCountsOnlyWhenItsOwnActionIsAMouseButton() {
|
||||
val custom = InputSurfaceElement(InputControl.A, 0f, 0f, .2f, .2f, id = "custom:1")
|
||||
val game = InputProfile.defaults(InputProfile.GAME)
|
||||
assertFalse(game.hasMouseButton(InputRole.PRIMARY, listOf(custom)))
|
||||
val bound = game.copy(elements = mapOf(InputRole.PRIMARY to mapOf("custom:1" to InputAction.MouseButton(272))))
|
||||
assertTrue(bound.hasMouseButton(InputRole.PRIMARY, listOf(custom)))
|
||||
assertFalse(bound.hasMouseButton(InputRole.SECONDARY, listOf(custom)))
|
||||
}
|
||||
|
||||
@Test fun savedDesktopProfileComparesAgainstItsDesktopBase() {
|
||||
val saved = InputProfile.defaults(InputProfile.DESKTOP).copy(id = "saved:1", base = InputProfile.DESKTOP)
|
||||
assertFalse(saved.hasMouseButton(InputRole.PRIMARY, listOf(a, trigger)))
|
||||
assertTrue(saved.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274)).hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
}
|
||||
|
||||
@Test fun configuredStickAndTrackpadClickMouseButtonsCount() {
|
||||
val stick = InputSurfaceElement(InputControl.LS, 0f, 0f, .3f, .3f)
|
||||
val desktop = InputProfile.defaults(InputProfile.DESKTOP)
|
||||
assertFalse(desktop.hasMouseButton(InputRole.PRIMARY, listOf(stick, trackpad)))
|
||||
assertFalse(InputProfile.defaults(InputProfile.GAME).hasMouseButton(InputRole.PRIMARY, listOf(stick, trackpad)))
|
||||
val stickClick = desktop.copy(clicks = mapOf(InputRole.PRIMARY to mapOf(stick.id to InputAction.MouseButton(274))))
|
||||
assertTrue(stickClick.hasMouseButton(InputRole.PRIMARY, listOf(stick)))
|
||||
assertFalse(stickClick.hasMouseButton(InputRole.SECONDARY, listOf(stick)))
|
||||
val padClick = InputProfile.defaults(InputProfile.GAME).copy(clicks = mapOf(InputRole.PRIMARY to mapOf(trackpad.id to InputAction.MouseButton(272))))
|
||||
assertTrue(padClick.hasMouseButton(InputRole.PRIMARY, listOf(trackpad)))
|
||||
}
|
||||
|
||||
@Test fun secondaryRoleBindingCountsOnlyForTheSecondaryRole() {
|
||||
val secondary = InputProfile.defaults(InputProfile.GAME).withBinding(InputRole.SECONDARY, InputControl.A, InputAction.MouseButton(272))
|
||||
assertTrue(secondary.hasMouseButton(InputRole.SECONDARY, listOf(a)))
|
||||
assertFalse(secondary.hasMouseButton(InputRole.PRIMARY, listOf(a)))
|
||||
}
|
||||
}
|
||||
@@ -227,6 +227,20 @@ class OnScreenControlsTest {
|
||||
assertFalse(view.hasPinned)
|
||||
}
|
||||
|
||||
@Test fun shownElementsFollowPinnedOnlyAndQuickHide() {
|
||||
val key = InputSurfaceElement(InputControl.B, .45f, .1f, .1f, .1f, "imported:0", name = "Find", alwaysShown = true)
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left, button, key), aspect = ASPECT))
|
||||
measure(view)
|
||||
assertEquals(listOf(left, button, key).map { it.id }, view.shownElements().map { it.id })
|
||||
view.setQuickHidden(true)
|
||||
assertEquals(listOf("imported:0"), view.shownElements().map { it.id })
|
||||
view.setQuickHidden(false)
|
||||
view.setPinnedOnly(true)
|
||||
assertEquals(listOf("imported:0"), view.shownElements().map { it.id })
|
||||
view.updateLayout(SavedInputLayout("test", "Test", listOf(left, button), aspect = ASPECT))
|
||||
assertTrue(view.shownElements().isEmpty())
|
||||
}
|
||||
|
||||
private companion object { const val ASPECT = 1000f / 600f }
|
||||
|
||||
private fun touch(action: Int, vararg pointers: Pair<Int, Pair<Float, Float>>, flags: Int = 0): Boolean {
|
||||
|
||||
@@ -48,6 +48,31 @@ class ScrollTouchGesturesTest {
|
||||
assertEquals(listOf("move 400,300", "left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun tapsPressNothingButLongPressStillRightClicksWhileTapClicksAreOff() {
|
||||
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", "right down", "right up"), events)
|
||||
}
|
||||
|
||||
@Test fun holdThenMoveStillDragsWhileTapClicksAreOff() {
|
||||
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", "left down", "move 403,600", "left up"), events)
|
||||
assertEquals(0f, scrolledY, 0f)
|
||||
}
|
||||
|
||||
@Test fun draggingScrollsWithTheFingerAndNeverClicks() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 800f)
|
||||
advance(200)
|
||||
|
||||
@@ -35,6 +35,7 @@ class SessionGestureRoutingTest {
|
||||
private lateinit var directHold: DirectTouchHold
|
||||
private val keys = mutableListOf<Pair<Int, Boolean>>()
|
||||
private val directButtons = mutableListOf<Pair<Int, Boolean>>()
|
||||
private val directTouches = mutableListOf<Int>()
|
||||
private val scrollPositions = mutableListOf<Pair<Float, Float>>()
|
||||
private val scrollDeltas = mutableListOf<Pair<Float, Float>>()
|
||||
private var keyboards = 0
|
||||
@@ -221,12 +222,13 @@ class SessionGestureRoutingTest {
|
||||
override fun onWheel(steps: Int) {}
|
||||
override fun onLongPress() {}
|
||||
}, object : DirectTouchHold.Touch {
|
||||
override fun down(pointerId: Int, x: Float, y: Float) {}
|
||||
override fun down(pointerId: Int, x: Float, y: Float) { directTouches += 0 }
|
||||
override fun move(pointerId: Int, x: Float, y: Float) {}
|
||||
override fun up(pointerId: Int, x: Float, y: Float) {}
|
||||
override fun cancel() {}
|
||||
}).also { it.configure(config) }
|
||||
setField("directTouchHold", directHold)
|
||||
setField("twoFingerGestures", inertTwoFingerGestures())
|
||||
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) {}
|
||||
@@ -236,6 +238,74 @@ class SessionGestureRoutingTest {
|
||||
setField("scrollTouch", launcherScroll)
|
||||
}
|
||||
|
||||
@Test fun pointerLockedTapsAreDroppedWhileTapClicksAreOffButHoldAndSwipesStillWork() {
|
||||
prepare(SessionPrefs.TOUCH_DIRECT)
|
||||
setField("pointerLocked", true)
|
||||
SessionState.outputSize = 1000 to 600
|
||||
val rect = android.graphics.RectF(0f, 0f, 1000f, 600f)
|
||||
fun forward(action: Int, x: Float, y: Float) {
|
||||
val now = SystemClock.uptimeMillis()
|
||||
val event = MotionEvent.obtain(now, now, action, x, y, 0)
|
||||
try { ReflectionHelpers.callInstanceMethod<Any?>(activity, "forwardTouch",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event),
|
||||
ReflectionHelpers.ClassParameter.from(android.graphics.RectF::class.java, rect)) } finally { event.recycle() }
|
||||
}
|
||||
fun tap() {
|
||||
forward(MotionEvent.ACTION_DOWN, 300f, 300f)
|
||||
forward(MotionEvent.ACTION_UP, 300f, 300f)
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(200))
|
||||
}
|
||||
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)
|
||||
directHold.tapClicks = true
|
||||
tap()
|
||||
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 tapWith(profile: InputProfile): Int {
|
||||
setField("inputProfile", profile)
|
||||
directTouches.clear()
|
||||
val now = SystemClock.uptimeMillis()
|
||||
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() }
|
||||
}
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(200))
|
||||
return directTouches.size
|
||||
}
|
||||
CompositorShadow.pointerMoves.clear()
|
||||
assertEquals(1, tapWith(InputProfile.defaults(InputProfile.DESKTOP)))
|
||||
assertTrue(CompositorShadow.pointerMoves.isEmpty())
|
||||
assertEquals(0, tapWith(InputProfile.defaults(InputProfile.DESKTOP)
|
||||
.withBinding(InputRole.PRIMARY, InputControl.A, InputAction.MouseButton(274))))
|
||||
assertEquals(1, CompositorShadow.pointerMoves.size)
|
||||
assertEquals(1, tapWith(InputProfile.defaults(InputProfile.DESKTOP)))
|
||||
assertEquals(1, CompositorShadow.pointerMoves.size)
|
||||
}
|
||||
|
||||
private fun tapThreeFingers(expectSteamGesture: Boolean) {
|
||||
val down = SystemClock.uptimeMillis()
|
||||
fun send(action: Int, index: Int, count: Int) {
|
||||
@@ -263,9 +333,12 @@ class SessionGestureRoutingTest {
|
||||
@Implements(value = WaylandCompositor::class, isInAndroidSdk = false)
|
||||
class CompositorShadow {
|
||||
companion object {
|
||||
@JvmStatic var sceneInputs = 0
|
||||
@JvmStatic val pointerMoves = mutableListOf<Pair<Int, Int>>()
|
||||
@JvmStatic @Implementation fun __staticInitializer__() {}
|
||||
@JvmStatic @Implementation fun nativeSendPointer(action: Int, x: Int, y: Int) { pointerMoves += x to y }
|
||||
@JvmStatic @Implementation fun nativeSendTouch(action: Int, id: Int, x: Int, y: Int) {}
|
||||
@JvmStatic @Implementation fun nativeSendSceneInput(type: Int, code: Int, value: Int) {}
|
||||
@JvmStatic @Implementation fun nativeSendSceneInput(type: Int, code: Int, value: Int) { sceneInputs++ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,6 +360,7 @@ class SessionPenRoutingTest {
|
||||
field("routedTouchMode", SessionPrefs.TOUCH_DIRECT)
|
||||
field("padMouseCheckedAt", android.os.SystemClock.uptimeMillis())
|
||||
field("threeFingerTap", ThreeFingerTap(8f))
|
||||
field("twoFingerGestures", inertTwoFingerGestures())
|
||||
field("directTouchHold", DirectTouchHold(8f, object : PointerGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) {}
|
||||
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.view.View
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import java.nio.file.Files
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -64,6 +68,85 @@ class SessionTouchRoutingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun pinnedMouseButtonSuppressesTapsAfterSteamTouchIsHiddenForTheKeyboard() {
|
||||
val controls = shownControls(button.copy(alwaysShown = true))
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "steamTouchInUse\$delegate").value = true
|
||||
ReflectionHelpers.getField<MutableState<Boolean>>(activity, "pcKeyboardOpen\$delegate").value = true
|
||||
invoke("updateOnScreenControls")
|
||||
assertEquals(View.GONE, steam.visibility)
|
||||
assertEquals(View.VISIBLE, controls.visibility)
|
||||
assertTrue(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun visibleSteamTouchKeepsTapClicksAndGameBindingsHaveNoMouseButton() {
|
||||
shownControls(button)
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
assertFalse(mouseButtonShown())
|
||||
steam.visibility = View.GONE
|
||||
assertTrue(mouseButtonShown())
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.GAME))
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun mouseButtonOnTheDeckSurfaceSuppressesTapsOnlyWhileItIsShown() {
|
||||
steam.visibility = View.GONE
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
val deck = InputSurfaceView(activity, null, listOf(button), InputRole.PRIMARY)
|
||||
field("unfoldedDeckSurface", deck)
|
||||
assertTrue(mouseButtonShown())
|
||||
deck.visibility = View.GONE
|
||||
assertFalse(mouseButtonShown())
|
||||
deck.visibility = View.VISIBLE
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.GAME))
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun pinnedMouseButtonInButtonsOnlyControlsSuppressesTaps() {
|
||||
steam.visibility = View.GONE
|
||||
field("inputProfile", userMouseButtonProfile)
|
||||
val controls = shownControls(button.copy(alwaysShown = true))
|
||||
controls.setButtonsOnly(true)
|
||||
assertTrue(mouseButtonShown())
|
||||
val plain = shownControls(button)
|
||||
plain.setButtonsOnly(true)
|
||||
assertFalse(mouseButtonShown())
|
||||
}
|
||||
|
||||
@Test fun mouseClickOnAStickOrTrackpadSuppressesTaps() {
|
||||
steam.visibility = View.GONE
|
||||
val stick = InputSurfaceElement(InputControl.LS, .1f, .3f, .3f, .4f)
|
||||
shownControls(stick)
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP))
|
||||
assertFalse(mouseButtonShown())
|
||||
field("inputProfile", InputProfile.defaults(InputProfile.DESKTOP)
|
||||
.copy(clicks = mapOf(InputRole.PRIMARY to mapOf(stick.id to InputAction.MouseButton(274)))))
|
||||
assertTrue(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 {
|
||||
updateLayout(SavedInputLayout("test", "Test", elements.toList(), aspect = 1000f / 600f))
|
||||
measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY))
|
||||
layout(0, 0, 1000, 600)
|
||||
visibility = View.VISIBLE
|
||||
field("onScreenControls", this)
|
||||
}
|
||||
|
||||
private fun mouseButtonShown() = invoke("onScreenMouseButtonShown") as Boolean
|
||||
private fun field(name: String, value: Any) = ReflectionHelpers.setField(activity, name, value)
|
||||
private fun invoke(name: String) = ReflectionHelpers.callInstanceMethod<Any?>(activity, name)
|
||||
}
|
||||
@@ -262,6 +262,58 @@ class TouchpadGesturesTest {
|
||||
assertFalse(events.contains("left down"))
|
||||
}
|
||||
|
||||
@Test fun tapsDoNotClickWhenTapClicksAreOff() {
|
||||
touchpad.tapClicks = false
|
||||
tap()
|
||||
advance(50)
|
||||
tap()
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(10)
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 310f))
|
||||
advance(60)
|
||||
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
|
||||
advance(10)
|
||||
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
|
||||
advance(TouchTiming.CLICK_MS + 100)
|
||||
assertEquals(emptyList<String>(), events)
|
||||
}
|
||||
|
||||
@Test fun movementAndHoldDragStillWorkWhenTapClicksAreOff() {
|
||||
touchpad.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(10)
|
||||
touch(MotionEvent.ACTION_MOVE, 0, 1 to (460f to 300f))
|
||||
touch(MotionEvent.ACTION_UP, 0, 1 to (460f to 300f))
|
||||
assertTrue(events.contains("move"))
|
||||
assertFalse(events.any { it.startsWith("left") })
|
||||
events.clear()
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(TouchTiming.HOLD_MS + 50)
|
||||
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
|
||||
assertEquals(listOf("long press", "left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun tapsClickAgainOnceTapClicksAreBackOn() {
|
||||
touchpad.tapClicks = false
|
||||
tap()
|
||||
touchpad.tapClicks = true
|
||||
tap()
|
||||
advance(TouchTiming.CLICK_MS + 100)
|
||||
assertEquals(listOf("left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun doubleTapDragIsNotStartedAfterTapClicksTurnOff() {
|
||||
tap()
|
||||
advance(TouchTiming.CLICK_MS + 10)
|
||||
events.clear()
|
||||
touchpad.tapClicks = false
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(TouchTiming.HOLD_MS - 50)
|
||||
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
|
||||
advance(TouchTiming.CLICK_MS + 100)
|
||||
assertEquals(emptyList<String>(), events)
|
||||
}
|
||||
|
||||
private fun tap() {
|
||||
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
|
||||
advance(80)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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