From 11193646b2cad99113be56d47eabb33bd3dc64a5 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Sun, 29 Nov 2026 19:27:51 +0000 Subject: [PATCH] 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. --- .../com/droiddeck/launcher/SessionActivity.kt | 17 +++++++--- .../launcher/input/PointerCapture.kt | 3 ++ .../droiddeck/launcher/ui/BottomGameScreen.kt | 2 ++ .../launcher/input/PointerCaptureTest.kt | 31 +++++++++++++++++ .../launcher/input/SessionPenRoutingTest.kt | 34 ++++++++++++++++++- 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 8473957bcd..1158ee76cf 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -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) { diff --git a/app/src/main/java/com/droiddeck/launcher/input/PointerCapture.kt b/app/src/main/java/com/droiddeck/launcher/input/PointerCapture.kt index d598a1bc05..049c71d3a1 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/PointerCapture.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/PointerCapture.kt @@ -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 diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomGameScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomGameScreen.kt index 046142ad1d..f8653921ae 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomGameScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomGameScreen.kt @@ -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) } diff --git a/app/src/test/java/com/droiddeck/launcher/input/PointerCaptureTest.kt b/app/src/test/java/com/droiddeck/launcher/input/PointerCaptureTest.kt index 3d85e8c259..77f114317a 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/PointerCaptureTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/PointerCaptureTest.kt @@ -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) } diff --git a/app/src/test/java/com/droiddeck/launcher/input/SessionPenRoutingTest.kt b/app/src/test/java/com/droiddeck/launcher/input/SessionPenRoutingTest.kt index cd6a40bc24..6db635bea1 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/SessionPenRoutingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/SessionPenRoutingTest.kt @@ -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(activity, "onBottomGameHover", + ReflectionHelpers.ClassParameter.from(MotionEvent::class.java, event)) + fun touch(event: MotionEvent) = ReflectionHelpers.callInstanceMethod(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(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("glassesOutputActive").value = true activity.dispatchGenericMotionEvent(event(MotionEvent.ACTION_HOVER_MOVE, 10, pen to 500f))