mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Preserve motion dispatch and rate-limit right-stick scrolling
This commit is contained in:
1 parent
55d97d82fd
commit
30fddaf53a
1 file changed
+10
-9
@@ -2216,6 +2216,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private var rightStickScrollDeviceId = android.view.InputDevice.INVALID_DEVICE_ID
|
||||
private var rightStickScrollDeflection = 0f
|
||||
private var rightStickScrollScheduled = false
|
||||
private var rightStickNextDispatchAt = 0L
|
||||
private val rightStickScrollTick = object : Runnable {
|
||||
override fun run() {
|
||||
val deviceId = rightStickScrollDeviceId
|
||||
@@ -2228,6 +2229,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
rightStickScrollScheduled = false
|
||||
dispatchRightStickScroll(rightStickScrollDeflection, deviceId)
|
||||
rightStickNextDispatchAt = android.os.SystemClock.uptimeMillis() + 130L
|
||||
rightStickScrollHandler.postDelayed(this, 130L)
|
||||
rightStickScrollScheduled = true
|
||||
}
|
||||
@@ -2265,26 +2267,25 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollPageWithRightStick(event: android.view.MotionEvent): Boolean {
|
||||
private fun scrollPageWithRightStick(event: android.view.MotionEvent) {
|
||||
if (event.actionMasked != android.view.MotionEvent.ACTION_MOVE ||
|
||||
!com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return false
|
||||
val device = event.device ?: return false
|
||||
!com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return
|
||||
val device = event.device ?: return
|
||||
val rxRy = com.droiddeck.launcher.input.PadBridge.rightStickUsesRxRy(event, device, rightStickLayouts)
|
||||
?: return false
|
||||
?: return
|
||||
val axis = if (rxRy) android.view.MotionEvent.AXIS_RY else android.view.MotionEvent.AXIS_RZ
|
||||
val value = event.getAxisValue(axis)
|
||||
if (kotlin.math.abs(value) < 0.55f) {
|
||||
if (rightStickScrollDeviceId == event.deviceId) stopRightStickScroll()
|
||||
return false
|
||||
return
|
||||
}
|
||||
rightStickScrollDeviceId = event.deviceId
|
||||
rightStickScrollDeflection = value
|
||||
if (!rightStickScrollScheduled) {
|
||||
dispatchRightStickScroll(value, event.deviceId)
|
||||
rightStickScrollHandler.postDelayed(rightStickScrollTick, 130L)
|
||||
val delay = (rightStickNextDispatchAt - android.os.SystemClock.uptimeMillis()).coerceAtLeast(0L)
|
||||
rightStickScrollHandler.postDelayed(rightStickScrollTick, delay)
|
||||
rightStickScrollScheduled = true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: android.view.MotionEvent): Boolean {
|
||||
@@ -2294,7 +2295,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
return true
|
||||
}
|
||||
triggerKeys.onMotion(event)
|
||||
if (scrollPageWithRightStick(event)) return true
|
||||
scrollPageWithRightStick(event)
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user