Bug 4576: remove touch/mouse duplication for Android
authorSylvain Becker <sylvain.becker@gmail.com>
Tue, 02 Apr 2019 17:23:55 +0200
changeset 126830dd4bae437a5
parent 12682 aec854f934db
child 12684 16a389d01a4a
Bug 4576: remove touch/mouse duplication for Android
src/video/android/SDL_androidtouch.c
     1.1 --- a/src/video/android/SDL_androidtouch.c	Tue Apr 02 17:18:47 2019 +0200
     1.2 +++ b/src/video/android/SDL_androidtouch.c	Tue Apr 02 17:23:55 2019 +0200
     1.3 @@ -40,23 +40,11 @@
     1.4  #define ACTION_POINTER_DOWN 5
     1.5  #define ACTION_POINTER_UP 6
     1.6  
     1.7 -static void Android_GetWindowCoordinates(SDL_Window *window, float x, float y,
     1.8 -                                         int *window_x, int *window_y)
     1.9 -{
    1.10 -    int window_w, window_h;
    1.11 -
    1.12 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.13 -    *window_x = (int)(x * window_w);
    1.14 -    *window_y = (int)(y * window_h);
    1.15 -}
    1.16 -
    1.17 -static SDL_bool separate_mouse_and_touch = SDL_FALSE;
    1.18 -
    1.19  static void SDLCALL
    1.20  SeparateEventsHintWatcher(void *userdata, const char *name,
    1.21                            const char *oldValue, const char *newValue)
    1.22  {
    1.23 -    separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    1.24 +    SDL_bool separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    1.25  
    1.26      Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
    1.27  }
    1.28 @@ -74,7 +62,6 @@
    1.29  {
    1.30      SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    1.31                          SeparateEventsHintWatcher, NULL);
    1.32 -    separate_mouse_and_touch = SDL_FALSE;
    1.33  }
    1.34  
    1.35  void Android_OnTouch(SDL_Window *window, int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    1.36 @@ -82,7 +69,6 @@
    1.37      SDL_TouchID touchDeviceId = 0;
    1.38      SDL_FingerID fingerId = 0;
    1.39      int window_x, window_y;
    1.40 -    static SDL_FingerID pointerFingerID = 0;
    1.41  
    1.42      if (!window) {
    1.43          return;
    1.44 @@ -96,40 +82,16 @@
    1.45      fingerId = (SDL_FingerID)pointer_finger_id_in;
    1.46      switch (action) {
    1.47          case ACTION_DOWN:
    1.48 -            /* Primary pointer down */
    1.49 -            if (!separate_mouse_and_touch) {
    1.50 -                Android_GetWindowCoordinates(window, x, y, &window_x, &window_y);
    1.51 -                /* send moved event */
    1.52 -                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    1.53 -                /* send mouse down event */
    1.54 -                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.55 -            }
    1.56 -            pointerFingerID = fingerId;
    1.57          case ACTION_POINTER_DOWN:
    1.58 -            /* Non primary pointer down */
    1.59              SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
    1.60              break;
    1.61  
    1.62          case ACTION_MOVE:
    1.63 -            if (!pointerFingerID) {
    1.64 -                if (!separate_mouse_and_touch) {
    1.65 -                    Android_GetWindowCoordinates(window, x, y, &window_x, &window_y);
    1.66 -                    /* send moved event */
    1.67 -                    SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    1.68 -                }
    1.69 -            }
    1.70              SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
    1.71              break;
    1.72  
    1.73          case ACTION_UP:
    1.74 -            /* Primary pointer up */
    1.75 -            if (!separate_mouse_and_touch) {
    1.76 -                /* send mouse up */
    1.77 -                SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.78 -            }
    1.79 -            pointerFingerID = (SDL_FingerID) 0;
    1.80          case ACTION_POINTER_UP:
    1.81 -            /* Non primary pointer up */
    1.82              SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
    1.83              break;
    1.84