SDL: android: Relative mode mouse support for more devices. (#16483)

From 137944bb94b6967b9b96981550a4989b306715bd Mon Sep 17 00:00:00 2001
From: Rachel Blackman <[EMAIL REDACTED]>
Date: Fri, 9 Oct 2026 18:28:44 -0700
Subject: [PATCH] android: Relative mode mouse support for more devices.
 (#16483)

SOME android devices (like the Samsung A7 and S9 tablets) will, instead of using ACTION_HOVER_MOVE for relative mouse move events, will use just ACTION_MOVE. In addition, they will only generate ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE for mouse clicks while in relative mode.
---
 .../org/libsdl/app/SDLControllerManager.java  | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index e5b0b864606aa..4779adfeb3c91 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -830,20 +830,31 @@ public boolean onGenericMotion(View v, MotionEvent event) {
             int toolType = event.getToolType(i);
 
             if (toolType == MotionEvent.TOOL_TYPE_MOUSE) {
+                int buttonState = event.getButtonState();
+
                 switch (action) {
                     case MotionEvent.ACTION_SCROLL:
                         x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, i);
                         y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, i);
-                        SDLActivity.onNativeMouse(0, action, x, y, false);
+                        SDLActivity.onNativeMouse(buttonState, action, x, y, false);
                         consumed = true;
                         break;
 
-                    case MotionEvent.ACTION_HOVER_MOVE:
+                    case MotionEvent.ACTION_HOVER_MOVE:     // Absolute mode mouse movement
+                    case MotionEvent.ACTION_MOVE:           // Relative mode mouse movement
+                    case MotionEvent.ACTION_BUTTON_PRESS:
+                    case MotionEvent.ACTION_BUTTON_RELEASE:
+                        boolean isRelative = checkRelativeEvent(event);
                         x = getEventX(event, i);
                         y = getEventY(event, i);
 
-                        SDLActivity.onNativeMouse(0, action, x, y, checkRelativeEvent(event));
-                        consumed = true;
+                        if (isRelative || (action != MotionEvent.ACTION_BUTTON_PRESS && action != MotionEvent.ACTION_BUTTON_RELEASE)) {
+                            // In absolute mode, we get touch events alongside the mouse clicks, and handle those elsewhere. 
+                            // In relative mode, we ONLY get the ACTION_BUTTON_PRESS/ACTION_BUTTON_RELEASE, so if we don't consume them they
+                            // will be turned into key events for Enter or Select or Back or something similar.
+                            SDLActivity.onNativeMouse(buttonState, action, x, y, isRelative);
+                            consumed = true;                            
+                        }
                         break;
 
                     default: