SDL_Mouse/Touch: discard synthetic events when hints are not set.
authorSylvain Becker <sylvain.becker@gmail.com>
Tue, 09 Jul 2019 11:46:42 +0200
changeset 12934d03900e991a2
parent 12933 895066b9f1b4
child 12935 7e37d3b5e7a3
SDL_Mouse/Touch: discard synthetic events when hints are not set.
Those are generated/flagged by platform layer.
src/events/SDL_mouse.c
src/events/SDL_touch.c
     1.1 --- a/src/events/SDL_mouse.c	Tue Jul 09 08:55:00 2019 +0300
     1.2 +++ b/src/events/SDL_mouse.c	Tue Jul 09 11:46:42 2019 +0200
     1.3 @@ -338,6 +338,13 @@
     1.4          }
     1.5      }
     1.6  
     1.7 +    /* SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer */
     1.8 +    if (mouse->touch_mouse_events == 0) {
     1.9 +        if (mouseID == SDL_TOUCH_MOUSEID) {
    1.10 +            return 0;
    1.11 +        }
    1.12 +    }
    1.13 +
    1.14      if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
    1.15          int center_x = 0, center_y = 0;
    1.16          SDL_GetWindowSize(window, &center_x, &center_y);
    1.17 @@ -499,6 +506,13 @@
    1.18          }
    1.19      }
    1.20  
    1.21 +    /* SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer */
    1.22 +    if (mouse->touch_mouse_events == 0) {
    1.23 +        if (mouseID == SDL_TOUCH_MOUSEID) {
    1.24 +            return 0;
    1.25 +        }
    1.26 +    }
    1.27 +
    1.28      /* Figure out which event to perform */
    1.29      switch (state) {
    1.30      case SDL_PRESSED:
     2.1 --- a/src/events/SDL_touch.c	Tue Jul 09 08:55:00 2019 +0300
     2.2 +++ b/src/events/SDL_touch.c	Tue Jul 09 11:46:42 2019 +0200
     2.3 @@ -244,16 +244,18 @@
     2.4  {
     2.5      int posted;
     2.6      SDL_Finger *finger;
     2.7 +    SDL_Mouse *mouse;
     2.8  
     2.9      SDL_Touch* touch = SDL_GetTouch(id);
    2.10      if (!touch) {
    2.11          return -1;
    2.12      }
    2.13  
    2.14 +    mouse = SDL_GetMouse();
    2.15 +
    2.16  #if SYNTHESIZE_TOUCH_TO_MOUSE
    2.17      /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
    2.18      {
    2.19 -        SDL_Mouse *mouse = SDL_GetMouse();
    2.20          if (mouse->touch_mouse_events) {
    2.21              /* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
    2.22              if (id != SDL_MOUSE_TOUCHID) {
    2.23 @@ -301,6 +303,13 @@
    2.24      }
    2.25  #endif
    2.26  
    2.27 +    /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
    2.28 +    if (mouse->mouse_touch_events == 0) {
    2.29 +        if (id == SDL_MOUSE_TOUCHID) {
    2.30 +            return 0;
    2.31 +        }
    2.32 +    }
    2.33 +
    2.34      finger = SDL_GetFinger(touch, fingerid);
    2.35      if (down) {
    2.36          if (finger) {
    2.37 @@ -357,6 +366,7 @@
    2.38  {
    2.39      SDL_Touch *touch;
    2.40      SDL_Finger *finger;
    2.41 +    SDL_Mouse *mouse;
    2.42      int posted;
    2.43      float xrel, yrel, prel;
    2.44  
    2.45 @@ -365,10 +375,11 @@
    2.46          return -1;
    2.47      }
    2.48  
    2.49 +    mouse = SDL_GetMouse();
    2.50 +
    2.51  #if SYNTHESIZE_TOUCH_TO_MOUSE
    2.52      /* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
    2.53      {
    2.54 -        SDL_Mouse *mouse = SDL_GetMouse();
    2.55          if (mouse->touch_mouse_events) {
    2.56              if (id != SDL_MOUSE_TOUCHID) {
    2.57                  SDL_Window *window = SDL_GetMouseFocus();
    2.58 @@ -388,6 +399,13 @@
    2.59      }
    2.60  #endif
    2.61  
    2.62 +    /* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
    2.63 +    if (mouse->mouse_touch_events == 0) {
    2.64 +        if (id == SDL_MOUSE_TOUCHID) {
    2.65 +            return 0;
    2.66 +        }
    2.67 +    }
    2.68 +
    2.69      finger = SDL_GetFinger(touch,fingerid);
    2.70      if (!finger) {
    2.71          return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);