mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-27 16:45:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbc634ebd5 |
No files matched your search
@@ -349,7 +349,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var gestureSettingsOpen by mutableStateOf(false)
|
||||
private var steamImportAsk by mutableStateOf<com.droiddeck.launcher.session.SteamImportPrompt.Ask?>(null)
|
||||
private var steamImportAnswered: String? = null
|
||||
private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_CLICK)
|
||||
private var directHoldBehavior by mutableStateOf(com.droiddeck.launcher.input.TouchGestureConfig.MOUSE_BEHAVIOR_NONE)
|
||||
private var relativeMouseMode by mutableIntStateOf(0)
|
||||
@Volatile private var appliedRelativeMouseMode: Int? = null
|
||||
private val agentReadyListener: () -> Unit = {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import kotlin.math.abs
|
||||
|
||||
@@ -22,8 +23,9 @@ class DirectTouchHold(
|
||||
private var downY = 0f
|
||||
private var downId = 0
|
||||
private var delayMs = 0L
|
||||
private var holdBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK
|
||||
private var holdBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_NONE
|
||||
private var forwarded = false
|
||||
private var forwardedAt = 0L
|
||||
private var held = false
|
||||
private var pressing = false
|
||||
private var upX = 0f
|
||||
@@ -125,8 +127,11 @@ class DirectTouchHold(
|
||||
upX = event.x
|
||||
upY = event.y
|
||||
liftId = event.getPointerId(event.actionIndex)
|
||||
liftPending = true
|
||||
handler.postDelayed(lift, LIFT_MS)
|
||||
val wait = MIN_PRESS_MS - (SystemClock.uptimeMillis() - forwardedAt)
|
||||
if (wait > 0L) {
|
||||
liftPending = true
|
||||
handler.postDelayed(lift, wait)
|
||||
} else lift.run()
|
||||
}
|
||||
MotionEvent.ACTION_CANCEL -> cancel()
|
||||
}
|
||||
@@ -136,9 +141,10 @@ class DirectTouchHold(
|
||||
private fun forwardDown() {
|
||||
touch.down(downId, downX, downY)
|
||||
forwarded = true
|
||||
forwardedAt = SystemClock.uptimeMillis()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val LIFT_MS = 50L
|
||||
const val MIN_PRESS_MS = 50L
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ data class TouchGestureConfig(
|
||||
val longPressAction: String = ACTION_RIGHT_CLICK,
|
||||
val longPressMouseBehavior: String = MOUSE_BEHAVIOR_HOLD,
|
||||
val longPressDelay: Int = DEFAULT_DELAY_MS,
|
||||
val directHoldBehavior: String = MOUSE_BEHAVIOR_CLICK,
|
||||
val directHoldBehavior: String = MOUSE_BEHAVIOR_NONE,
|
||||
val doubleTapEnabled: Boolean = true,
|
||||
val doubleTapDelay: Int = DEFAULT_DELAY_MS,
|
||||
val twoFingerDragEnabled: Boolean = true,
|
||||
@@ -167,7 +167,7 @@ data class TouchGestureConfig(
|
||||
),
|
||||
longPressDelay = obj.optInt(KEY_LONG_PRESS_DELAY, DEFAULT_DELAY_MS),
|
||||
directHoldBehavior = normalizeDirectHoldBehavior(
|
||||
obj.optString(KEY_DIRECT_HOLD_BEHAVIOR, MOUSE_BEHAVIOR_CLICK)
|
||||
obj.optString(KEY_DIRECT_HOLD_BEHAVIOR, MOUSE_BEHAVIOR_NONE)
|
||||
),
|
||||
doubleTapEnabled = obj.optBoolean(KEY_DOUBLE_TAP_ENABLED, true),
|
||||
doubleTapDelay = obj.optInt(KEY_DOUBLE_TAP_DELAY, DEFAULT_DELAY_MS),
|
||||
|
||||
@@ -333,7 +333,7 @@ class DrawerActions(
|
||||
val onInputSelection: (com.droiddeck.launcher.input.InputRole?) -> Unit = {},
|
||||
val onGestureSettings: () -> Unit = {},
|
||||
val touchActive: String = "",
|
||||
val directHoldBehavior: String = MOUSE_BEHAVIOR_CLICK,
|
||||
val directHoldBehavior: String = MOUSE_BEHAVIOR_NONE,
|
||||
val onDirectHoldBehavior: (String) -> Unit = {},
|
||||
val onFexPreset: (String) -> Unit,
|
||||
val onUpscaler: (Int) -> Unit = {},
|
||||
|
||||
@@ -29,7 +29,7 @@ class DirectTouchHoldTest {
|
||||
override fun move(pointerId: Int, x: Float, y: Float) { touches += "move $pointerId at $x,$y" }
|
||||
override fun up(pointerId: Int, x: Float, y: Float) { touches += "up $pointerId at $x,$y" }
|
||||
override fun cancel() { touches += "cancel" }
|
||||
}).also { it.configure(TouchGestureConfig(longPressEnabled = true, longPressDelay = 500)) }
|
||||
}).also { it.configure(TouchGestureConfig(longPressDelay = 500, directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK)) }
|
||||
|
||||
@Test fun holdClicksRightWithoutTouchingTheGame() {
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
@@ -87,18 +87,49 @@ class DirectTouchHoldTest {
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 44.0,30.0"), touches)
|
||||
}
|
||||
|
||||
@Test fun stillHoldClicksRightWithTheDefaultConfig() {
|
||||
@Test fun stillHoldStaysHeldWithTheDefaultConfig() {
|
||||
hold.configure(TouchGestureConfig())
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0"), touches)
|
||||
advance(2000)
|
||||
touch(MotionEvent.ACTION_MOVE)
|
||||
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 40.0,30.0"), touches)
|
||||
assertTrue(buttons.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aSavedRightClickChoiceIsKept() {
|
||||
val saved = TouchGestureConfig.fromJson(
|
||||
TouchGestureConfig(directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK).toJson())
|
||||
assertEquals(TouchGestureConfig.MOUSE_BEHAVIOR_CLICK, saved.directHoldBehavior)
|
||||
hold.configure(saved)
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(2000)
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
|
||||
assertTrue(touches.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aHeldTouchLiftsAtOnce() {
|
||||
hold.configure(TouchGestureConfig())
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(80)
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 40.0,30.0"), touches)
|
||||
}
|
||||
|
||||
@Test fun aShortTapStaysPressedLongEnoughToBeSeen() {
|
||||
hold.configure(TouchGestureConfig())
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(10)
|
||||
touch(MotionEvent.ACTION_UP)
|
||||
advance(39)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0"), touches)
|
||||
advance(1)
|
||||
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 40.0,30.0"), touches)
|
||||
}
|
||||
|
||||
@Test fun longPressFollowsTheConfiguredDelay() {
|
||||
hold.configure(TouchGestureConfig(longPressEnabled = true, longPressDelay = 800))
|
||||
hold.configure(TouchGestureConfig(longPressDelay = 800, directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK))
|
||||
touch(MotionEvent.ACTION_DOWN)
|
||||
advance(700)
|
||||
assertTrue(buttons.isEmpty())
|
||||
|
||||
@@ -152,7 +152,8 @@ class SessionGestureRoutingTest {
|
||||
|
||||
@Test fun pausingCancelsPendingHoldsInBothTouchModes() {
|
||||
for (mode in listOf(SessionPrefs.TOUCH_GESTURES, SessionPrefs.TOUCH_DIRECT)) {
|
||||
prepare(mode, TouchGestureConfig(longPressEnabled = true, longPressAction = "key_E"))
|
||||
prepare(mode, TouchGestureConfig(longPressEnabled = true, longPressAction = "key_E",
|
||||
directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK))
|
||||
val now = SystemClock.uptimeMillis()
|
||||
val event = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 400f, 300f, 0)
|
||||
try { assertTrue(activity.onTouchEvent(event)) } finally { event.recycle() }
|
||||
@@ -167,7 +168,8 @@ class SessionGestureRoutingTest {
|
||||
for (mode in listOf(SessionPrefs.TOUCH_GESTURES, SessionPrefs.TOUCH_DIRECT)) {
|
||||
keys.clear()
|
||||
directButtons.clear()
|
||||
prepare(mode, TouchGestureConfig(longPressEnabled = true, longPressAction = "key_E"))
|
||||
prepare(mode, TouchGestureConfig(longPressEnabled = true, longPressAction = "key_E",
|
||||
directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_CLICK))
|
||||
val now = SystemClock.uptimeMillis()
|
||||
val event = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, 400f, 300f, 0)
|
||||
try { assertTrue(activity.onTouchEvent(event)) } finally { event.recycle() }
|
||||
|
||||
Reference in new issue
Block a user