Added a hint SDL_HINT_TOUCH_MOUSE_EVENTS to control whether touch events generate synthetic mouse events.
authorSam Lantinga <slouken@libsdl.org>
Thu, 03 Aug 2017 09:48:44 -0700
changeset 1118227ed95cf83d6
parent 11181 951807bdae20
child 11183 2b3b51f36654
Added a hint SDL_HINT_TOUCH_MOUSE_EVENTS to control whether touch events generate synthetic mouse events.
include/SDL_hints.h
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
     1.1 --- a/include/SDL_hints.h	Wed Aug 02 17:45:15 2017 -0700
     1.2 +++ b/include/SDL_hints.h	Thu Aug 03 09:48:44 2017 -0700
     1.3 @@ -276,6 +276,17 @@
     1.4  #define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH "SDL_MOUSE_FOCUS_CLICKTHROUGH"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable controlling whether touch events should generate synthetic mouse events
     1.8 + *
     1.9 + *  This variable can be set to the following values:
    1.10 + *    "0"       - Touch events will not generate mouse events
    1.11 + *    "1"       - Touch events will generate mouse events
    1.12 + *
    1.13 + *  By default SDL will generate mouse events for touch events
    1.14 + */
    1.15 +#define SDL_HINT_TOUCH_MOUSE_EVENTS    "SDL_TOUCH_MOUSE_EVENTS"
    1.16 +
    1.17 +/**
    1.18   *  \brief Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to true.
    1.19   *
    1.20   */
     2.1 --- a/src/events/SDL_mouse.c	Wed Aug 02 17:45:15 2017 -0700
     2.2 +++ b/src/events/SDL_mouse.c	Thu Aug 03 09:48:44 2017 -0700
     2.3 @@ -64,6 +64,18 @@
     2.4      }
     2.5  }
     2.6  
     2.7 +static void
     2.8 +SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
     2.9 +{
    2.10 +    SDL_Mouse *mouse = (SDL_Mouse *)userdata;
    2.11 +
    2.12 +    if (hint && (*hint == '0' || SDL_strcasecmp(hint, "false") == 0)) {
    2.13 +        mouse->touch_mouse_events = SDL_FALSE;
    2.14 +    } else {
    2.15 +        mouse->touch_mouse_events = SDL_TRUE;
    2.16 +    }
    2.17 +}
    2.18 +
    2.19  /* Public functions */
    2.20  int
    2.21  SDL_MouseInit(void)
    2.22 @@ -76,6 +88,9 @@
    2.23      SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
    2.24                          SDL_MouseRelativeSpeedScaleChanged, mouse);
    2.25  
    2.26 +    SDL_AddHintCallback(SDL_HINT_TOUCH_MOUSE_EVENTS,
    2.27 +                        SDL_TouchMouseEventsChanged, mouse);
    2.28 +
    2.29      mouse->cursor_shown = SDL_TRUE;
    2.30  
    2.31      return (0);
    2.32 @@ -252,6 +267,10 @@
    2.33      int xrel;
    2.34      int yrel;
    2.35  
    2.36 +    if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
    2.37 +        return 0;
    2.38 +    }
    2.39 +
    2.40      if (mouse->relative_mode_warp) {
    2.41          int center_x = 0, center_y = 0;
    2.42          SDL_GetWindowSize(window, &center_x, &center_y);
    2.43 @@ -384,6 +403,10 @@
    2.44      Uint32 type;
    2.45      Uint32 buttonstate = mouse->buttonstate;
    2.46  
    2.47 +    if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
    2.48 +        return 0;
    2.49 +    }
    2.50 +
    2.51      /* Figure out which event to perform */
    2.52      switch (state) {
    2.53      case SDL_PRESSED:
     3.1 --- a/src/events/SDL_mouse_c.h	Wed Aug 02 17:45:15 2017 -0700
     3.2 +++ b/src/events/SDL_mouse_c.h	Thu Aug 03 09:48:44 2017 -0700
     3.3 @@ -87,6 +87,7 @@
     3.4      float relative_speed_scale;
     3.5      float scale_accum_x;
     3.6      float scale_accum_y;
     3.7 +    SDL_bool touch_mouse_events;
     3.8  
     3.9      /* Data for double-click tracking */
    3.10      int num_clickstates;