Updated touch API
authorSam Lantinga <slouken@libsdl.org>
Sun, 03 Mar 2013 01:01:33 -0800
changeset 69517833f01322b3
parent 6950 1ddb72193079
child 6952 d2e309e7f77c
Updated touch API
* Normalized touch coordinates as floats in the 0...1 range
* Removed unused touchpad concepts from the API
* Added API functions to get active touch devices and current finger state
include/SDL_events.h
include/SDL_touch.h
src/events/SDL_gesture.c
src/events/SDL_gesture_c.h
src/events/SDL_touch.c
src/events/SDL_touch_c.h
src/video/android/SDL_androidtouch.c
src/video/cocoa/SDL_cocoawindow.m
src/video/uikit/SDL_uikitview.m
src/video/windows/SDL_windowsevents.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11touch.c
src/video/x11/SDL_x11touch.h
src/video/x11/SDL_x11xinput2.c
test/testgesture.c
     1.1 --- a/include/SDL_events.h	Sat Mar 02 20:44:16 2013 -0800
     1.2 +++ b/include/SDL_events.h	Sun Mar 03 01:01:33 2013 -0800
     1.3 @@ -105,8 +105,6 @@
     1.4      SDL_FINGERDOWN      = 0x700,
     1.5      SDL_FINGERUP,
     1.6      SDL_FINGERMOTION,
     1.7 -    SDL_TOUCHBUTTONDOWN,
     1.8 -    SDL_TOUCHBUTTONUP,    
     1.9  
    1.10      /* Gesture events */
    1.11      SDL_DOLLARGESTURE   = 0x800,
    1.12 @@ -367,75 +365,50 @@
    1.13  
    1.14  
    1.15  /**
    1.16 - *  \brief Touch finger motion/finger event structure (event.tfinger.*)
    1.17 + *  \brief Touch finger event structure (event.tfinger.*)
    1.18   */
    1.19  typedef struct SDL_TouchFingerEvent
    1.20  {
    1.21      Uint32 type;        /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
    1.22      Uint32 timestamp;
    1.23 -    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.24      SDL_TouchID touchId; /**< The touch device id */
    1.25      SDL_FingerID fingerId;
    1.26 -    Uint8 state;        /**< The current button state */
    1.27 -    Uint8 padding1;
    1.28 -    Uint8 padding2;
    1.29 -    Uint8 padding3;
    1.30 -    Uint16 x;
    1.31 -    Uint16 y;
    1.32 -    Sint16 dx;
    1.33 -    Sint16 dy;
    1.34 -    Uint16 pressure;
    1.35 +    float x;            /**< Normalized in the range 0...1 */
    1.36 +    float y;            /**< Normalized in the range 0...1 */
    1.37 +    float dx;           /**< Normalized in the range 0...1 */
    1.38 +    float dy;           /**< Normalized in the range 0...1 */
    1.39 +    float pressure;     /**< Normalized in the range 0...1 */
    1.40  } SDL_TouchFingerEvent;
    1.41  
    1.42  
    1.43  /**
    1.44 - *  \brief Touch finger motion/finger event structure (event.tbutton.*)
    1.45 - */
    1.46 -typedef struct SDL_TouchButtonEvent
    1.47 -{
    1.48 -    Uint32 type;        /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
    1.49 -    Uint32 timestamp;
    1.50 -    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.51 -    SDL_TouchID touchId;        /**< The touch device index */
    1.52 -    Uint8 state;        /**< The current button state */
    1.53 -    Uint8 button;        /**< The button changing state */
    1.54 -    Uint8 padding1;
    1.55 -    Uint8 padding2;
    1.56 -} SDL_TouchButtonEvent;
    1.57 -
    1.58 -
    1.59 -/**
    1.60   *  \brief Multiple Finger Gesture Event (event.mgesture.*)
    1.61   */
    1.62  typedef struct SDL_MultiGestureEvent
    1.63  {
    1.64      Uint32 type;        /**< ::SDL_MULTIGESTURE */
    1.65      Uint32 timestamp;
    1.66 -    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.67 -    SDL_TouchID touchId;        /**< The touch device index */
    1.68 +    SDL_TouchID touchId; /**< The touch device index */
    1.69      float dTheta;
    1.70      float dDist;
    1.71 -    float x;  /* currently 0...1. Change to screen coords? */
    1.72 +    float x;
    1.73      float y;  
    1.74      Uint16 numFingers;
    1.75      Uint16 padding;
    1.76  } SDL_MultiGestureEvent;
    1.77  
    1.78 +
    1.79  /* (event.dgesture.*) */
    1.80  typedef struct SDL_DollarGestureEvent
    1.81  {
    1.82      Uint32 type;        /**< ::SDL_DOLLARGESTURE */
    1.83      Uint32 timestamp;
    1.84 -    Uint32 windowID;    /**< The window with mouse focus, if any */
    1.85 -    SDL_TouchID touchId;        /**< The touch device index */
    1.86 +    SDL_TouchID touchId; /**< The touch device id */
    1.87      SDL_GestureID gestureId;
    1.88      Uint32 numFingers;
    1.89      float error;
    1.90 -  /*
    1.91 -    //TODO: Enable to give location?
    1.92 -    float x;  //currently 0...1. Change to screen coords?
    1.93 -    float y;  
    1.94 -  */
    1.95 +    float x;            /**< Normalized center of gesture */
    1.96 +    float y;            /**< Normalized center of gesture */
    1.97  } SDL_DollarGestureEvent;
    1.98  
    1.99  
   1.100 @@ -518,9 +491,8 @@
   1.101      SDL_UserEvent user;             /**< Custom event data */
   1.102      SDL_SysWMEvent syswm;           /**< System dependent window event data */
   1.103      SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
   1.104 -    SDL_TouchButtonEvent tbutton;   /**< Touch button event data */
   1.105 -    SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */
   1.106 -    SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */
   1.107 +    SDL_MultiGestureEvent mgesture; /**< Gesture event data */
   1.108 +    SDL_DollarGestureEvent dgesture; /**< Gesture event data */
   1.109      SDL_DropEvent drop;             /**< Drag and drop event data */
   1.110  
   1.111      /* This is necessary for ABI compatibility between Visual C++ and GCC
     2.1 --- a/include/SDL_touch.h	Sat Mar 02 20:44:16 2013 -0800
     2.2 +++ b/include/SDL_touch.h	Sun Mar 03 01:01:33 2013 -0800
     2.3 @@ -46,46 +46,11 @@
     2.4  typedef struct SDL_Finger
     2.5  {
     2.6      SDL_FingerID id;
     2.7 -    Uint16 x;
     2.8 -    Uint16 y;
     2.9 -    Uint16 pressure;
    2.10 -    Uint16 xdelta;
    2.11 -    Uint16 ydelta;
    2.12 -    Uint16 last_x, last_y,last_pressure;  /* the last reported coordinates */
    2.13 -    SDL_bool down;
    2.14 +    float x;
    2.15 +    float y;
    2.16 +    float pressure;
    2.17  } SDL_Finger;
    2.18  
    2.19 -typedef struct SDL_Touch
    2.20 -{
    2.21 -  /* Free the touch when it's time */
    2.22 -  void (*FreeTouch) (struct SDL_Touch * touch);
    2.23 -  
    2.24 -  /* data common for tablets */
    2.25 -  float pressure_max, pressure_min;
    2.26 -  float x_max,x_min;
    2.27 -  float y_max,y_min;
    2.28 -  Uint16 xres,yres,pressureres;
    2.29 -  float native_xres,native_yres,native_pressureres;
    2.30 -  float tilt_x;                 /* for future use */
    2.31 -  float tilt_y;                 /* for future use */
    2.32 -  float rotation;               /* for future use */
    2.33 -  
    2.34 -  /* Data common to all touch */
    2.35 -  SDL_TouchID id;
    2.36 -  SDL_Window *focus;
    2.37 -  
    2.38 -  char *name;
    2.39 -  Uint8 buttonstate;
    2.40 -  SDL_bool relative_mode;
    2.41 -  SDL_bool flush_motion;
    2.42 -
    2.43 -  int num_fingers;
    2.44 -  int max_fingers;
    2.45 -  SDL_Finger** fingers;
    2.46 -    
    2.47 -  void *driverdata;
    2.48 -} SDL_Touch;
    2.49 -
    2.50  /* Used as the device ID for mouse events simulated with touch input */
    2.51  #define SDL_TOUCH_MOUSEID ((Uint32)-1)
    2.52  
    2.53 @@ -93,14 +58,24 @@
    2.54  /* Function prototypes */
    2.55  
    2.56  /**
    2.57 - *  \brief Get the touch object with the given id.
    2.58 + *  \brief Get the number of registered touch devices.
    2.59   */
    2.60 -extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(SDL_TouchID id);
    2.61 +extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices();
    2.62  
    2.63  /**
    2.64 - *  \brief Get the finger object of the given touch, with the given id.
    2.65 + *  \brief Get the touch ID with the given index, or 0 if the index is invalid.
    2.66   */
    2.67 -extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, SDL_FingerID id);
    2.68 +extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index);
    2.69 +
    2.70 +/**
    2.71 + *  \brief Get the number of active fingers for a given touch device.
    2.72 + */
    2.73 +extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
    2.74 +
    2.75 +/**
    2.76 + *  \brief Get the finger object of the given touch, with the given index.
    2.77 + */
    2.78 +extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
    2.79  
    2.80  /* Ends C function definitions when using C++ */
    2.81  #ifdef __cplusplus
     3.1 --- a/src/events/SDL_gesture.c	Sat Mar 02 20:44:16 2013 -0800
     3.2 +++ b/src/events/SDL_gesture.c	Sun Mar 03 01:01:33 2013 -0800
     3.3 @@ -64,7 +64,6 @@
     3.4  
     3.5  typedef struct {
     3.6      SDL_TouchID id;
     3.7 -    SDL_FloatPoint res;
     3.8      SDL_FloatPoint centroid;
     3.9      SDL_DollarPath dollarPath;
    3.10      Uint16 numDownFingers;
    3.11 @@ -410,7 +409,7 @@
    3.12      return bestDiff;
    3.13  }
    3.14  
    3.15 -int SDL_GestureAddTouch(SDL_Touch* touch)
    3.16 +int SDL_GestureAddTouch(SDL_TouchID touchId)
    3.17  {
    3.18      SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
    3.19                                                                       (SDL_numGestureTouches + 1) *
    3.20 @@ -423,12 +422,8 @@
    3.21  
    3.22      SDL_gestureTouch = gestureTouch;
    3.23  
    3.24 -    SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
    3.25 -    SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres;
    3.26      SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
    3.27 -
    3.28 -    SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres;
    3.29 -    SDL_gestureTouch[SDL_numGestureTouches].id = touch->id;
    3.30 +    SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
    3.31  
    3.32      SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
    3.33  
    3.34 @@ -468,11 +463,8 @@
    3.35      SDL_Event event;
    3.36      event.dgesture.type = SDL_DOLLARGESTURE;
    3.37      event.dgesture.touchId = touch->id;
    3.38 -    /*
    3.39 -    //TODO: Add this to give location of gesture?
    3.40      event.mgesture.x = touch->centroid.x;
    3.41      event.mgesture.y = touch->centroid.y;
    3.42 -    */
    3.43      event.dgesture.gestureId = gestureId;
    3.44      event.dgesture.error = error;
    3.45      //A finger came up to trigger this event.
    3.46 @@ -513,14 +505,8 @@
    3.47          //Shouldn't be possible
    3.48          if (inTouch == NULL) return;
    3.49  
    3.50 -        //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x,
    3.51 -        //           (int)event->tfinger.y,
    3.52 -        //   (int)inTouch->res.x,(int)inTouch->res.y);
    3.53 -
    3.54 -
    3.55 -        x = ((float)event->tfinger.x)/(float)inTouch->res.x;
    3.56 -        y = ((float)event->tfinger.y)/(float)inTouch->res.y;
    3.57 -
    3.58 +        x = event->tfinger.x;
    3.59 +        y = event->tfinger.y;
    3.60  
    3.61          //Finger Up
    3.62          if (event->type == SDL_FINGERUP) {
    3.63 @@ -569,9 +555,8 @@
    3.64              }
    3.65          }
    3.66          else if (event->type == SDL_FINGERMOTION) {
    3.67 -            float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x;
    3.68 -            float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y;
    3.69 -            //printf("dx,dy: (%f,%f)\n",dx,dy);
    3.70 +            float dx = event->tfinger.dx;
    3.71 +            float dy = event->tfinger.dy;
    3.72  #ifdef ENABLE_DOLLAR
    3.73              SDL_DollarPath* path = &inTouch->dollarPath;
    3.74              if (path->numPoints < MAXPATHSIZE) {
     4.1 --- a/src/events/SDL_gesture_c.h	Sat Mar 02 20:44:16 2013 -0800
     4.2 +++ b/src/events/SDL_gesture_c.h	Sun Mar 03 01:01:33 2013 -0800
     4.3 @@ -23,12 +23,12 @@
     4.4  #ifndef _SDL_gesture_c_h
     4.5  #define _SDL_gesture_c_h
     4.6  
     4.7 +extern int SDL_GestureAddTouch(SDL_TouchID touchId);
     4.8 +
     4.9  extern void SDL_GestureProcessEvent(SDL_Event* event);
    4.10  
    4.11  extern int SDL_RecordGesture(SDL_TouchID touchId);
    4.12  
    4.13 -extern int SDL_GestureAddTouch(SDL_Touch* touch);
    4.14 -
    4.15  #endif /* _SDL_gesture_c_h */
    4.16  
    4.17  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/events/SDL_touch.c	Sat Mar 02 20:44:16 2013 -0800
     5.2 +++ b/src/events/SDL_touch.c	Sun Mar 03 01:01:33 2013 -0800
     5.3 @@ -22,72 +22,46 @@
     5.4  
     5.5  /* General touch handling code for SDL */
     5.6  
     5.7 +#include "SDL_assert.h"
     5.8  #include "SDL_events.h"
     5.9  #include "SDL_events_c.h"
    5.10 -#include "../video/SDL_sysvideo.h"
    5.11 -
    5.12 -#include <stdio.h>
    5.13  
    5.14  
    5.15  static int SDL_num_touch = 0;
    5.16 -static SDL_Touch **SDL_touchPads = NULL;
    5.17 +static SDL_Touch **SDL_touchDevices = NULL;
    5.18  
    5.19  
    5.20  /* Public functions */
    5.21  int
    5.22  SDL_TouchInit(void)
    5.23  {
    5.24 -  return (0);
    5.25 +    return (0);
    5.26  }
    5.27  
    5.28 -SDL_Touch *
    5.29 -SDL_GetTouch(SDL_TouchID id)
    5.30 +int
    5.31 +SDL_GetNumTouchDevices()
    5.32  {
    5.33 -    int index = SDL_GetTouchIndexId(id);
    5.34 -    if (index < 0 || index >= SDL_num_touch) {
    5.35 -        return NULL;
    5.36 -    }
    5.37 -    return SDL_touchPads[index];
    5.38 +    return SDL_num_touch;
    5.39  }
    5.40  
    5.41 -SDL_Touch *
    5.42 -SDL_GetTouchIndex(int index)
    5.43 +SDL_TouchID
    5.44 +SDL_GetTouchDevice(int index)
    5.45  {
    5.46      if (index < 0 || index >= SDL_num_touch) {
    5.47 -        return NULL;
    5.48 +        SDL_SetError("Unknown touch device");
    5.49 +        return 0;
    5.50      }
    5.51 -    return SDL_touchPads[index];
    5.52 +    return SDL_touchDevices[index]->id;
    5.53  }
    5.54  
    5.55  static int
    5.56 -SDL_GetFingerIndexId(SDL_Touch* touch,SDL_FingerID fingerid)
    5.57 -{
    5.58 -    int i;
    5.59 -    for(i = 0;i < touch->num_fingers;i++)
    5.60 -        if(touch->fingers[i]->id == fingerid)
    5.61 -            return i;
    5.62 -    return -1;
    5.63 -}
    5.64 -
    5.65 -
    5.66 -SDL_Finger *
    5.67 -SDL_GetFinger(SDL_Touch* touch,SDL_FingerID id)
    5.68 -{
    5.69 -    int index = SDL_GetFingerIndexId(touch,id);
    5.70 -    if(index < 0 || index >= touch->num_fingers)
    5.71 -        return NULL;
    5.72 -    return touch->fingers[index];
    5.73 -}
    5.74 -
    5.75 -
    5.76 -int
    5.77 -SDL_GetTouchIndexId(SDL_TouchID id)
    5.78 +SDL_GetTouchIndex(SDL_TouchID id)
    5.79  {
    5.80      int index;
    5.81      SDL_Touch *touch;
    5.82  
    5.83      for (index = 0; index < SDL_num_touch; ++index) {
    5.84 -        touch = SDL_touchPads[index];
    5.85 +        touch = SDL_touchDevices[index];
    5.86          if (touch->id == id) {
    5.87              return index;
    5.88          }
    5.89 @@ -95,78 +69,284 @@
    5.90      return -1;
    5.91  }
    5.92  
    5.93 +SDL_Touch *
    5.94 +SDL_GetTouch(SDL_TouchID id)
    5.95 +{
    5.96 +    int index = SDL_GetTouchIndex(id);
    5.97 +    if (index < 0 || index >= SDL_num_touch) {
    5.98 +        SDL_SetError("Unknown touch device");
    5.99 +        return NULL;
   5.100 +    }
   5.101 +    return SDL_touchDevices[index];
   5.102 +}
   5.103 +
   5.104 +static int
   5.105 +SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
   5.106 +{
   5.107 +    int index;
   5.108 +    for (index = 0; index < touch->num_fingers; ++index) {
   5.109 +        if (touch->fingers[index]->id == fingerid) {
   5.110 +            return index;
   5.111 +        }
   5.112 +    }
   5.113 +    return -1;
   5.114 +}
   5.115 +
   5.116 +SDL_Finger *
   5.117 +SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id)
   5.118 +{
   5.119 +    int index = SDL_GetFingerIndex(touch, id);
   5.120 +    if (index < 0 || index >= touch->num_fingers) {
   5.121 +        return NULL;
   5.122 +    }
   5.123 +    return touch->fingers[index];
   5.124 +}
   5.125 +
   5.126  int
   5.127 -SDL_AddTouch(const SDL_Touch * touch, char *name)
   5.128 +SDL_GetNumTouchFingers(SDL_TouchID touchID)
   5.129  {
   5.130 -    SDL_Touch **touchPads;
   5.131 +    SDL_Touch *touch = SDL_GetTouch(touchID);
   5.132 +    if (touch) {
   5.133 +        return touch->num_fingers;
   5.134 +    }
   5.135 +    return 0;
   5.136 +}
   5.137 +
   5.138 +SDL_Finger *
   5.139 +SDL_GetTouchFinger(SDL_TouchID touchID, int index)
   5.140 +{
   5.141 +    SDL_Touch *touch = SDL_GetTouch(touchID);
   5.142 +    if (!touch) {
   5.143 +        return NULL;
   5.144 +    }
   5.145 +    if (index < 0 || index >= touch->num_fingers) {
   5.146 +        SDL_SetError("Unknown touch finger");
   5.147 +        return NULL;
   5.148 +    }
   5.149 +    return touch->fingers[index];
   5.150 +}
   5.151 +
   5.152 +int
   5.153 +SDL_AddTouch(SDL_TouchID touchID, const char *name)
   5.154 +{
   5.155 +    SDL_Touch **touchDevices;
   5.156      int index;
   5.157 -    size_t length;
   5.158  
   5.159 -    if (SDL_GetTouchIndexId(touch->id) != -1) {
   5.160 -        SDL_SetError("Touch ID already in use");
   5.161 +    index = SDL_GetTouchIndex(touchID);
   5.162 +    if (index >= 0) {
   5.163 +        return index;
   5.164      }
   5.165  
   5.166      /* Add the touch to the list of touch */
   5.167 -    touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
   5.168 -                                      (SDL_num_touch + 1) * sizeof(*touch));
   5.169 -    if (!touchPads) {
   5.170 +    touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
   5.171 +                                      (SDL_num_touch + 1) * sizeof(*touchDevices));
   5.172 +    if (!touchDevices) {
   5.173          SDL_OutOfMemory();
   5.174          return -1;
   5.175      }
   5.176  
   5.177 -    SDL_touchPads = touchPads;
   5.178 +    SDL_touchDevices = touchDevices;
   5.179      index = SDL_num_touch++;
   5.180  
   5.181 -    SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
   5.182 -    if (!SDL_touchPads[index]) {
   5.183 +    SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
   5.184 +    if (!SDL_touchDevices[index]) {
   5.185          SDL_OutOfMemory();
   5.186          return -1;
   5.187      }
   5.188 -    SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch));
   5.189  
   5.190      /* we're setting the touch properties */
   5.191 -    length = SDL_strlen(name);
   5.192 -    SDL_touchPads[index]->focus = 0;
   5.193 -    SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
   5.194 -    SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   
   5.195 +    SDL_touchDevices[index]->id = touchID;
   5.196 +    SDL_touchDevices[index]->num_fingers = 0;
   5.197 +    SDL_touchDevices[index]->max_fingers = 0;
   5.198 +    SDL_touchDevices[index]->fingers = NULL;
   5.199  
   5.200 -    SDL_touchPads[index]->num_fingers = 0;
   5.201 -    SDL_touchPads[index]->max_fingers = 1;
   5.202 -    SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
   5.203 -    SDL_touchPads[index]->fingers[0] = NULL;
   5.204 -    SDL_touchPads[index]->buttonstate = 0;
   5.205 -    SDL_touchPads[index]->relative_mode = SDL_FALSE;
   5.206 -    SDL_touchPads[index]->flush_motion = SDL_FALSE;
   5.207 -    
   5.208 -    SDL_touchPads[index]->xres = (1<<(16-1));
   5.209 -    SDL_touchPads[index]->yres = (1<<(16-1));
   5.210 -    SDL_touchPads[index]->pressureres = (1<<(16-1));
   5.211 -    //Do I want this here? Probably
   5.212 -    SDL_GestureAddTouch(SDL_touchPads[index]);
   5.213 +    /* Record this touch device for gestures */
   5.214 +    /* We could do this on the fly in the gesture code if we wanted */
   5.215 +    SDL_GestureAddTouch(touchID);
   5.216  
   5.217      return index;
   5.218  }
   5.219  
   5.220 +static int 
   5.221 +SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
   5.222 +{
   5.223 +    SDL_Finger *finger;
   5.224 +
   5.225 +    if (touch->num_fingers == touch->max_fingers) {
   5.226 +        SDL_Finger **new_fingers;
   5.227 +        new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
   5.228 +        if (!new_fingers) {
   5.229 +            SDL_OutOfMemory();
   5.230 +            return -1;
   5.231 +        }
   5.232 +        touch->fingers = new_fingers;
   5.233 +        touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger));
   5.234 +        if (!touch->fingers[touch->max_fingers]) {
   5.235 +            SDL_OutOfMemory();
   5.236 +            return -1;
   5.237 +        }
   5.238 +        touch->max_fingers++;
   5.239 +    }
   5.240 +
   5.241 +    finger = touch->fingers[touch->num_fingers++];
   5.242 +    finger->id = fingerid;
   5.243 +    finger->x = x;
   5.244 +    finger->y = y;
   5.245 +    finger->pressure = pressure;
   5.246 +    return 0;
   5.247 +}
   5.248 +
   5.249 +static int
   5.250 +SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid)
   5.251 +{
   5.252 +    SDL_Finger *temp;
   5.253 +
   5.254 +    int index = SDL_GetFingerIndex(touch, fingerid);
   5.255 +    if (index < 0) {
   5.256 +        return -1;
   5.257 +    }
   5.258 +
   5.259 +    touch->num_fingers--;
   5.260 +    temp = touch->fingers[index];
   5.261 +    touch->fingers[index] = touch->fingers[touch->num_fingers];
   5.262 +    touch->fingers[touch->num_fingers] = temp;
   5.263 +    return 0;
   5.264 +}
   5.265 +
   5.266 +int
   5.267 +SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
   5.268 +              SDL_bool down, float x, float y, float pressure)
   5.269 +{
   5.270 +    int posted;
   5.271 +    SDL_Finger *finger;
   5.272 +
   5.273 +    SDL_Touch* touch = SDL_GetTouch(id);
   5.274 +    if (!touch) {
   5.275 +        return -1;
   5.276 +    }
   5.277 +
   5.278 +    finger = SDL_GetFinger(touch, fingerid);
   5.279 +    if (down) {
   5.280 +        if (finger) {
   5.281 +            /* This finger is already down */
   5.282 +            return 0;
   5.283 +        }
   5.284 +
   5.285 +        if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
   5.286 +            return 0;
   5.287 +        }
   5.288 +
   5.289 +        posted = 0;
   5.290 +        if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
   5.291 +            SDL_Event event;
   5.292 +            event.tfinger.type = SDL_FINGERDOWN;
   5.293 +            event.tfinger.touchId = id;
   5.294 +            event.tfinger.fingerId = fingerid;
   5.295 +            event.tfinger.x = x;
   5.296 +            event.tfinger.y = y;
   5.297 +            event.tfinger.dx = 0;
   5.298 +            event.tfinger.dy = 0;
   5.299 +            event.tfinger.pressure = pressure;
   5.300 +            posted = (SDL_PushEvent(&event) > 0);
   5.301 +        }
   5.302 +    } else {
   5.303 +        if (!finger) {
   5.304 +            /* This finger is already up */
   5.305 +            return 0;
   5.306 +        }
   5.307 +
   5.308 +        posted = 0;
   5.309 +        if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
   5.310 +            SDL_Event event;
   5.311 +            event.tfinger.type = SDL_FINGERUP;
   5.312 +            event.tfinger.touchId =  id;
   5.313 +            event.tfinger.fingerId = fingerid;
   5.314 +            /* I don't trust the coordinates passed on fingerUp */
   5.315 +            event.tfinger.x = finger->x; 
   5.316 +            event.tfinger.y = finger->y;
   5.317 +            event.tfinger.dx = 0;
   5.318 +            event.tfinger.dy = 0;
   5.319 +            event.tfinger.pressure = pressure;
   5.320 +            posted = (SDL_PushEvent(&event) > 0);
   5.321 +        }
   5.322 +
   5.323 +        SDL_DelFinger(touch, fingerid);
   5.324 +    }
   5.325 +    return posted;
   5.326 +}
   5.327 +
   5.328 +int
   5.329 +SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
   5.330 +                    float x, float y, float pressure)
   5.331 +{
   5.332 +    SDL_Touch *touch;
   5.333 +    SDL_Finger *finger;
   5.334 +    int posted;
   5.335 +    float xrel, yrel, prel;
   5.336 +
   5.337 +    touch = SDL_GetTouch(id);
   5.338 +    if (!touch) {
   5.339 +        return -1;
   5.340 +    }
   5.341 +
   5.342 +    finger = SDL_GetFinger(touch,fingerid);
   5.343 +    if (!finger) {
   5.344 +        return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);        
   5.345 +    }
   5.346 +
   5.347 +    xrel = x - finger->x;
   5.348 +    yrel = y - finger->y;
   5.349 +    prel = pressure - finger->pressure;
   5.350 +
   5.351 +    /* Drop events that don't change state */
   5.352 +    if (!xrel && !yrel && !prel) {
   5.353 +#if 0
   5.354 +        printf("Touch event didn't change state - dropped!\n");
   5.355 +#endif
   5.356 +        return 0;
   5.357 +    }
   5.358 +
   5.359 +    /* Update internal touch coordinates */
   5.360 +    finger->x = x;
   5.361 +    finger->y = y;
   5.362 +    finger->pressure = pressure;
   5.363 +        
   5.364 +    /* Post the event, if desired */
   5.365 +    posted = 0;
   5.366 +    if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
   5.367 +        SDL_Event event;
   5.368 +        event.tfinger.type = SDL_FINGERMOTION;
   5.369 +        event.tfinger.touchId = id;
   5.370 +        event.tfinger.fingerId = fingerid;
   5.371 +        event.tfinger.x = x;
   5.372 +        event.tfinger.y = y;
   5.373 +        event.tfinger.dx = xrel;
   5.374 +        event.tfinger.dy = yrel;            
   5.375 +        event.tfinger.pressure = pressure;
   5.376 +        posted = (SDL_PushEvent(&event) > 0);
   5.377 +    }
   5.378 +    return posted;
   5.379 +}
   5.380 +
   5.381  void
   5.382  SDL_DelTouch(SDL_TouchID id)
   5.383  {
   5.384 -    int index = SDL_GetTouchIndexId(id);
   5.385 +    int i;
   5.386 +    int index = SDL_GetTouchIndex(id);
   5.387      SDL_Touch *touch = SDL_GetTouch(id);
   5.388  
   5.389      if (!touch) {
   5.390          return;
   5.391      }
   5.392  
   5.393 -    
   5.394 -    SDL_free(touch->name);
   5.395 - 
   5.396 -    if (touch->FreeTouch) {
   5.397 -        touch->FreeTouch(touch);
   5.398 +    for (i = 0; i < touch->max_fingers; ++i) {
   5.399 +        SDL_free(touch->fingers[i]);
   5.400      }
   5.401 +    SDL_free(touch->fingers);
   5.402      SDL_free(touch);
   5.403  
   5.404      SDL_num_touch--;
   5.405 -    SDL_touchPads[index] = SDL_touchPads[SDL_num_touch];
   5.406 +    SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
   5.407  }
   5.408  
   5.409  void
   5.410 @@ -174,400 +354,15 @@
   5.411  {
   5.412      int i;
   5.413  
   5.414 -    for (i = SDL_num_touch-1; i > 0 ; --i) {
   5.415 -        SDL_DelTouch(i);
   5.416 +    for (i = SDL_num_touch; i--; ) {
   5.417 +        SDL_DelTouch(SDL_touchDevices[i]->id);
   5.418      }
   5.419 -    SDL_num_touch = 0;
   5.420 +    SDL_assert(SDL_num_touch == 0);
   5.421  
   5.422 -    if (SDL_touchPads) {
   5.423 -        SDL_free(SDL_touchPads);
   5.424 -        SDL_touchPads = NULL;
   5.425 +    if (SDL_touchDevices) {
   5.426 +        SDL_free(SDL_touchDevices);
   5.427 +        SDL_touchDevices = NULL;
   5.428      }
   5.429  }
   5.430  
   5.431 -int
   5.432 -SDL_GetNumTouch(void)
   5.433 -{
   5.434 -    return SDL_num_touch;
   5.435 -}
   5.436 -
   5.437 -SDL_Window *
   5.438 -SDL_GetTouchFocusWindow(SDL_TouchID id)
   5.439 -{
   5.440 -    SDL_Touch *touch = SDL_GetTouch(id);
   5.441 -
   5.442 -    if (!touch) {
   5.443 -        return 0;
   5.444 -    }
   5.445 -    return touch->focus;
   5.446 -}
   5.447 -
   5.448 -void
   5.449 -SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window)
   5.450 -{
   5.451 -    int index = SDL_GetTouchIndexId(id);
   5.452 -    SDL_Touch *touch = SDL_GetTouch(id);
   5.453 -    int i;
   5.454 -    SDL_bool focus;
   5.455 -
   5.456 -    if (!touch || (touch->focus == window)) {
   5.457 -        return;
   5.458 -    }
   5.459 -
   5.460 -    /* See if the current window has lost focus */
   5.461 -    if (touch->focus) {
   5.462 -        focus = SDL_FALSE;
   5.463 -        for (i = 0; i < SDL_num_touch; ++i) {
   5.464 -            SDL_Touch *check;
   5.465 -            if (i != index) {
   5.466 -                check = SDL_touchPads[i];
   5.467 -                if (check && check->focus == touch->focus) {
   5.468 -                    focus = SDL_TRUE;
   5.469 -                    break;
   5.470 -                }
   5.471 -            }
   5.472 -        }
   5.473 -        if (!focus) {
   5.474 -            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   5.475 -        }
   5.476 -    }
   5.477 -
   5.478 -    touch->focus = window;
   5.479 -
   5.480 -    if (touch->focus) {
   5.481 -        focus = SDL_FALSE;
   5.482 -        for (i = 0; i < SDL_num_touch; ++i) {
   5.483 -            SDL_Touch *check;
   5.484 -            if (i != index) {
   5.485 -                check = SDL_touchPads[i];
   5.486 -                if (check && check->focus == touch->focus) {
   5.487 -                    focus = SDL_TRUE;
   5.488 -                    break;
   5.489 -                }
   5.490 -            }
   5.491 -        }
   5.492 -        if (!focus) {
   5.493 -            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   5.494 -        }
   5.495 -    }
   5.496 -}
   5.497 -
   5.498 -int 
   5.499 -SDL_AddFinger(SDL_Touch* touch,SDL_Finger *finger)
   5.500 -{
   5.501 -    int index;
   5.502 -    SDL_Finger **fingers;
   5.503 -    //printf("Adding Finger...\n");
   5.504 -    if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
   5.505 -        SDL_SetError("Finger ID already in use");
   5.506 -        }
   5.507 -
   5.508 -    /* Add the touch to the list of touch */
   5.509 -    if(touch->num_fingers  >= touch->max_fingers){
   5.510 -                //printf("Making room for it!\n");
   5.511 -                fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
   5.512 -                                                     (touch->num_fingers + 1) * sizeof(SDL_Finger *));
   5.513 -                if (!fingers) {
   5.514 -                        SDL_OutOfMemory();
   5.515 -                        return -1;
   5.516 -                } else {
   5.517 -                        touch->max_fingers = touch->num_fingers+1;
   5.518 -                        touch->fingers = fingers;
   5.519 -                }
   5.520 -        }
   5.521 -
   5.522 -    index = touch->num_fingers;
   5.523 -    //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
   5.524 -
   5.525 -    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
   5.526 -    if (!touch->fingers[index]) {
   5.527 -        SDL_OutOfMemory();
   5.528 -        return -1;
   5.529 -    }
   5.530 -    *(touch->fingers[index]) = *finger;
   5.531 -    touch->num_fingers++;
   5.532 -
   5.533 -    return index;
   5.534 -}
   5.535 -
   5.536 -int
   5.537 -SDL_DelFinger(SDL_Touch* touch,SDL_FingerID fingerid)
   5.538 -{
   5.539 -    int index = SDL_GetFingerIndexId(touch,fingerid);
   5.540 -    SDL_Finger* finger = SDL_GetFinger(touch,fingerid);
   5.541 -
   5.542 -    if (!finger) {
   5.543 -        return -1;
   5.544 -    }
   5.545 - 
   5.546 -
   5.547 -    SDL_free(finger);
   5.548 -    touch->num_fingers--;
   5.549 -    touch->fingers[index] = touch->fingers[touch->num_fingers];
   5.550 -    return 0;
   5.551 -}
   5.552 -
   5.553 -
   5.554 -int
   5.555 -SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, 
   5.556 -                   float xin, float yin, float pressurein)
   5.557 -{
   5.558 -    int posted;
   5.559 -        Uint16 x;
   5.560 -        Uint16 y;
   5.561 -        Uint16 pressure;
   5.562 -        SDL_Finger *finger;
   5.563 -
   5.564 -    SDL_Touch* touch = SDL_GetTouch(id);
   5.565 -
   5.566 -    if(!touch) {
   5.567 -      return SDL_TouchNotFoundError(id);
   5.568 -    }
   5.569 -
   5.570 -    
   5.571 -    //scale to Integer coordinates
   5.572 -    x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
   5.573 -    y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
   5.574 -    pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
   5.575 -    
   5.576 -    finger = SDL_GetFinger(touch,fingerid);
   5.577 -    if(down) {
   5.578 -        if(finger == NULL) {
   5.579 -            SDL_Finger nf;
   5.580 -            nf.id = fingerid;
   5.581 -            nf.x = x;
   5.582 -            nf.y = y;
   5.583 -            nf.pressure = pressure;
   5.584 -            nf.xdelta = 0;
   5.585 -            nf.ydelta = 0;
   5.586 -            nf.last_x = x;
   5.587 -            nf.last_y = y;
   5.588 -            nf.last_pressure = pressure;
   5.589 -            nf.down = SDL_FALSE;
   5.590 -            if(SDL_AddFinger(touch,&nf) < 0) return 0;
   5.591 -            finger = SDL_GetFinger(touch,fingerid);
   5.592 -        }
   5.593 -        else if(finger->down) return 0;
   5.594 -        if(xin < touch->x_min || yin < touch->y_min) return 0; //should defer if only a partial input
   5.595 -        posted = 0;
   5.596 -        if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
   5.597 -            SDL_Event event;
   5.598 -            event.tfinger.type = SDL_FINGERDOWN;
   5.599 -            event.tfinger.touchId = id;
   5.600 -            event.tfinger.x = x;
   5.601 -            event.tfinger.y = y;
   5.602 -            event.tfinger.dx = 0;
   5.603 -            event.tfinger.dy = 0;
   5.604 -            event.tfinger.pressure = pressure;
   5.605 -            event.tfinger.state = touch->buttonstate;
   5.606 -            event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   5.607 -            event.tfinger.fingerId = fingerid;
   5.608 -            posted = (SDL_PushEvent(&event) > 0);
   5.609 -        }
   5.610 -        if(posted) finger->down = SDL_TRUE;
   5.611 -        return posted;
   5.612 -    }
   5.613 -    else {
   5.614 -        if(finger == NULL) {
   5.615 -            SDL_SetError("Finger not found.");
   5.616 -            return 0;
   5.617 -        }      
   5.618 -        posted = 0;
   5.619 -        if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
   5.620 -            SDL_Event event;
   5.621 -            event.tfinger.type = SDL_FINGERUP;
   5.622 -            event.tfinger.touchId =  id;
   5.623 -            event.tfinger.state = touch->buttonstate;
   5.624 -            event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   5.625 -            event.tfinger.fingerId = fingerid;
   5.626 -            //I don't trust the coordinates passed on fingerUp
   5.627 -            event.tfinger.x = finger->x; 
   5.628 -            event.tfinger.y = finger->y;
   5.629 -            event.tfinger.dx = 0;
   5.630 -            event.tfinger.dy = 0;
   5.631 -            event.tfinger.pressure = pressure;
   5.632 -
   5.633 -            if(SDL_DelFinger(touch,fingerid) < 0) return 0;
   5.634 -            posted = (SDL_PushEvent(&event) > 0);
   5.635 -        }        
   5.636 -        return posted;
   5.637 -    }
   5.638 -}
   5.639 -
   5.640 -int
   5.641 -SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, int relative, 
   5.642 -                    float xin, float yin, float pressurein)
   5.643 -{
   5.644 -    SDL_Touch *touch;
   5.645 -    SDL_Finger *finger;
   5.646 -    int posted;
   5.647 -    Sint16 xrel, yrel;
   5.648 -    Uint16 x;
   5.649 -    Uint16 y;
   5.650 -    Uint16 pressure;
   5.651 -    
   5.652 -    touch = SDL_GetTouch(id);
   5.653 -    if (!touch) {
   5.654 -      return SDL_TouchNotFoundError(id);
   5.655 -    }
   5.656 -
   5.657 -    //scale to Integer coordinates
   5.658 -    x = (Uint16)((xin+touch->x_min)*(touch->xres)/(touch->native_xres));
   5.659 -    y = (Uint16)((yin+touch->y_min)*(touch->yres)/(touch->native_yres));
   5.660 -    pressure = (Uint16)((pressurein+touch->pressure_min)*(touch->pressureres)/(touch->native_pressureres));
   5.661 -    if(touch->flush_motion) {
   5.662 -        return 0;
   5.663 -    }
   5.664 -    
   5.665 -    finger = SDL_GetFinger(touch,fingerid);
   5.666 -    if(finger == NULL || !finger->down) {
   5.667 -        return SDL_SendFingerDown(id,fingerid,SDL_TRUE,xin,yin,pressurein);        
   5.668 -    } else {
   5.669 -        /* the relative motion is calculated regarding the last position */
   5.670 -        if (relative) {
   5.671 -            xrel = x;
   5.672 -            yrel = y;
   5.673 -            x = (finger->last_x + x);
   5.674 -            y = (finger->last_y + y);
   5.675 -        } else {
   5.676 -            if(xin < touch->x_min) x = finger->last_x; /*If movement is only in one axis,*/
   5.677 -            if(yin < touch->y_min) y = finger->last_y; /*The other is marked as -1*/
   5.678 -            if(pressurein < touch->pressure_min) pressure = finger->last_pressure;
   5.679 -            xrel = x - finger->last_x;
   5.680 -            yrel = y - finger->last_y;
   5.681 -            //printf("xrel,yrel (%i,%i)\n",(int)xrel,(int)yrel);
   5.682 -        }
   5.683 -        
   5.684 -        /* Drop events that don't change state */
   5.685 -        if (!xrel && !yrel) {
   5.686 -#if 0
   5.687 -            printf("Touch event didn't change state - dropped!\n");
   5.688 -#endif
   5.689 -            return 0;
   5.690 -        }
   5.691 -        
   5.692 -        /* Update internal touch coordinates */
   5.693 -        
   5.694 -        finger->x = x;
   5.695 -        finger->y = y;
   5.696 -        
   5.697 -        /*Should scale to window? Normalize? Maintain Aspect?*/
   5.698 -        //SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   5.699 -        
   5.700 -        /* make sure that the pointers find themselves inside the windows */
   5.701 -        /* only check if touch->xmax is set ! */
   5.702 -        /*
   5.703 -          if (x_max && touch->x > x_max) {
   5.704 -          touch->x = x_max;
   5.705 -          } else if (touch->x < 0) {
   5.706 -          touch->x = 0;
   5.707 -          }
   5.708 -          
   5.709 -          if (y_max && touch->y > y_max) {
   5.710 -          touch->y = y_max;
   5.711 -          } else if (touch->y < 0) {
   5.712 -          touch->y = 0;
   5.713 -          }
   5.714 -        */
   5.715 -        finger->xdelta = xrel;
   5.716 -        finger->ydelta = yrel;
   5.717 -        finger->pressure = pressure;
   5.718 -        
   5.719 -        
   5.720 -        
   5.721 -        /* Post the event, if desired */
   5.722 -        posted = 0;
   5.723 -        if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
   5.724 -            SDL_Event event;
   5.725 -            event.tfinger.type = SDL_FINGERMOTION;
   5.726 -            event.tfinger.touchId = id;
   5.727 -            event.tfinger.fingerId = fingerid;
   5.728 -            event.tfinger.x = x;
   5.729 -            event.tfinger.y = y;
   5.730 -            event.tfinger.dx = xrel;
   5.731 -            event.tfinger.dy = yrel;            
   5.732 -                
   5.733 -            event.tfinger.pressure = pressure;
   5.734 -            event.tfinger.state = touch->buttonstate;
   5.735 -            event.tfinger.windowID = touch->focus ? touch->focus->id : 0;
   5.736 -            posted = (SDL_PushEvent(&event) > 0);
   5.737 -        }
   5.738 -        finger->last_x = finger->x;
   5.739 -        finger->last_y = finger->y;
   5.740 -        finger->last_pressure = finger->pressure;
   5.741 -        return posted;
   5.742 -    }
   5.743 -}
   5.744 -
   5.745 -int
   5.746 -SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button)
   5.747 -{
   5.748 -    SDL_Touch *touch;
   5.749 -    int posted;
   5.750 -    Uint32 type;
   5.751 -
   5.752 -    
   5.753 -    touch = SDL_GetTouch(id);
   5.754 -    if (!touch) {
   5.755 -      return SDL_TouchNotFoundError(id);
   5.756 -    }
   5.757 -
   5.758 -    /* Figure out which event to perform */
   5.759 -    switch (state) {
   5.760 -    case SDL_PRESSED:
   5.761 -        if (touch->buttonstate & SDL_BUTTON(button)) {
   5.762 -            /* Ignore this event, no state change */
   5.763 -            return 0;
   5.764 -        }
   5.765 -        type = SDL_TOUCHBUTTONDOWN;
   5.766 -        touch->buttonstate |= SDL_BUTTON(button);
   5.767 -        break;
   5.768 -    case SDL_RELEASED:
   5.769 -        if (!(touch->buttonstate & SDL_BUTTON(button))) {
   5.770 -            /* Ignore this event, no state change */
   5.771 -            return 0;
   5.772 -        }
   5.773 -        type = SDL_TOUCHBUTTONUP;
   5.774 -        touch->buttonstate &= ~SDL_BUTTON(button);
   5.775 -        break;
   5.776 -    default:
   5.777 -        /* Invalid state -- bail */
   5.778 -        return 0;
   5.779 -    }
   5.780 -
   5.781 -    /* Post the event, if desired */
   5.782 -    posted = 0;
   5.783 -    if (SDL_GetEventState(type) == SDL_ENABLE) {
   5.784 -        SDL_Event event;
   5.785 -        event.type = type;
   5.786 -        event.tbutton.touchId = touch->id;
   5.787 -        event.tbutton.state = state;
   5.788 -        event.tbutton.button = button;
   5.789 -        event.tbutton.windowID = touch->focus ? touch->focus->id : 0;
   5.790 -        posted = (SDL_PushEvent(&event) > 0);
   5.791 -    }
   5.792 -    return posted;
   5.793 -}
   5.794 -
   5.795 -char *
   5.796 -SDL_GetTouchName(SDL_TouchID id)
   5.797 -{
   5.798 -    SDL_Touch *touch = SDL_GetTouch(id);
   5.799 -    if (!touch) {
   5.800 -        return NULL;
   5.801 -    }
   5.802 -    return touch->name;
   5.803 -}
   5.804 -
   5.805 -int SDL_TouchNotFoundError(SDL_TouchID id) {
   5.806 -  //int i;
   5.807 -  SDL_SetError("ERROR: Cannot send touch on non-existent device with id: %li make sure SDL_AddTouch has been called\n",id);
   5.808 -#if 0
   5.809 -  printf("ERROR: There are %i touches installed with Id's:\n",SDL_num_touch);
   5.810 -  for(i=0;i < SDL_num_touch;i++) {
   5.811 -    printf("ERROR: %li\n",SDL_touchPads[i]->id);
   5.812 -  }
   5.813 -#endif
   5.814 -  return 0;
   5.815 -}
   5.816  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/events/SDL_touch_c.h	Sat Mar 02 20:44:16 2013 -0800
     6.2 +++ b/src/events/SDL_touch_c.h	Sun Mar 03 01:01:33 2013 -0800
     6.3 @@ -24,55 +24,38 @@
     6.4  #ifndef _SDL_touch_c_h
     6.5  #define _SDL_touch_c_h
     6.6  
     6.7 +typedef struct SDL_Touch
     6.8 +{
     6.9 +    SDL_TouchID id;
    6.10 +    int num_fingers;
    6.11 +    int max_fingers;
    6.12 +    SDL_Finger** fingers;
    6.13 +} SDL_Touch;
    6.14  
    6.15  
    6.16  /* Initialize the touch subsystem */
    6.17  extern int SDL_TouchInit(void);
    6.18  
    6.19 -/*Get the touch at an index */
    6.20 -extern SDL_Touch *SDL_GetTouchIndex(int index);
    6.21 -
    6.22 -/* Get the touch with id = id */
    6.23 +/* Add a touch, returning the index of the touch, or -1 if there was an error. */
    6.24 +extern int SDL_AddTouch(SDL_TouchID id, const char *name);
    6.25 +                     
    6.26 +/* Get the touch with a given id */
    6.27  extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
    6.28  
    6.29 -/*Get the finger at an index */
    6.30 -extern SDL_Finger *SDL_GetFingerIndex(SDL_Touch *touch, int index);
    6.31 -
    6.32 -/* Get the finger with id = id */
    6.33 -extern SDL_Finger *SDL_GetFinger(SDL_Touch *touch,SDL_FingerID id);
    6.34 -
    6.35 -
    6.36 -/* Add a touch, possibly reattaching at a particular index (or -1),
    6.37 -   returning the index of the touch, or -1 if there was an error. */
    6.38 -extern int SDL_AddTouch(const SDL_Touch * touch, char *name);
    6.39 -                     
    6.40 -
    6.41 -/* Remove a touch at an index, clearing the slot for later */
    6.42 -extern void SDL_DelTouch(SDL_TouchID id);
    6.43 -
    6.44 -/* Set the touch focus window */
    6.45 -extern void SDL_SetTouchFocus(SDL_TouchID id, SDL_Window * window);
    6.46 +/* Send a touch down/up event for a touch */
    6.47 +extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, 
    6.48 +			             SDL_bool down, float x, float y, float pressure);
    6.49  
    6.50  /* Send a touch motion event for a touch */
    6.51  extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
    6.52 -			       int relative, float x, float y, float z);
    6.53 +			                   float x, float y, float pressure);
    6.54  
    6.55 -/* Send a touch down/up event for a touch */
    6.56 -extern int SDL_SendFingerDown(SDL_TouchID id, SDL_FingerID fingerid, 
    6.57 -			      SDL_bool down, float x, float y, float pressure);
    6.58 -
    6.59 -/* Send a touch button event for a touch */
    6.60 -extern int SDL_SendTouchButton(SDL_TouchID id, Uint8 state, Uint8 button);
    6.61 +/* Remove a touch */
    6.62 +extern void SDL_DelTouch(SDL_TouchID id);
    6.63  
    6.64  /* Shutdown the touch subsystem */
    6.65  extern void SDL_TouchQuit(void);
    6.66  
    6.67 -/* Get the index of a touch device */
    6.68 -extern int SDL_GetTouchIndexId(SDL_TouchID id);
    6.69 -
    6.70 -/* Print a debug message for a nonexistent touch */
    6.71 -extern int SDL_TouchNotFoundError(SDL_TouchID id);
    6.72 -
    6.73  #endif /* _SDL_touch_c_h */
    6.74  
    6.75  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/android/SDL_androidtouch.c	Sat Mar 02 20:44:16 2013 -0800
     7.2 +++ b/src/video/android/SDL_androidtouch.c	Sun Mar 03 01:01:33 2013 -0800
     7.3 @@ -64,19 +64,7 @@
     7.4  
     7.5      touchDeviceId = (SDL_TouchID)touch_device_id_in;
     7.6      if (!SDL_GetTouch(touchDeviceId)) {
     7.7 -        SDL_Touch touch;
     7.8 -        memset( &touch, 0, sizeof(touch) );
     7.9 -        touch.id = touchDeviceId;
    7.10 -        touch.x_min = 0.0f;
    7.11 -        touch.x_max = 1.0f;
    7.12 -        touch.native_xres = touch.x_max - touch.x_min;
    7.13 -        touch.y_min = 0.0f;
    7.14 -        touch.y_max = 1.0f;
    7.15 -        touch.native_yres = touch.y_max - touch.y_min;
    7.16 -        touch.pressure_min = 0.0f;
    7.17 -        touch.pressure_max = 1.0f;
    7.18 -        touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    7.19 -        if (SDL_AddTouch(&touch, "") < 0) {
    7.20 +        if (SDL_AddTouch(touchDeviceId, "") < 0) {
    7.21               SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
    7.22          }
    7.23      }
    7.24 @@ -96,7 +84,7 @@
    7.25  
    7.26                  leftFingerDown = fingerId;
    7.27              }
    7.28 -            SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
    7.29 +            SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
    7.30              break;
    7.31          case ACTION_MOVE:
    7.32              if (!leftFingerDown) {
    7.33 @@ -105,7 +93,7 @@
    7.34                  /* send moved event */
    7.35                  SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
    7.36              }
    7.37 -            SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
    7.38 +            SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
    7.39              break;
    7.40          case ACTION_UP:
    7.41          case ACTION_POINTER_1_UP:
    7.42 @@ -114,7 +102,7 @@
    7.43                  SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    7.44                  leftFingerDown = 0;
    7.45              }
    7.46 -            SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
    7.47 +            SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
    7.48              break;
    7.49          default:
    7.50              break;
     8.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Mar 02 20:44:16 2013 -0800
     8.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Mar 03 01:01:33 2013 -0800
     8.3 @@ -408,27 +408,14 @@
     8.4      enumerator = [touches objectEnumerator];
     8.5      touch = (NSTouch*)[enumerator nextObject];
     8.6      while (touch) {
     8.7 -        const SDL_TouchID touchId = (SDL_TouchID) ((size_t) [touch device]);
     8.8 +        const SDL_TouchID touchId = (SDL_TouchID)[touch device];
     8.9          if (!SDL_GetTouch(touchId)) {
    8.10 -            SDL_Touch touch;
    8.11 -
    8.12 -            touch.id = touchId;
    8.13 -            touch.x_min = 0;
    8.14 -            touch.x_max = 1;
    8.15 -            touch.native_xres = touch.x_max - touch.x_min;
    8.16 -            touch.y_min = 0;
    8.17 -            touch.y_max = 1;
    8.18 -            touch.native_yres = touch.y_max - touch.y_min;
    8.19 -            touch.pressure_min = 0;
    8.20 -            touch.pressure_max = 1;
    8.21 -            touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    8.22 -            
    8.23 -            if (SDL_AddTouch(&touch, "") < 0) {
    8.24 +            if (SDL_AddTouch(touchId, "") < 0) {
    8.25                  return;
    8.26              }
    8.27          } 
    8.28  
    8.29 -        const SDL_FingerID fingerId = (SDL_FingerID) ((size_t) [touch identity]);
    8.30 +        const SDL_FingerID fingerId = (SDL_FingerID)[touch identity];
    8.31          float x = [touch normalizedPosition].x;
    8.32          float y = [touch normalizedPosition].y;
    8.33          /* Make the origin the upper left instead of the lower left */
    8.34 @@ -436,17 +423,17 @@
    8.35  
    8.36          switch (type) {
    8.37          case COCOA_TOUCH_DOWN:
    8.38 -            SDL_SendFingerDown(touchId, fingerId, SDL_TRUE, x, y, 1);
    8.39 +            SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
    8.40              break;
    8.41          case COCOA_TOUCH_UP:
    8.42          case COCOA_TOUCH_CANCELLED:
    8.43 -            SDL_SendFingerDown(touchId, fingerId, SDL_FALSE, x, y, 1);
    8.44 +            SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
    8.45              break;
    8.46          case COCOA_TOUCH_MOVE:
    8.47 -            SDL_SendTouchMotion(touchId, fingerId, SDL_FALSE, x, y, 1);
    8.48 +            SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
    8.49              break;
    8.50          }
    8.51 -        
    8.52 +
    8.53          touch = (NSTouch*)[enumerator nextObject];
    8.54      }
    8.55  #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 */
     9.1 --- a/src/video/uikit/SDL_uikitview.m	Sat Mar 02 20:44:16 2013 -0800
     9.2 +++ b/src/video/uikit/SDL_uikitview.m	Sun Mar 03 01:01:33 2013 -0800
     9.3 @@ -52,23 +52,8 @@
     9.4  
     9.5      self.multipleTouchEnabled = YES;
     9.6  
     9.7 -    SDL_Touch touch;
     9.8 -    touch.id = 0; //TODO: Should be -1?
     9.9 -
    9.10 -    //touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    9.11 -    //EventTouchData* data = (EventTouchData*)(touch.driverdata);
    9.12 -
    9.13 -    touch.x_min = 0;
    9.14 -    touch.x_max = 1;
    9.15 -    touch.native_xres = touch.x_max - touch.x_min;
    9.16 -    touch.y_min = 0;
    9.17 -    touch.y_max = 1;
    9.18 -    touch.native_yres = touch.y_max - touch.y_min;
    9.19 -    touch.pressure_min = 0;
    9.20 -    touch.pressure_max = 1;
    9.21 -    touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    9.22 -
    9.23 -    touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    9.24 +    touchId = 1;
    9.25 +    SDL_AddTouch(touchId, "");
    9.26  
    9.27      return self;
    9.28  
    9.29 @@ -117,17 +102,15 @@
    9.30          // FIXME: TODO: Using touch as the fingerId is potentially dangerous
    9.31          // It is also much more efficient than storing the UITouch pointer
    9.32          // and comparing it to the incoming event.
    9.33 -        SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
    9.34 -                           SDL_TRUE, locationInView.x, locationInView.y,
    9.35 -                           1);
    9.36 +        SDL_SendTouch(touchId, (SDL_FingerID)touch,
    9.37 +                      SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
    9.38  #else
    9.39          int i;
    9.40          for(i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    9.41              if (finger[i] == NULL) {
    9.42                  finger[i] = touch;
    9.43 -                SDL_SendFingerDown(touchId, i,
    9.44 -                                   SDL_TRUE, locationInView.x, locationInView.y,
    9.45 -                                   1);
    9.46 +                SDL_SendTouch(touchId, i,
    9.47 +                              SDL_TRUE, locationInView.x, locationInView.y, 1.0f);
    9.48                  break;
    9.49              }
    9.50          }
    9.51 @@ -150,16 +133,14 @@
    9.52  
    9.53          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    9.54  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    9.55 -        SDL_SendFingerDown(touchId, (long)touch,
    9.56 -                           SDL_FALSE, locationInView.x, locationInView.y,
    9.57 -                           1);
    9.58 +        SDL_SendTouch(touchId, (long)touch,
    9.59 +                      SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
    9.60  #else
    9.61          int i;
    9.62          for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    9.63              if (finger[i] == touch) {
    9.64 -                SDL_SendFingerDown(touchId, i,
    9.65 -                                   SDL_FALSE, locationInView.x, locationInView.y,
    9.66 -                                   1);
    9.67 +                SDL_SendTouch(touchId, i,
    9.68 +                              SDL_FALSE, locationInView.x, locationInView.y, 1.0f);
    9.69                  finger[i] = NULL;
    9.70                  break;
    9.71              }
    9.72 @@ -195,15 +176,13 @@
    9.73          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    9.74  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    9.75          SDL_SendTouchMotion(touchId, (long)touch,
    9.76 -                            SDL_FALSE, locationInView.x, locationInView.y,
    9.77 -                            1);
    9.78 +                            locationInView.x, locationInView.y, 1.0f);
    9.79  #else
    9.80          int i;
    9.81          for (i = 0; i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    9.82              if (finger[i] == touch) {
    9.83                  SDL_SendTouchMotion(touchId, i,
    9.84 -                                    SDL_FALSE, locationInView.x, locationInView.y,
    9.85 -                                    1);
    9.86 +                                    locationInView.x, locationInView.y, 1.0f);
    9.87                  break;
    9.88              }
    9.89          }
    10.1 --- a/src/video/windows/SDL_windowsevents.c	Sat Mar 02 20:44:16 2013 -0800
    10.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Mar 03 01:01:33 2013 -0800
    10.3 @@ -691,23 +691,9 @@
    10.4  				for (i = 0; i < num_inputs; ++i) {
    10.5  					PTOUCHINPUT input = &inputs[i];
    10.6  
    10.7 -					const SDL_TouchID touchId = (SDL_TouchID)
    10.8 -												((size_t)input->hSource);
    10.9 +					const SDL_TouchID touchId = (SDL_TouchID)input->hSource;
   10.10  					if (!SDL_GetTouch(touchId)) {
   10.11 -						SDL_Touch touch;
   10.12 -
   10.13 -						touch.id = touchId;
   10.14 -						touch.x_min = 0;
   10.15 -						touch.x_max = 1;
   10.16 -						touch.native_xres = touch.x_max - touch.x_min;
   10.17 -						touch.y_min = 0;
   10.18 -						touch.y_max = 1;
   10.19 -						touch.native_yres = touch.y_max - touch.y_min;
   10.20 -						touch.pressure_min = 0;
   10.21 -						touch.pressure_max = 1;
   10.22 -						touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   10.23 -
   10.24 -						if (SDL_AddTouch(&touch, "") < 0) {
   10.25 +						if (SDL_AddTouch(touchId, "") < 0) {
   10.26  							continue;
   10.27  						}
   10.28  					}
   10.29 @@ -717,13 +703,13 @@
   10.30  					y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
   10.31  
   10.32  					if (input->dwFlags & TOUCHEVENTF_DOWN) {
   10.33 -						SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
   10.34 +						SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f);
   10.35  					}
   10.36  					if (input->dwFlags & TOUCHEVENTF_MOVE) {
   10.37 -						SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
   10.38 +						SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f);
   10.39  					}
   10.40  					if (input->dwFlags & TOUCHEVENTF_UP) {
   10.41 -						SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
   10.42 +						SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f);
   10.43  					}
   10.44  				}
   10.45  			}
    11.1 --- a/src/video/x11/SDL_x11events.c	Sat Mar 02 20:44:16 2013 -0800
    11.2 +++ b/src/video/x11/SDL_x11events.c	Sun Mar 03 01:01:33 2013 -0800
    11.3 @@ -41,12 +41,6 @@
    11.4  
    11.5  #include <stdio.h>
    11.6  
    11.7 -#ifdef SDL_INPUT_LINUXEV
    11.8 -/* Touch Input/event* includes */
    11.9 -#include <linux/input.h>
   11.10 -#include <fcntl.h>
   11.11 -#endif
   11.12 -
   11.13  /*#define DEBUG_XEVENTS*/
   11.14  
   11.15  /* Check to see if this is a repeated key.
   11.16 @@ -703,90 +697,6 @@
   11.17  
   11.18      /* FIXME: Only need to do this when there are pending focus changes */
   11.19      X11_HandleFocusChanges(_this);
   11.20 -
   11.21 -    /*Dont process evtouch events if XInput2 multitouch is supported*/
   11.22 -    if(X11_Xinput2IsMultitouchSupported()) {
   11.23 -        return;
   11.24 -    }
   11.25 -
   11.26 -#ifdef SDL_INPUT_LINUXEV
   11.27 -    /* Process Touch events*/
   11.28 -    int i = 0,rd;
   11.29 -    struct input_event ev[64];
   11.30 -    int size = sizeof (struct input_event);
   11.31 -
   11.32 -/* !!! FIXME: clean the tabstops out of here. */
   11.33 -    for(i = 0;i < SDL_GetNumTouch();++i) {
   11.34 -	SDL_Touch* touch = SDL_GetTouchIndex(i);
   11.35 -	if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
   11.36 -	EventTouchData* data;
   11.37 -	data = (EventTouchData*)(touch->driverdata);
   11.38 -	if(data == NULL) {
   11.39 -	  printf("No driver data\n");
   11.40 -	  continue;
   11.41 -	}
   11.42 -	if(data->eventStream <= 0) 
   11.43 -	    printf("Error: Couldn't open stream\n");
   11.44 -	rd = read(data->eventStream, ev, size * 64);
   11.45 -	if(rd >= size) {
   11.46 -	    for (i = 0; i < rd / sizeof(struct input_event); i++) {
   11.47 -		switch (ev[i].type) {
   11.48 -		case EV_ABS:
   11.49 -		    switch (ev[i].code) {
   11.50 -			case ABS_X:
   11.51 -			    data->x = ev[i].value;
   11.52 -			    break;
   11.53 -			case ABS_Y:
   11.54 -			    data->y = ev[i].value;
   11.55 -			    break;
   11.56 -			case ABS_PRESSURE:
   11.57 -			    data->pressure = ev[i].value;
   11.58 -			    if(data->pressure < 0) data->pressure = 0;
   11.59 -			    break;
   11.60 -			case ABS_MISC:
   11.61 -			    if(ev[i].value == 0)
   11.62 -			        data->up = SDL_TRUE;			    
   11.63 -			    break;
   11.64 -			}
   11.65 -		    break;
   11.66 -		case EV_MSC:
   11.67 -			if(ev[i].code == MSC_SERIAL)
   11.68 -				data->finger = ev[i].value;
   11.69 -			break;
   11.70 -		case EV_KEY:
   11.71 -			if(ev[i].code == BTN_TOUCH)
   11.72 -			    if(ev[i].value == 0)
   11.73 -			        data->up = SDL_TRUE;
   11.74 -			break;
   11.75 -		case EV_SYN:
   11.76 -		  if(!data->down) {
   11.77 -		      data->down = SDL_TRUE;
   11.78 -		      SDL_SendFingerDown(touch->id,data->finger,
   11.79 -		    		  data->down, data->x, data->y,
   11.80 -		    		  data->pressure);
   11.81 -		  }
   11.82 -		  else if(!data->up)
   11.83 -		    SDL_SendTouchMotion(touch->id,data->finger, 
   11.84 -					SDL_FALSE, data->x,data->y,
   11.85 -					data->pressure);
   11.86 -		  else
   11.87 -		  {
   11.88 -		      data->down = SDL_FALSE;
   11.89 -			  SDL_SendFingerDown(touch->id,data->finger,
   11.90 -					  data->down, data->x,data->y,
   11.91 -					  data->pressure);
   11.92 -			  data->x = -1;
   11.93 -			  data->y = -1;
   11.94 -			  data->pressure = -1;
   11.95 -			  data->finger = 0;
   11.96 -			  data->up = SDL_FALSE;
   11.97 -		  }
   11.98 -		  break;		
   11.99 -		}
  11.100 -	    }
  11.101 -	}
  11.102 -    }
  11.103 -#endif
  11.104  }
  11.105  
  11.106  
    12.1 --- a/src/video/x11/SDL_x11touch.c	Sat Mar 02 20:44:16 2013 -0800
    12.2 +++ b/src/video/x11/SDL_x11touch.c	Sun Mar 03 01:01:33 2013 -0800
    12.3 @@ -28,97 +28,12 @@
    12.4  #include "../../events/SDL_touch_c.h"
    12.5  
    12.6  
    12.7 -#ifdef SDL_INPUT_LINUXEV
    12.8 -#include <linux/input.h>
    12.9 -#include <fcntl.h>
   12.10 -#endif
   12.11 -
   12.12  void
   12.13  X11_InitTouch(_THIS)
   12.14  {
   12.15 -    /*Initilized Xinput2 multitouch 
   12.16 -    * and return in order to not initialize
   12.17 -    * evtouch also*/
   12.18 -    if(X11_Xinput2IsMultitouchSupported()) {
   12.19 +    if (X11_Xinput2IsMultitouchSupported()) {
   12.20          X11_InitXinput2Multitouch(_this);
   12.21 -        return;
   12.22      }
   12.23 -#ifdef SDL_INPUT_LINUXEV
   12.24 -    FILE *fd;
   12.25 -    fd = fopen("/proc/bus/input/devices","r");
   12.26 -    if (!fd) return;
   12.27 -
   12.28 -    int i = 0;
   12.29 -    int tsfd;
   12.30 -    char line[256];
   12.31 -    char tstr[256];
   12.32 -    int vendor = -1,product = -1,event = -1;
   12.33 -    while(!feof(fd)) {
   12.34 -        if(fgets(line,256,fd) <=0) continue;
   12.35 -        if(line[0] == '\n') {
   12.36 -            if(vendor == 1386 || vendor==1) {
   12.37 -                sprintf(tstr,"/dev/input/event%i",event);
   12.38 -
   12.39 -                tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
   12.40 -                if ( tsfd == -1 )
   12.41 -                    continue;   /* Maybe not enough permissions ? */
   12.42 -
   12.43 -                SDL_Touch touch;
   12.44 -                touch.pressure_max = 0;
   12.45 -                touch.pressure_min = 0;
   12.46 -                touch.id = event; 
   12.47 -
   12.48 -                touch.driverdata = SDL_malloc(sizeof(EventTouchData));
   12.49 -                EventTouchData* data = (EventTouchData*)(touch.driverdata);
   12.50 -
   12.51 -                data->x = -1;
   12.52 -                data->y = -1;
   12.53 -                data->pressure = -1;
   12.54 -                data->finger = 0;
   12.55 -                data->up = SDL_FALSE;
   12.56 -                data->down = SDL_FALSE;
   12.57 -
   12.58 -                data->eventStream = tsfd;
   12.59 -                ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
   12.60 -
   12.61 -                int abs[5];
   12.62 -                ioctl(data->eventStream,EVIOCGABS(0),abs);	
   12.63 -                touch.x_min = abs[1];
   12.64 -                touch.x_max = abs[2];
   12.65 -                touch.native_xres = touch.x_max - touch.x_min;
   12.66 -                ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
   12.67 -                touch.y_min = abs[1];
   12.68 -                touch.y_max = abs[2];
   12.69 -                touch.native_yres = touch.y_max - touch.y_min;
   12.70 -                ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
   12.71 -                touch.pressure_min = abs[1];
   12.72 -                touch.pressure_max = abs[2];
   12.73 -                touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   12.74 -
   12.75 -                SDL_AddTouch(&touch, tstr);
   12.76 -            }
   12.77 -            vendor = -1;
   12.78 -            product = -1;
   12.79 -            event = -1;      
   12.80 -        }
   12.81 -        else if(line[0] == 'I') {
   12.82 -            i = 1;
   12.83 -            while(line[i]) {
   12.84 -                sscanf(&line[i],"Vendor=%x",&vendor);
   12.85 -                sscanf(&line[i],"Product=%x",&product);
   12.86 -                i++;
   12.87 -            }
   12.88 -        }
   12.89 -        else if(line[0] == 'H') {
   12.90 -            i = 1;
   12.91 -            while(line[i]) {
   12.92 -                sscanf(&line[i],"event%d",&event);
   12.93 -                i++;
   12.94 -            }
   12.95 -        }
   12.96 -    }
   12.97 -    fclose(fd);
   12.98 -#endif
   12.99  }
  12.100  
  12.101  void
    13.1 --- a/src/video/x11/SDL_x11touch.h	Sat Mar 02 20:44:16 2013 -0800
    13.2 +++ b/src/video/x11/SDL_x11touch.h	Sun Mar 03 01:01:33 2013 -0800
    13.3 @@ -23,16 +23,6 @@
    13.4  #ifndef _SDL_x11touch_h
    13.5  #define _SDL_x11touch_h
    13.6  
    13.7 -#ifdef SDL_INPUT_LINUXEV
    13.8 -typedef struct EventTouchData
    13.9 -{
   13.10 -    int x,y,pressure,finger; /* Temporary Variables until sync */
   13.11 -    int eventStream;
   13.12 -    SDL_bool up;
   13.13 -    SDL_bool down;
   13.14 -} EventTouchData;
   13.15 -#endif
   13.16 -
   13.17  extern void X11_InitTouch(_THIS);
   13.18  extern void X11_QuitTouch(_THIS);
   13.19  
    14.1 --- a/src/video/x11/SDL_x11xinput2.c	Sat Mar 02 20:44:16 2013 -0800
    14.2 +++ b/src/video/x11/SDL_x11xinput2.c	Sun Mar 03 01:01:33 2013 -0800
    14.3 @@ -121,8 +121,6 @@
    14.4  #endif
    14.5  }
    14.6  
    14.7 -
    14.8 -
    14.9  int 
   14.10  X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
   14.11  {
   14.12 @@ -149,25 +147,22 @@
   14.13  #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
   14.14          case XI_TouchBegin: {
   14.15              const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   14.16 -            SDL_SendFingerDown(xev->sourceid,xev->detail,
   14.17 -                      SDL_TRUE, (int)xev->event_x, (int)xev->event_y,
   14.18 -		    		  1.0);
   14.19 +            SDL_SendTouch(xev->sourceid,xev->detail,
   14.20 +                      SDL_TRUE, xev->event_x, xev->event_y, 1.0);
   14.21              return 1;
   14.22              }
   14.23              break;
   14.24          case XI_TouchEnd: {
   14.25              const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   14.26 -            SDL_SendFingerDown(xev->sourceid,xev->detail,
   14.27 -                      SDL_FALSE, (int)xev->event_x, (int)xev->event_y,
   14.28 -		    		  1.0);
   14.29 +            SDL_SendTouch(xev->sourceid,xev->detail,
   14.30 +                      SDL_FALSE, xev->event_x, xev->event_y, 1.0);
   14.31              return 1;
   14.32              }
   14.33              break;
   14.34          case XI_TouchUpdate: {
   14.35              const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   14.36              SDL_SendTouchMotion(xev->sourceid,xev->detail,
   14.37 -                      SDL_FALSE, (int)xev->event_x, (int)xev->event_y,
   14.38 -		    		  1.0);
   14.39 +                                xev->event_x, xev->event_y, 1.0);
   14.40              return 1;
   14.41              }
   14.42              break;
   14.43 @@ -198,22 +193,8 @@
   14.44                  continue;
   14.45  
   14.46              touchId = t->sourceid;
   14.47 -            /*Add the touch*/
   14.48              if (!SDL_GetTouch(touchId)) {
   14.49 -                SDL_Touch touch;
   14.50 -
   14.51 -                touch.id = touchId;
   14.52 -                touch.x_min = 0;
   14.53 -                touch.x_max = 1;
   14.54 -                touch.native_xres = touch.x_max - touch.x_min;
   14.55 -                touch.y_min = 0;
   14.56 -                touch.y_max = 1;
   14.57 -                touch.native_yres = touch.y_max - touch.y_min;
   14.58 -                touch.pressure_min = 0;
   14.59 -                touch.pressure_max = 1;
   14.60 -                touch.native_pressureres = touch.pressure_max - touch.pressure_min;
   14.61 -
   14.62 -                SDL_AddTouch(&touch,dev->name);
   14.63 +                SDL_AddTouch(touchId, dev->name);
   14.64              }
   14.65          }
   14.66      }
    15.1 --- a/test/testgesture.c	Sat Mar 02 20:44:16 2013 -0800
    15.2 +++ b/test/testgesture.c	Sun Mar 03 01:01:33 2013 -0800
    15.3 @@ -167,11 +167,8 @@
    15.4      if(event->type == SDL_FINGERMOTION || 
    15.5         event->type == SDL_FINGERDOWN ||
    15.6         event->type == SDL_FINGERUP) {
    15.7 -      SDL_Touch* inTouch = SDL_GetTouch(event->tfinger.touchId);
    15.8 -      if(inTouch == NULL) continue;
    15.9 -
   15.10 -      x = ((float)event->tfinger.x)/inTouch->xres;
   15.11 -      y = ((float)event->tfinger.y)/inTouch->yres;      
   15.12 +      x = event->tfinger.x;
   15.13 +      y = event->tfinger.y;
   15.14        
   15.15        //draw the touch:      
   15.16        c = colors[event->tfinger.fingerId%7]; 
   15.17 @@ -269,10 +266,6 @@
   15.18  	    SDL_Log("Finger: %i,x: %i, y: %i",event.tfinger.fingerId,
   15.19  	    	   event.tfinger.x,event.tfinger.y);
   15.20  #endif
   15.21 -		{
   15.22 -			SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
   15.23 -			SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
   15.24 -		}
   15.25  	    break;	    
   15.26  	  case SDL_FINGERDOWN:
   15.27  #if VERBOSE