Commit bfdd0b228a7d629ef621ab0449783e5851d8611f

Sylvain Becker 2019-04-04T17:01:02

Android: remove SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH java layer runs as if separate mouse and touch was 1, Use SDL_HINT_MOUSE_TOUCH_EVENTS and SDL_HINT_TOUCH_MOUSE_EVENTS for generating synthetic touch/mouse events

diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index caee004..0e3580c 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -73,10 +73,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
     /** If shared libraries (e.g. SDL or the native application) could not be loaded. */
     public static boolean mBrokenLibraries;
 
-    // If we want to separate mouse and touch events.
-    //  This is only toggled in native code when a hint is set!
-    public static boolean mSeparateMouseAndTouch;
-
     // Main components
     protected static SDLActivity mSingleton;
     protected static SDLSurface mSurface;
@@ -1772,8 +1768,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
         // 12290 = Samsung DeX mode desktop mouse
         // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
         // 0x2   = SOURCE_CLASS_POINTER
-        if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN))
-                && SDLActivity.mSeparateMouseAndTouch) {
+        if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
             try {
                 mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
             } catch(Exception e) {
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 d3329c9..a81e97b 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
@@ -555,9 +555,6 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener {
                 return SDLControllerManager.handleJoystickMotionEvent(event);
 
             case InputDevice.SOURCE_MOUSE:
-                if (!SDLActivity.mSeparateMouseAndTouch) {
-                    break;
-                }
                 action = event.getActionMasked();
                 switch (action) {
                     case MotionEvent.ACTION_SCROLL:
@@ -624,14 +621,12 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API12 {
         // Handle relative mouse mode
         if (mRelativeModeEnabled) {
             if (event.getSource() == InputDevice.SOURCE_MOUSE) {
-                if (SDLActivity.mSeparateMouseAndTouch) {
-                    int action = event.getActionMasked();
-                    if (action == MotionEvent.ACTION_HOVER_MOVE) {
-                        float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
-                        float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
-                        SDLActivity.onNativeMouse(0, action, x, y, true);
-                        return true;
-                    }
+                int action = event.getActionMasked();
+                if (action == MotionEvent.ACTION_HOVER_MOVE) {
+                    float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
+                    float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
+                    SDLActivity.onNativeMouse(0, action, x, y, true);
+                    return true;
                 }
             }
         }
@@ -696,10 +691,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
             case InputDevice.SOURCE_MOUSE:
             // DeX desktop mouse cursor is a separate non-standard input type.
             case InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN:
-                if (!SDLActivity.mSeparateMouseAndTouch) {
-                    break;
-                }
-
                 action = event.getActionMasked();
                 switch (action) {
                     case MotionEvent.ACTION_SCROLL:
@@ -720,9 +711,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
                 break;
 
             case InputDevice.SOURCE_MOUSE_RELATIVE:
-                if (!SDLActivity.mSeparateMouseAndTouch) {
-                    break;
-                }
                 action = event.getActionMasked();
                 switch (action) {
                     case MotionEvent.ACTION_SCROLL:
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 90d0e81..8cbcc3e 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -869,19 +869,7 @@ extern "C" {
  */
 #define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"
 
- /**
- * \brief A variable to control whether mouse and touch events are to be treated together or separately
- *
- * The variable can be set to the following values:
- *   "0"       - Mouse events will be handled as touch events, and touch will raise fake mouse
- *               events. This is the behaviour of SDL <= 2.0.3. (default)
- *   "1"       - Mouse events will be handled separately from pure touch events.
- *
- * The value of this hint is used at runtime, so it can be changed at any time.
- */
-#define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
-
- /**
+/**
  * \brief A variable to control whether we trap the Android back button to handle it manually.
  *        This is necessary for the right mouse button to work on some Android devices, or
  *        to be able to trap the back button for use in your code reliably.  If set to true,
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index fe365be..2368bb1 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -280,9 +280,6 @@ static jmethodID midPollHapticDevices;
 static jmethodID midHapticRun;
 static jmethodID midHapticStop;
 
-/* static fields */
-static jfieldID fidSeparateMouseAndTouch;
-
 /* Accelerometer data storage */
 static SDL_DisplayOrientation displayOrientation;
 static float fLastAccelerometer[3];
@@ -537,12 +534,6 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
         __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
     }
 
-    fidSeparateMouseAndTouch = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");
-
-    if (!fidSeparateMouseAndTouch) {
-        __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?");
-    }
-
     checkJNIReady();
 }
 
@@ -2206,13 +2197,6 @@ void Android_JNI_InitTouch() {
     (*env)->CallStaticVoidMethod(env, mActivityClass, midInitTouch);
 }
 
-/* sets the mSeparateMouseAndTouch field */
-void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
-{
-    JNIEnv *env = Android_JNI_GetEnv();
-    (*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
-}
-
 void Android_JNI_PollInputDevices(void)
 {
     JNIEnv *env = Android_JNI_GetEnv();
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index 8373786..52332fb 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -96,7 +96,6 @@ void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
 
 /* Touch support */
 void Android_JNI_InitTouch(void);
-void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
 
 /* Threads */
 #include <jni.h>
diff --git a/src/video/android/SDL_androidtouch.c b/src/video/android/SDL_androidtouch.c
index 0e48100..1320326 100644
--- a/src/video/android/SDL_androidtouch.c
+++ b/src/video/android/SDL_androidtouch.c
@@ -40,28 +40,15 @@
 #define ACTION_POINTER_DOWN 5
 #define ACTION_POINTER_UP 6
 
-static void SDLCALL
-SeparateEventsHintWatcher(void *userdata, const char *name,
-                          const char *oldValue, const char *newValue)
-{
-    SDL_bool separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
-
-    Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
-}
-
 void Android_InitTouch(void)
 {
-    SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
-                        SeparateEventsHintWatcher, NULL);
-
     /* Add all touch devices */
     Android_JNI_InitTouch();
 }
 
 void Android_QuitTouch(void)
 {
-    SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
-                        SeparateEventsHintWatcher, NULL);
+    return;
 }
 
 void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)