Bug 4576: track both FingerId and TrackId
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 04 Apr 2019 15:19:00 +0200
changeset 12687712d84dd14c9
parent 12686 a34ab2e5ddcf
child 12688 cc45bcb16ef2
Bug 4576: track both FingerId and TrackId
src/core/linux/SDL_evdev.c
src/events/SDL_mouse.c
src/events/SDL_touch.c
     1.1 --- a/src/core/linux/SDL_evdev.c	Wed Apr 03 10:14:42 2019 +0200
     1.2 +++ b/src/core/linux/SDL_evdev.c	Thu Apr 04 15:19:00 2019 +0200
     1.3 @@ -270,9 +270,7 @@
     1.4                      /* BTH_TOUCH event value 1 indicates there is contact with
     1.5                         a touchscreen or trackpad (earlist finger's current
     1.6                         position is sent in EV_ABS ABS_X/ABS_Y, switching to
     1.7 -                       next finger after earlist is released) however using it
     1.8 -                       for virtual mouse SDL_TOUCH_MOUSEID would differ from
     1.9 -                       other SDL backends which require a new finger touch. */
    1.10 +                       next finger after earlist is released) */
    1.11                      if (item->is_touchscreen && events[i].code == BTN_TOUCH) {
    1.12                          break;
    1.13                      }
     2.1 --- a/src/events/SDL_mouse.c	Wed Apr 03 10:14:42 2019 +0200
     2.2 +++ b/src/events/SDL_mouse.c	Thu Apr 04 15:19:00 2019 +0200
     2.3 @@ -298,10 +298,6 @@
     2.4      int xrel;
     2.5      int yrel;
     2.6  
     2.7 -    if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
     2.8 -        return 0;
     2.9 -    }
    2.10 -
    2.11      if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
    2.12          int center_x = 0, center_y = 0;
    2.13          SDL_GetWindowSize(window, &center_x, &center_y);
    2.14 @@ -447,10 +443,6 @@
    2.15      Uint32 type;
    2.16      Uint32 buttonstate = mouse->buttonstate;
    2.17  
    2.18 -    if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
    2.19 -        return 0;
    2.20 -    }
    2.21 -
    2.22      /* Figure out which event to perform */
    2.23      switch (state) {
    2.24      case SDL_PRESSED:
    2.25 @@ -520,7 +512,7 @@
    2.26      if (window && state == SDL_RELEASED) {
    2.27          SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    2.28      }
    2.29 -    
    2.30 +
    2.31      return posted;
    2.32  }
    2.33  
     3.1 --- a/src/events/SDL_touch.c	Wed Apr 03 10:14:42 2019 +0200
     3.2 +++ b/src/events/SDL_touch.c	Thu Apr 04 15:19:00 2019 +0200
     3.3 @@ -32,11 +32,9 @@
     3.4  static SDL_Touch **SDL_touchDevices = NULL;
     3.5  
     3.6  /* for mapping touch events to mice */
     3.7 -#define DUPLICATE_TO_MOUSE_EVENT
     3.8 -#if defined(DUPLICATE_TO_MOUSE_EVENT)
     3.9  static SDL_bool finger_touching = SDL_FALSE;
    3.10 -static SDL_FingerID first_finger;
    3.11 -#endif
    3.12 +static SDL_FingerID track_fingerid;
    3.13 +static SDL_TouchID  track_touchid;
    3.14  
    3.15  /* Public functions */
    3.16  int
    3.17 @@ -247,28 +245,31 @@
    3.18          return -1;
    3.19      }
    3.20  
    3.21 -#if defined(DUPLICATE_TO_MOUSE_EVENT)
    3.22 +    /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
    3.23      {
    3.24 -        SDL_Window *window = SDL_GetMouseFocus();
    3.25 -        if (window) {
    3.26 -            if (down) {
    3.27 -                if (finger_touching == SDL_FALSE) {
    3.28 -                    int pos_x = (int)(x * (float)window->w);
    3.29 -                    int pos_y = (int)(y * (float)window->h);
    3.30 -                    finger_touching = SDL_TRUE;
    3.31 -                    first_finger = fingerid;
    3.32 -                    SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    3.33 -                    SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    3.34 -                }
    3.35 -            } else {
    3.36 -                if (finger_touching == SDL_TRUE && first_finger == fingerid) {
    3.37 -                    SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    3.38 -                    finger_touching = SDL_FALSE;
    3.39 +        SDL_Mouse *mouse = SDL_GetMouse();
    3.40 +        if (mouse->touch_mouse_events) {
    3.41 +            SDL_Window *window = SDL_GetMouseFocus();
    3.42 +            if (window) {
    3.43 +                if (down) {
    3.44 +                    if (finger_touching == SDL_FALSE) {
    3.45 +                        int pos_x = (int)(x * (float)window->w);
    3.46 +                        int pos_y = (int)(y * (float)window->h);
    3.47 +                        finger_touching = SDL_TRUE;
    3.48 +                        track_touchid = id;
    3.49 +                        track_fingerid = fingerid;
    3.50 +                        SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    3.51 +                        SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    3.52 +                    }
    3.53 +                } else {
    3.54 +                    if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    3.55 +                        SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    3.56 +                        finger_touching = SDL_FALSE;
    3.57 +                    }
    3.58                  }
    3.59              }
    3.60          }
    3.61      }
    3.62 -#endif
    3.63  
    3.64      finger = SDL_GetFinger(touch, fingerid);
    3.65      if (down) {
    3.66 @@ -334,18 +335,20 @@
    3.67          return -1;
    3.68      }
    3.69  
    3.70 -#if defined(DUPLICATE_TO_MOUSE_EVENT)
    3.71 +    /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
    3.72      {
    3.73 -        SDL_Window *window = SDL_GetMouseFocus();
    3.74 -        if (window) {
    3.75 -            if (finger_touching == SDL_TRUE && first_finger == fingerid) {
    3.76 -                int pos_x = (int)(x * (float)window->w);
    3.77 -                int pos_y = (int)(y * (float)window->h);
    3.78 -                SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    3.79 +        SDL_Mouse *mouse = SDL_GetMouse();
    3.80 +        if (mouse->touch_mouse_events) {
    3.81 +            SDL_Window *window = SDL_GetMouseFocus();
    3.82 +            if (window) {
    3.83 +                if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
    3.84 +                    int pos_x = (int)(x * (float)window->w);
    3.85 +                    int pos_y = (int)(y * (float)window->h);
    3.86 +                    SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
    3.87 +                }
    3.88              }
    3.89          }
    3.90      }
    3.91 -#endif
    3.92  
    3.93      finger = SDL_GetFinger(touch,fingerid);
    3.94      if (!finger) {