Bug 4576: handle mapping of TouchEvents to MouseEvents at higher level
authorSylvain Becker <sylvain.becker@gmail.com>
Tue, 02 Apr 2019 16:46:17 +0200
changeset 12676994f7540d7f3
parent 12675 33be90a3c475
child 12677 ed8b457b0a17
Bug 4576: handle mapping of TouchEvents to MouseEvents at higher level
src/events/SDL_touch.c
     1.1 --- a/src/events/SDL_touch.c	Tue Apr 02 05:31:08 2019 -0700
     1.2 +++ b/src/events/SDL_touch.c	Tue Apr 02 16:46:17 2019 +0200
     1.3 @@ -31,6 +31,12 @@
     1.4  static int SDL_num_touch = 0;
     1.5  static SDL_Touch **SDL_touchDevices = NULL;
     1.6  
     1.7 +/* for mapping touch events to mice */
     1.8 +#define DUPLICATE_TO_MOUSE_EVENT
     1.9 +#if defined(DUPLICATE_TO_MOUSE_EVENT)
    1.10 +static SDL_bool finger_touching = SDL_FALSE;
    1.11 +static SDL_FingerID first_finger;
    1.12 +#endif
    1.13  
    1.14  /* Public functions */
    1.15  int
    1.16 @@ -241,6 +247,29 @@
    1.17          return -1;
    1.18      }
    1.19  
    1.20 +#if defined(DUPLICATE_TO_MOUSE_EVENT)
    1.21 +    {
    1.22 +        SDL_Window *window = SDL_GetMouseFocus();
    1.23 +        if (window) {
    1.24 +            if (down) {
    1.25 +                if (finger_touching == SDL_FALSE) {
    1.26 +                    int pos_x = x * window->w;
    1.27 +                    int pos_y = y * window->y;
    1.28 +                    finger_touching = SDL_TRUE;
    1.29 +                    first_finger = fingerid;
    1.30 +                    SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.31 +                    SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.32 +                }
    1.33 +            } else {
    1.34 +                if (finger_touching == SDL_TRUE && first_finger == fingerid) {
    1.35 +                    SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    1.36 +                    finger_touching = SDL_FALSE;
    1.37 +                }
    1.38 +            }
    1.39 +        }
    1.40 +    }
    1.41 +#endif
    1.42 +
    1.43      finger = SDL_GetFinger(touch, fingerid);
    1.44      if (down) {
    1.45          if (finger) {
    1.46 @@ -305,6 +334,19 @@
    1.47          return -1;
    1.48      }
    1.49  
    1.50 +#if defined(DUPLICATE_TO_MOUSE_EVENT)
    1.51 +    {
    1.52 +        SDL_Window *window = SDL_GetMouseFocus();
    1.53 +        if (window) {
    1.54 +            if (finger_touching == SDL_TRUE && first_finger == fingerid) {
    1.55 +                int pos_x = x * window->w;
    1.56 +                int pos_y = y * window->y;
    1.57 +                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    1.58 +            }
    1.59 +        }
    1.60 +    }
    1.61 +#endif
    1.62 +
    1.63      finger = SDL_GetFinger(touch,fingerid);
    1.64      if (!finger) {
    1.65          return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);