src/video/android/SDL_androidtouch.c
changeset 9441 fc7522030729
parent 9439 0d01b53cdbea
child 9449 a65088766e35
     1.1 --- a/src/video/android/SDL_androidtouch.c	Wed Mar 25 10:48:59 2015 -0400
     1.2 +++ b/src/video/android/SDL_androidtouch.c	Wed Mar 25 10:59:10 2015 -0400
     1.3 @@ -50,11 +50,24 @@
     1.4      *window_y = (int)(y * window_h);
     1.5  }
     1.6  
     1.7 +static volatile SDL_bool separate_mouse_and_touch = SDL_FALSE;
     1.8 +
     1.9 +static void
    1.10 +SeparateEventsHintWatcher(void *userdata, const char *name,
    1.11 +                          const char *oldValue, const char *newValue)
    1.12 +{
    1.13 +    separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
    1.14 +}
    1.15 +
    1.16  void Android_InitTouch(void)
    1.17  {
    1.18      int i;
    1.19      int* ids;
    1.20 -    int number = Android_JNI_GetTouchDeviceIds(&ids);
    1.21 +    const int number = Android_JNI_GetTouchDeviceIds(&ids);
    1.22 +
    1.23 +    SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    1.24 +                        SeparateEventsHintWatcher, NULL);
    1.25 +
    1.26      if (0 < number) {
    1.27          for (i = 0; i < number; ++i) {
    1.28              SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
    1.29 @@ -63,12 +76,18 @@
    1.30      }
    1.31  }
    1.32  
    1.33 +void Android_QuitTouch(void)
    1.34 +{
    1.35 +    SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
    1.36 +                        SeparateEventsHintWatcher, NULL);
    1.37 +    separate_mouse_and_touch = SDL_FALSE;
    1.38 +}
    1.39 +
    1.40  void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
    1.41  {
    1.42      SDL_TouchID touchDeviceId = 0;
    1.43      SDL_FingerID fingerId = 0;
    1.44      int window_x, window_y;
    1.45 -    const char * hint;
    1.46      static SDL_FingerID pointerFingerID = 0;
    1.47  
    1.48      if (!Android_Window) {
    1.49 @@ -81,12 +100,11 @@
    1.50      }
    1.51  
    1.52      fingerId = (SDL_FingerID)pointer_finger_id_in;
    1.53 -    hint = SDL_GetHint("SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH");
    1.54      switch (action) {
    1.55          case ACTION_DOWN:
    1.56              /* Primary pointer down */
    1.57              Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    1.58 -            if ((!hint) || (hint && SDL_strcmp(hint, "1") != 0)) {
    1.59 +            if (!separate_mouse_and_touch) {
    1.60                  /* send moved event */
    1.61                  SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    1.62                  /* send mouse down event */
    1.63 @@ -101,8 +119,7 @@
    1.64          case ACTION_MOVE:
    1.65              if (!pointerFingerID) {
    1.66                  Android_GetWindowCoordinates(x, y, &window_x, &window_y);
    1.67 -
    1.68 -                if ((!hint) || (hint && SDL_strcmp(hint, "1") != 0)) {
    1.69 +                if (!separate_mouse_and_touch) {
    1.70                      /* send moved event */
    1.71                      SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    1.72                  }
    1.73 @@ -112,7 +129,7 @@
    1.74  
    1.75          case ACTION_UP:
    1.76              /* Primary pointer up */
    1.77 -            if ((!hint) || (hint && SDL_strcmp(hint, "1") != 0)) {
    1.78 +            if (!separate_mouse_and_touch) {
    1.79                  /* send mouse up */
    1.80                  pointerFingerID = (SDL_FingerID) 0;
    1.81                  SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);