mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
fix(input): a mouse on the game's second screen drives the session pointer
With the game shown on another display (Dual screen sessions set to game on second screen, or Swap screens), mouse and touchpad events on that display were passed to the phone window's panel, which consumed them, so the session pointer never moved. Route them to the session's mouse handler in that screen's surface space and hide Android's arrow over the game, where the compositor already draws the guest cursor.
This commit is contained in:
1 parent
422b339af8
commit
11193646b2
5 files changed
+81
-6
No files matched your search
@@ -3888,8 +3888,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
else -> return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
if ((event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD)) && !drawerOpen) {
|
||||
if (com.droiddeck.launcher.input.PointerCapture.isMouse(event) && !drawerOpen) {
|
||||
if (appUiOwnsPointer()) {
|
||||
if (super.dispatchGenericMotionEvent(event)) return true
|
||||
if (touchEditorOpen) return false
|
||||
@@ -5401,8 +5400,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private fun handleTouch(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
val penRouted = if (pen >= 0) routePen(event, pen).takeIf { it != PenRouter.Route.TOUCH } else null
|
||||
if (penRouted == null && (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE) ||
|
||||
event.isFromSource(android.view.InputDevice.SOURCE_TOUCHPAD))) return onMouse(event)
|
||||
if (penRouted == null && com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return onMouse(event)
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
sessionTouchDown = true
|
||||
@@ -6834,7 +6832,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
|
||||
private fun onBottomGameHover(event: MotionEvent): Boolean {
|
||||
val pen = PenStream.penIndex(event)
|
||||
if (pipUi || pen < 0) return false
|
||||
if (pipUi) return false
|
||||
if (pen < 0) return onBottomGameMouse(event)
|
||||
return when (routePen(event, pen)) {
|
||||
PenRouter.Route.TOUCH -> false
|
||||
PenRouter.Route.PEN -> {
|
||||
@@ -6846,8 +6845,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
}
|
||||
}
|
||||
|
||||
private fun onBottomGameMouse(event: MotionEvent): Boolean {
|
||||
if (PenStream.penIndex(event) >= 0 || !com.droiddeck.launcher.input.PointerCapture.isMouse(event)) return false
|
||||
notePress(event)
|
||||
onMouse(event)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun onBottomGameTouch(event: MotionEvent): Boolean {
|
||||
if (pipUi) return true
|
||||
if (onBottomGameMouse(event)) return true
|
||||
if (!event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN) && PenStream.penIndex(event) < 0) return false
|
||||
notePress(event)
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
|
||||
@@ -10,6 +10,9 @@ object PointerCapture {
|
||||
|
||||
fun isTouchpad(event: MotionEvent): Boolean = event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun isMouse(event: MotionEvent): Boolean =
|
||||
event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_TOUCHPAD)
|
||||
|
||||
fun delta(event: MotionEvent): FloatArray {
|
||||
var dx = event.x
|
||||
var dy = event.y
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Bundle
|
||||
import android.view.Display
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.PointerIcon
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.View
|
||||
@@ -44,6 +45,7 @@ class BottomGameScreen(
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
surfaceView.pointerIcon = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_NULL)
|
||||
surfaceView.setOnTouchListener { _, event -> onTouch(event) }
|
||||
surfaceView.holder.addCallback(callback)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,37 @@ class PointerCaptureTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aHoveringMouseOrTouchpadDrivesThePointer() {
|
||||
listOf(
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_BUTTON_PRESS, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_SCROLL, InputDevice.SOURCE_MOUSE, x = 640f, y = 360f),
|
||||
event(MotionEvent.ACTION_HOVER_MOVE, InputDevice.SOURCE_TOUCHPAD, x = 640f, y = 360f),
|
||||
).forEach { event ->
|
||||
try {
|
||||
assertTrue(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchesPensControllersAndCapturedMiceAreNotAHoveringMouse() {
|
||||
listOf(
|
||||
InputDevice.SOURCE_TOUCHSCREEN,
|
||||
InputDevice.SOURCE_STYLUS,
|
||||
InputDevice.SOURCE_JOYSTICK,
|
||||
InputDevice.SOURCE_MOUSE_RELATIVE,
|
||||
).forEach { source ->
|
||||
val event = event(MotionEvent.ACTION_MOVE, source, x = 640f, y = 360f)
|
||||
try {
|
||||
assertFalse(PointerCapture.isMouse(event))
|
||||
} finally {
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun touchpadTravelMatchesTheSameDistanceOnScreen() {
|
||||
assertEquals(0.5f, PointerCapture.touchpadScale(unitsPerMm = 20f, padWidth = 2000f, pixelsPerMm = 10f, screenWidth = 1920), 0.001f)
|
||||
}
|
||||
|
||||
@@ -157,10 +157,42 @@ class SessionPenRoutingTest {
|
||||
SessionPrefs.setPenSetting(activity, "pen", SessionPrefs.PEN_TOUCH)
|
||||
invoke("readPrefs")
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 30, pen to 500f)))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 40, finger to 500f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertEquals(listOf(PEN_IN, PEN_IN or PEN_TIP, 0), CompositorShadow.pens.map { it.flags })
|
||||
}
|
||||
|
||||
@Test fun aMouseOnTheOtherScreensGameMovesTheSessionPointer() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
fun touch(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameTouch",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
val mouse = MotionEvent.TOOL_TYPE_MOUSE
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 10, mouse to 250f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_BUTTON_PRESS, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_DOWN, 20, mouse to 250f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_MOVE, 30, mouse to 750f, source = InputDevice.SOURCE_MOUSE,
|
||||
buttons = MotionEvent.BUTTON_PRIMARY)))
|
||||
assertTrue(touch(event(MotionEvent.ACTION_UP, 40, mouse to 750f, source = InputDevice.SOURCE_MOUSE)))
|
||||
assertTrue(hover(event(MotionEvent.ACTION_HOVER_MOVE, 50, finger to 600f, source = InputDevice.SOURCE_TOUCHPAD)))
|
||||
assertEquals(
|
||||
listOf(InputSpace.x(250f, 1000), InputSpace.x(250f, 1000), InputSpace.x(750f, 1000), InputSpace.x(600f, 1000)),
|
||||
CompositorShadow.pointers.map { it.second },
|
||||
)
|
||||
assertTrue(CompositorShadow.pointers.all { it.first == 1 && it.third == InputSpace.y(300f, 600) })
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
assertTrue(CompositorShadow.touches.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aControllerOnTheOtherScreensGameIsNotTakenAsAMouse() {
|
||||
fun hover(event: MotionEvent) = ReflectionHelpers.callInstanceMethod<Boolean>(activity, "onBottomGameHover",
|
||||
ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event))
|
||||
assertFalse(hover(event(MotionEvent.ACTION_MOVE, 10, finger to 500f, source = InputDevice.SOURCE_JOYSTICK)))
|
||||
assertTrue(CompositorShadow.pointers.isEmpty())
|
||||
assertTrue(CompositorShadow.pens.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun glassesAProgramPointerLockAndAppUiDropPenHover() {
|
||||
state<Boolean>("glassesOutputActive").value = true
|
||||
activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))
|
||||
|
||||
Reference in new issue
Block a user