Android: remove SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 04 Apr 2019 17:01:02 +0200
changeset 12689d581caf613cd
parent 12688 cc45bcb16ef2
child 12690 1e0b433edcbb
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
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
include/SDL_hints.h
src/core/android/SDL_android.c
src/core/android/SDL_android.h
src/video/android/SDL_androidtouch.c
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Apr 04 16:51:50 2019 +0200
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java	Thu Apr 04 17:01:02 2019 +0200
     1.3 @@ -73,10 +73,6 @@
     1.4      /** If shared libraries (e.g. SDL or the native application) could not be loaded. */
     1.5      public static boolean mBrokenLibraries;
     1.6  
     1.7 -    // If we want to separate mouse and touch events.
     1.8 -    //  This is only toggled in native code when a hint is set!
     1.9 -    public static boolean mSeparateMouseAndTouch;
    1.10 -
    1.11      // Main components
    1.12      protected static SDLActivity mSingleton;
    1.13      protected static SDLSurface mSurface;
    1.14 @@ -1772,8 +1768,7 @@
    1.15          // 12290 = Samsung DeX mode desktop mouse
    1.16          // 12290 = 0x3002 = 0x2002 | 0x1002 = SOURCE_MOUSE | SOURCE_TOUCHSCREEN
    1.17          // 0x2   = SOURCE_CLASS_POINTER
    1.18 -        if ((event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN))
    1.19 -                && SDLActivity.mSeparateMouseAndTouch) {
    1.20 +        if (event.getSource() == InputDevice.SOURCE_MOUSE || event.getSource() == (InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN)) {
    1.21              try {
    1.22                  mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event);
    1.23              } catch(Exception e) {
     2.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Thu Apr 04 16:51:50 2019 +0200
     2.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Thu Apr 04 17:01:02 2019 +0200
     2.3 @@ -555,9 +555,6 @@
     2.4                  return SDLControllerManager.handleJoystickMotionEvent(event);
     2.5  
     2.6              case InputDevice.SOURCE_MOUSE:
     2.7 -                if (!SDLActivity.mSeparateMouseAndTouch) {
     2.8 -                    break;
     2.9 -                }
    2.10                  action = event.getActionMasked();
    2.11                  switch (action) {
    2.12                      case MotionEvent.ACTION_SCROLL:
    2.13 @@ -624,14 +621,12 @@
    2.14          // Handle relative mouse mode
    2.15          if (mRelativeModeEnabled) {
    2.16              if (event.getSource() == InputDevice.SOURCE_MOUSE) {
    2.17 -                if (SDLActivity.mSeparateMouseAndTouch) {
    2.18 -                    int action = event.getActionMasked();
    2.19 -                    if (action == MotionEvent.ACTION_HOVER_MOVE) {
    2.20 -                        float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    2.21 -                        float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    2.22 -                        SDLActivity.onNativeMouse(0, action, x, y, true);
    2.23 -                        return true;
    2.24 -                    }
    2.25 +                int action = event.getActionMasked();
    2.26 +                if (action == MotionEvent.ACTION_HOVER_MOVE) {
    2.27 +                    float x = event.getAxisValue(MotionEvent.AXIS_RELATIVE_X);
    2.28 +                    float y = event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y);
    2.29 +                    SDLActivity.onNativeMouse(0, action, x, y, true);
    2.30 +                    return true;
    2.31                  }
    2.32              }
    2.33          }
    2.34 @@ -696,10 +691,6 @@
    2.35              case InputDevice.SOURCE_MOUSE:
    2.36              // DeX desktop mouse cursor is a separate non-standard input type.
    2.37              case InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHSCREEN:
    2.38 -                if (!SDLActivity.mSeparateMouseAndTouch) {
    2.39 -                    break;
    2.40 -                }
    2.41 -
    2.42                  action = event.getActionMasked();
    2.43                  switch (action) {
    2.44                      case MotionEvent.ACTION_SCROLL:
    2.45 @@ -720,9 +711,6 @@
    2.46                  break;
    2.47  
    2.48              case InputDevice.SOURCE_MOUSE_RELATIVE:
    2.49 -                if (!SDLActivity.mSeparateMouseAndTouch) {
    2.50 -                    break;
    2.51 -                }
    2.52                  action = event.getActionMasked();
    2.53                  switch (action) {
    2.54                      case MotionEvent.ACTION_SCROLL:
     3.1 --- a/include/SDL_hints.h	Thu Apr 04 16:51:50 2019 +0200
     3.2 +++ b/include/SDL_hints.h	Thu Apr 04 17:01:02 2019 +0200
     3.3 @@ -869,19 +869,7 @@
     3.4   */
     3.5  #define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"
     3.6  
     3.7 - /**
     3.8 - * \brief A variable to control whether mouse and touch events are to be treated together or separately
     3.9 - *
    3.10 - * The variable can be set to the following values:
    3.11 - *   "0"       - Mouse events will be handled as touch events, and touch will raise fake mouse
    3.12 - *               events. This is the behaviour of SDL <= 2.0.3. (default)
    3.13 - *   "1"       - Mouse events will be handled separately from pure touch events.
    3.14 - *
    3.15 - * The value of this hint is used at runtime, so it can be changed at any time.
    3.16 - */
    3.17 -#define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
    3.18 -
    3.19 - /**
    3.20 +/**
    3.21   * \brief A variable to control whether we trap the Android back button to handle it manually.
    3.22   *        This is necessary for the right mouse button to work on some Android devices, or
    3.23   *        to be able to trap the back button for use in your code reliably.  If set to true,
     4.1 --- a/src/core/android/SDL_android.c	Thu Apr 04 16:51:50 2019 +0200
     4.2 +++ b/src/core/android/SDL_android.c	Thu Apr 04 17:01:02 2019 +0200
     4.3 @@ -280,9 +280,6 @@
     4.4  static jmethodID midHapticRun;
     4.5  static jmethodID midHapticStop;
     4.6  
     4.7 -/* static fields */
     4.8 -static jfieldID fidSeparateMouseAndTouch;
     4.9 -
    4.10  /* Accelerometer data storage */
    4.11  static SDL_DisplayOrientation displayOrientation;
    4.12  static float fLastAccelerometer[3];
    4.13 @@ -537,12 +534,6 @@
    4.14          __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
    4.15      }
    4.16  
    4.17 -    fidSeparateMouseAndTouch = (*env)->GetStaticFieldID(env, mActivityClass, "mSeparateMouseAndTouch", "Z");
    4.18 -
    4.19 -    if (!fidSeparateMouseAndTouch) {
    4.20 -        __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?");
    4.21 -    }
    4.22 -
    4.23      checkJNIReady();
    4.24  }
    4.25  
    4.26 @@ -2206,13 +2197,6 @@
    4.27      (*env)->CallStaticVoidMethod(env, mActivityClass, midInitTouch);
    4.28  }
    4.29  
    4.30 -/* sets the mSeparateMouseAndTouch field */
    4.31 -void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
    4.32 -{
    4.33 -    JNIEnv *env = Android_JNI_GetEnv();
    4.34 -    (*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
    4.35 -}
    4.36 -
    4.37  void Android_JNI_PollInputDevices(void)
    4.38  {
    4.39      JNIEnv *env = Android_JNI_GetEnv();
     5.1 --- a/src/core/android/SDL_android.h	Thu Apr 04 16:51:50 2019 +0200
     5.2 +++ b/src/core/android/SDL_android.h	Thu Apr 04 17:01:02 2019 +0200
     5.3 @@ -96,7 +96,6 @@
     5.4  
     5.5  /* Touch support */
     5.6  void Android_JNI_InitTouch(void);
     5.7 -void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
     5.8  
     5.9  /* Threads */
    5.10  #include <jni.h>
     6.1 --- a/src/video/android/SDL_androidtouch.c	Thu Apr 04 16:51:50 2019 +0200
     6.2 +++ b/src/video/android/SDL_androidtouch.c	Thu Apr 04 17:01:02 2019 +0200
     6.3 @@ -40,28 +40,15 @@
     6.4  #define ACTION_POINTER_DOWN 5
     6.5  #define ACTION_POINTER_UP 6
     6.6  
     6.7 -static void SDLCALL
     6.8 -SeparateEventsHintWatcher(void *userdata, const char *name,
     6.9 -                          const char *oldValue, const char *newValue)
    6.10 -{
    6.11 -    SDL_bool separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    6.12 -
    6.13 -    Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
    6.14 -}
    6.15 -
    6.16  void Android_InitTouch(void)
    6.17  {
    6.18 -    SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    6.19 -                        SeparateEventsHintWatcher, NULL);
    6.20 -
    6.21      /* Add all touch devices */
    6.22      Android_JNI_InitTouch();
    6.23  }
    6.24  
    6.25  void Android_QuitTouch(void)
    6.26  {
    6.27 -    SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    6.28 -                        SeparateEventsHintWatcher, NULL);
    6.29 +    return;
    6.30  }
    6.31  
    6.32  void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)