mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-04 21:13:20 -05:00
Route right-stick movement as Compose scroll events
This commit is contained in:
1 parent
8154a79420
commit
efb1b5437a
1 file changed
+24
-6
@@ -2208,22 +2208,40 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
private val triggerKeys = com.droiddeck.launcher.input.TriggerKeys { dispatchKeyEvent(it) }
|
||||
private val rightStickLayouts = HashMap<Int, Boolean>()
|
||||
private var rightStickScrollAt = 0L
|
||||
|
||||
private fun scrollPageWithRightStick(event: android.view.MotionEvent): Boolean {
|
||||
if (event.actionMasked != android.view.MotionEvent.ACTION_MOVE ||
|
||||
!event.isFromSource(android.view.InputDevice.SOURCE_JOYSTICK)) return false
|
||||
!com.droiddeck.launcher.input.PadBridge.isControllerMotionEvent(event)) return false
|
||||
val device = event.device ?: return false
|
||||
val axis = if (device.getMotionRange(android.view.MotionEvent.AXIS_RY, event.source) != null)
|
||||
android.view.MotionEvent.AXIS_RY else android.view.MotionEvent.AXIS_RZ
|
||||
val rxRy = com.droiddeck.launcher.input.PadBridge.rightStickUsesRxRy(event, device, rightStickLayouts)
|
||||
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) return false
|
||||
val now = android.os.SystemClock.uptimeMillis()
|
||||
if (now - rightStickScrollAt < 130L) return true
|
||||
rightStickScrollAt = now
|
||||
val key = if (value > 0f) android.view.KeyEvent.KEYCODE_PAGE_DOWN else android.view.KeyEvent.KEYCODE_PAGE_UP
|
||||
dispatchKeyEvent(android.view.KeyEvent(now, now, android.view.KeyEvent.ACTION_DOWN, key, 0))
|
||||
dispatchKeyEvent(android.view.KeyEvent(now, now, android.view.KeyEvent.ACTION_UP, key, 0))
|
||||
|
||||
val properties = android.view.MotionEvent.PointerProperties().apply {
|
||||
id = 0
|
||||
toolType = android.view.MotionEvent.TOOL_TYPE_MOUSE
|
||||
}
|
||||
val coordinates = android.view.MotionEvent.PointerCoords().apply {
|
||||
x = 1f
|
||||
y = 1f
|
||||
setAxisValue(android.view.MotionEvent.AXIS_VSCROLL, -value * 3f)
|
||||
}
|
||||
val scroll = android.view.MotionEvent.obtain(
|
||||
now, now, android.view.MotionEvent.ACTION_SCROLL, 1,
|
||||
arrayOf(properties), arrayOf(coordinates), 0, 0, 1f, 1f,
|
||||
event.deviceId, 0, android.view.InputDevice.SOURCE_MOUSE, 0,
|
||||
)
|
||||
try {
|
||||
super.dispatchGenericMotionEvent(scroll)
|
||||
} finally {
|
||||
scroll.recycle()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user