Initial support for XInput2 by Dimitris Zenios
authorSam Lantinga <slouken@libsdl.org>
Wed, 30 May 2012 11:25:35 -0400
changeset 63114e5e46f43438
parent 6310 f830e73e2acf
child 6312 b3ae153ff088
Initial support for XInput2 by Dimitris Zenios

1.initial work on XInput2 support
2.Implemented relative mouse motion when XInput2 is enabled
3.Created a test app to test relative mouse motion
4.Fixed Bug #1498
configure.in
include/SDL_config.h.in
include/SDL_config_macosx.h
include/SDL_config_pandora.h
src/video/x11/SDL_x11dyn.c
src/video/x11/SDL_x11dyn.h
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11mouse.c
src/video/x11/SDL_x11mouse.h
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
test/Makefile.in
test/testrelative.c
     1.1 --- a/configure.in	Fri May 25 18:21:22 2012 -0400
     1.2 +++ b/configure.in	Wed May 30 11:25:35 2012 -0400
     1.3 @@ -1091,6 +1091,8 @@
     1.4              fi
     1.5              have_video=yes
     1.6  
     1.7 +            AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))
     1.8 +
     1.9              AC_ARG_ENABLE(video-x11-xcursor,
    1.10  AC_HELP_STRING([--enable-video-x11-xcursor], [enable X11 Xcursor support [[default=yes]]]),
    1.11                              , enable_video_x11_xcursor=yes)
    1.12 @@ -1150,7 +1152,7 @@
    1.13                              , enable_video_x11_xinput=yes)
    1.14              if test x$enable_video_x11_xinput = xyes; then
    1.15                  definitely_enable_video_x11_xinput=no
    1.16 -                AC_CHECK_HEADER(X11/extensions/XInput.h,
    1.17 +                AC_CHECK_HEADER(X11/extensions/XInput2.h,
    1.18                                  have_xinput_h_hdr=yes,
    1.19                                  have_xinput_h_hdr=no,
    1.20                                  [#include <X11/Xlib.h>
    1.21 @@ -1158,7 +1160,7 @@
    1.22                  if test x$have_xinput_h_hdr = xyes; then
    1.23                      if test x$enable_x11_shared = xyes && test x$xinput_lib != x ; then
    1.24                          echo "-- dynamic libXi -> $xinput_lib"
    1.25 -                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT, "$xinput_lib", [ ])
    1.26 +                        AC_DEFINE_UNQUOTED(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2, "$xinput_lib", [ ])
    1.27                          definitely_enable_video_x11_xinput=yes
    1.28                      else
    1.29                          AC_CHECK_LIB(Xi, XOpenDevice, have_xinput_lib=yes)
    1.30 @@ -1170,7 +1172,7 @@
    1.31                  fi
    1.32              fi
    1.33              if test x$definitely_enable_video_x11_xinput = xyes; then
    1.34 -                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT, 1, [ ])
    1.35 +                AC_DEFINE(SDL_VIDEO_DRIVER_X11_XINPUT2, 1, [ ])
    1.36              fi
    1.37              AC_ARG_ENABLE(video-x11-xrandr,
    1.38  AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for fullscreen [[default=yes]]]),
     2.1 --- a/include/SDL_config.h.in	Fri May 25 18:21:22 2012 -0400
     2.2 +++ b/include/SDL_config.h.in	Wed May 30 11:25:35 2012 -0400
     2.3 @@ -257,17 +257,18 @@
     2.4  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
     2.5  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
     2.6  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
     2.7 -#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
     2.8 +#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
     2.9  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    2.10  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
    2.11  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
    2.12  #undef SDL_VIDEO_DRIVER_X11_XCURSOR
    2.13  #undef SDL_VIDEO_DRIVER_X11_XINERAMA
    2.14 -#undef SDL_VIDEO_DRIVER_X11_XINPUT
    2.15 +#undef SDL_VIDEO_DRIVER_X11_XINPUT2
    2.16  #undef SDL_VIDEO_DRIVER_X11_XRANDR
    2.17  #undef SDL_VIDEO_DRIVER_X11_XSCRNSAVER
    2.18  #undef SDL_VIDEO_DRIVER_X11_XSHAPE
    2.19  #undef SDL_VIDEO_DRIVER_X11_XVIDMODE
    2.20 +#undef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
    2.21  
    2.22  #undef SDL_VIDEO_RENDER_D3D
    2.23  #undef SDL_VIDEO_RENDER_OGL
     3.1 --- a/include/SDL_config_macosx.h	Fri May 25 18:21:22 2012 -0400
     3.2 +++ b/include/SDL_config_macosx.h	Wed May 30 11:25:35 2012 -0400
     3.3 @@ -134,16 +134,17 @@
     3.4  #define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib"
     3.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib"
     3.6  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "/usr/X11R6/lib/libXinerama.1.dylib"
     3.7 -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT "/usr/X11R6/lib/libXi.6.dylib"
     3.8 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "/usr/X11R6/lib/libXi.6.dylib"
     3.9  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
    3.10  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
    3.11  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
    3.12  #define SDL_VIDEO_DRIVER_X11_XINERAMA 1
    3.13 -#define SDL_VIDEO_DRIVER_X11_XINPUT 1
    3.14 +#define SDL_VIDEO_DRIVER_X11_XINPUT2 1
    3.15  #define SDL_VIDEO_DRIVER_X11_XRANDR 1
    3.16  #define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
    3.17  #define SDL_VIDEO_DRIVER_X11_XSHAPE 1
    3.18  #define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
    3.19 +#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
    3.20  
    3.21  #ifndef SDL_VIDEO_RENDER_OGL
    3.22  #define SDL_VIDEO_RENDER_OGL	1
     4.1 --- a/include/SDL_config_pandora.h	Fri May 25 18:21:22 2012 -0400
     4.2 +++ b/include/SDL_config_pandora.h	Wed May 30 11:25:35 2012 -0400
     4.3 @@ -117,7 +117,6 @@
     4.4  
     4.5  #define SDL_VIDEO_DRIVER_DUMMY 1
     4.6  #define SDL_VIDEO_DRIVER_X11 1
     4.7 -#define SDL_VIDEO_DRIVER_X11_XINPUT 1
     4.8  #define SDL_VIDEO_DRIVER_PANDORA 1
     4.9  #define SDL_VIDEO_RENDER_OGL_ES 1
    4.10  #define SDL_VIDEO_OPENGL_ES 1
     5.1 --- a/src/video/x11/SDL_x11dyn.c	Fri May 25 18:21:22 2012 -0400
     5.2 +++ b/src/video/x11/SDL_x11dyn.c	Wed May 30 11:25:35 2012 -0400
     5.3 @@ -53,8 +53,8 @@
     5.4  #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
     5.5  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL
     5.6  #endif
     5.7 -#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT
     5.8 -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT NULL
     5.9 +#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
    5.10 +#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL
    5.11  #endif
    5.12  #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    5.13  #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
    5.14 @@ -71,7 +71,7 @@
    5.15      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
    5.16      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR},
    5.17      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA},
    5.18 -    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT},
    5.19 +    {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2},
    5.20      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
    5.21      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
    5.22      {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE}
     6.1 --- a/src/video/x11/SDL_x11dyn.h	Fri May 25 18:21:22 2012 -0400
     6.2 +++ b/src/video/x11/SDL_x11dyn.h	Wed May 30 11:25:35 2012 -0400
     6.3 @@ -49,8 +49,8 @@
     6.4  #if SDL_VIDEO_DRIVER_X11_XINERAMA
     6.5  #include <X11/extensions/Xinerama.h>
     6.6  #endif
     6.7 -#if SDL_VIDEO_DRIVER_X11_XINPUT
     6.8 -#include <X11/extensions/XInput.h>
     6.9 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
    6.10 +#include <X11/extensions/XInput2.h>
    6.11  #endif
    6.12  #if SDL_VIDEO_DRIVER_X11_XRANDR
    6.13  #include <X11/extensions/Xrandr.h>
     7.1 --- a/src/video/x11/SDL_x11events.c	Fri May 25 18:21:22 2012 -0400
     7.2 +++ b/src/video/x11/SDL_x11events.c	Wed May 30 11:25:35 2012 -0400
     7.3 @@ -44,7 +44,6 @@
     7.4  #include <linux/input.h>
     7.5  #include <fcntl.h>
     7.6  #endif
     7.7 -/*#define DEBUG_XEVENTS*/
     7.8  
     7.9  /* Check to see if this is a repeated key.
    7.10     (idea shamelessly lifted from GII -- thanks guys! :)
    7.11 @@ -95,6 +94,56 @@
    7.12      return SDL_FALSE;
    7.13  }
    7.14  
    7.15 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
    7.16 +static void X11_HandleRawMotion(SDL_VideoData *videodata,const XIRawEvent *rawev)
    7.17 +{
    7.18 +    SDL_Mouse *mouse = SDL_GetMouse();
    7.19 +    const double *values = rawev->raw_values;
    7.20 +    int relative_cords[2] = {0,0};
    7.21 +    int i;
    7.22 +
    7.23 +    if (!mouse->relative_mode) {
    7.24 +        return;
    7.25 +    }
    7.26 +   
    7.27 +    /*2 axis,X-Y*/
    7.28 +    for (i = 0; i < 2; i++) {
    7.29 +        if (XIMaskIsSet(rawev->valuators.mask, i)) {
    7.30 +            const int value = (int) *values;
    7.31 +            relative_cords[i] = value;
    7.32 +            values++;
    7.33 +        }
    7.34 +    }
    7.35 +#ifdef DEBUG_MOTION
    7.36 +    printf("XInput relative motion: %d,%d\n", relative_cords[0],relative_cords[1]);
    7.37 +#endif
    7.38 +    SDL_SendMouseMotion(mouse->focus,1,relative_cords[0],relative_cords[1]);
    7.39 +}
    7.40 +#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    7.41 +
    7.42 +#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
    7.43 +static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event)
    7.44 +{
    7.45 +    XGenericEventCookie *cookie = &event.xcookie;
    7.46 +    XGetEventData(videodata->display, cookie);
    7.47 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
    7.48 +    if(cookie->extension == videodata->xinput_opcode) {
    7.49 +        switch(cookie->evtype) {
    7.50 +            case XI_RawMotion: {
    7.51 +                const XIRawEvent *rawev = (const XIRawEvent*)cookie->data;
    7.52 +                X11_HandleRawMotion(videodata,rawev);
    7.53 +                }
    7.54 +                break;
    7.55 +
    7.56 +        }
    7.57 +    }
    7.58 +#endif
    7.59 +    XFreeEventData(videodata->display,cookie);
    7.60 +}
    7.61 +#endif /* SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
    7.62 +
    7.63 +
    7.64 +
    7.65  static void
    7.66  X11_DispatchEvent(_THIS)
    7.67  {
    7.68 @@ -127,6 +176,13 @@
    7.69          SDL_SendSysWMEvent(&wmmsg);
    7.70      }
    7.71  
    7.72 +#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
    7.73 +    if(xevent.type == GenericEvent) {
    7.74 +        X11_HandleGenericEvent(videodata,xevent);
    7.75 +        return;
    7.76 +    }
    7.77 +#endif
    7.78 +
    7.79      data = NULL;
    7.80      if (videodata && videodata->windowlist) {
    7.81          for (i = 0; i < videodata->numwindows; ++i) {
    7.82 @@ -337,10 +393,14 @@
    7.83          break;
    7.84  
    7.85      case MotionNotify:{
    7.86 +            SDL_Mouse *mouse = SDL_GetMouse();  
    7.87 +            if(!mouse->relative_mode) {
    7.88  #ifdef DEBUG_MOTION
    7.89 -            printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    7.90 +                printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
    7.91  #endif
    7.92 -            SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
    7.93 +
    7.94 +                SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
    7.95 +            }
    7.96          }
    7.97          break;
    7.98  
     8.1 --- a/src/video/x11/SDL_x11mouse.c	Fri May 25 18:21:22 2012 -0400
     8.2 +++ b/src/video/x11/SDL_x11mouse.c	Wed May 30 11:25:35 2012 -0400
     8.3 @@ -272,8 +272,13 @@
     8.4  static int
     8.5  X11_SetRelativeMouseMode(SDL_bool enabled)
     8.6  {
     8.7 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
     8.8 +    /* FIXME: Need to remember from init if XInput2 is actually supported */
     8.9 +    return 0;
    8.10 +#else
    8.11      SDL_Unsupported();
    8.12      return -1;
    8.13 +#endif
    8.14  }
    8.15  
    8.16  void
     9.1 --- a/src/video/x11/SDL_x11mouse.h	Fri May 25 18:21:22 2012 -0400
     9.2 +++ b/src/video/x11/SDL_x11mouse.h	Wed May 30 11:25:35 2012 -0400
     9.3 @@ -23,21 +23,6 @@
     9.4  #ifndef _SDL_x11mouse_h
     9.5  #define _SDL_x11mouse_h
     9.6  
     9.7 -#if SDL_VIDEO_DRIVER_X11_XINPUT
     9.8 -typedef struct X11_MouseData
     9.9 -{
    9.10 -    Display *display;
    9.11 -    XDevice *device;
    9.12 -    int motion;
    9.13 -    int button_pressed;
    9.14 -    int button_released;
    9.15 -    int proximity_in;
    9.16 -    int proximity_out;
    9.17 -    int num_xevents;
    9.18 -    XEventClass xevents[5];
    9.19 -} X11_MouseData;
    9.20 -#endif
    9.21 -
    9.22  extern void X11_InitMouse(_THIS);
    9.23  extern void X11_QuitMouse(_THIS);
    9.24  
    10.1 --- a/src/video/x11/SDL_x11sym.h	Fri May 25 18:21:22 2012 -0400
    10.2 +++ b/src/video/x11/SDL_x11sym.h	Wed May 30 11:25:35 2012 -0400
    10.3 @@ -103,7 +103,7 @@
    10.4  SDL_X11_SYM(int,XUnmapWindow,(Display* a,Window b),(a,b),return)
    10.5  SDL_X11_SYM(int,XWarpPointer,(Display* a,Window b,Window c,int d,int e,unsigned int f,unsigned int g,int h,int i),(a,b,c,d,e,f,g,h,i),return)
    10.6  SDL_X11_SYM(VisualID,XVisualIDFromVisual,(Visual* a),(a),return)
    10.7 -SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo* a,Display* b,char* c,XExtensionHooks* d,int e,XPointer f),(a,b,c,d,e,f),return)
    10.8 +SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f),(a,b,c,d,e,f),return)
    10.9  SDL_X11_SYM(XExtensionInfo*,XextCreateExtension,(void),(),return)
   10.10  SDL_X11_SYM(void,XextDestroyExtension,(XExtensionInfo* a),(a),)
   10.11  SDL_X11_SYM(XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo* a,Display* b),(a,b),return)
   10.12 @@ -123,6 +123,11 @@
   10.13  SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
   10.14  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
   10.15  
   10.16 +#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
   10.17 +SDL_X11_SYM(Bool,XGetEventData,(Display* a,XGenericEventCookie* b),(a,b),return)
   10.18 +SDL_X11_SYM(void,XFreeEventData,(Display* a,XGenericEventCookie* b),(a,b),)    
   10.19 +#endif
   10.20 +
   10.21  #if NeedWidePrototypes
   10.22  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
   10.23  #else
   10.24 @@ -190,14 +195,14 @@
   10.25  SDL_X11_SYM(XineramaScreenInfo*,XineramaQueryScreens,(Display *a, int *b),(a,b),return)
   10.26  #endif
   10.27  
   10.28 -/* XInput support for multiple mice, tablets, etc. */
   10.29 -#if SDL_VIDEO_DRIVER_X11_XINPUT
   10.30 -SDL_X11_MODULE(XINPUT)
   10.31 -SDL_X11_SYM(XDeviceInfo*,XListInputDevices,(Display *a,int *b),(a,b),return)
   10.32 -SDL_X11_SYM(void,XFreeDeviceList,(XDeviceInfo *a),(a),)
   10.33 -SDL_X11_SYM(int,XSelectExtensionEvent,(Display *a,Window b,XEventClass *c,int d),(a,b,c,d),return)
   10.34 -SDL_X11_SYM(XDevice*,XOpenDevice,(Display *a,XID b),(a,b),return)
   10.35 -SDL_X11_SYM(int,XCloseDevice,(Display* a,XDevice* b),(a,b),return)
   10.36 +/* XInput2 support for multiple mice, tablets, etc. */
   10.37 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
   10.38 +SDL_X11_MODULE(XINPUT2)
   10.39 +SDL_X11_SYM(XIDeviceInfo*,XIQueryDevice,(Display *a,int b,int *c),(a,b,c),return)
   10.40 +SDL_X11_SYM(void,XIFreeDeviceInfo,(XIDeviceInfo *a),(a),)
   10.41 +SDL_X11_SYM(int,XISelectEvents,(Display *a,Window b,XIEventMask *c,int d),(a,b,c,d),return)
   10.42 +SDL_X11_SYM(Status,XIQueryVersion,(Display *a,int *b,int *c),(a,b,c),return)
   10.43 +SDL_X11_SYM(XIEventMask*,XIGetSelectedEvents,(Display *a,Window b,int *c),(a,b,c),return)
   10.44  #endif
   10.45  
   10.46  /* XRandR support */
    11.1 --- a/src/video/x11/SDL_x11video.c	Fri May 25 18:21:22 2012 -0400
    11.2 +++ b/src/video/x11/SDL_x11video.c	Wed May 30 11:25:35 2012 -0400
    11.3 @@ -321,6 +321,54 @@
    11.4  }
    11.5  
    11.6  int
    11.7 +X11_CheckXInput2(_THIS)
    11.8 +{
    11.9 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
   11.10 +    if (SDL_X11_HAVE_XINPUT2) {
   11.11 +        XIEventMask eventmask;
   11.12 +        unsigned char mask[3] = { 0,0,0 };
   11.13 +        int opcode, event, err;
   11.14 +        int major = 2, minor = 0;
   11.15 +        /*
   11.16 +        * Initialize XInput 2
   11.17 +        * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
   11.18 +        * to inform Xserver what version of Xinput we support.The server will store the version we support. 
   11.19 +        * "As XI2 progresses it becomes important that you use this call as the server may treat the client 
   11.20 +        * differently depending on the supported version".
   11.21 +        *
   11.22 +        * FIXME:event and err are not needed but if not passed XQueryExtension returns SegmentationFault
   11.23 +        */
   11.24 +        if (!XQueryExtension(data->display, "XInputExtension", &opcode, &event, &err)) {
   11.25 +            SDL_SetError("XInput 2 extension not available.");
   11.26 +            return -1;
   11.27 +        }
   11.28 +      
   11.29 +        if (XIQueryVersion(data->display, &major, &minor) != Success) {
   11.30 +            SDL_SetError("Error supporting XInput 2 version");
   11.31 +            return -1;      
   11.32 +        }
   11.33 +
   11.34 +        /* Save the opcode for event processing */
   11.35 +        data->xinput_opcode = opcode;
   11.36 +
   11.37 +        /*Enable  Raw motion events for this display*/
   11.38 +        eventmask.deviceid = XIAllMasterDevices;
   11.39 +        eventmask.mask_len = sizeof(mask);
   11.40 +        eventmask.mask = mask;
   11.41 +
   11.42 +        XISetMask(mask, XI_RawMotion);
   11.43 +             
   11.44 +        if (XISelectEvents(data->display,DefaultRootWindow(data->display),&eventmask,1) != Success) {
   11.45 +            SDL_SetError("Error in selecting XInput 2 Raw motion events");
   11.46 +            return -1;      
   11.47 +        }
   11.48 +    }
   11.49 +#else
   11.50 +    return 0;
   11.51 +#endif
   11.52 +}
   11.53 +
   11.54 +int
   11.55  X11_VideoInit(_THIS)
   11.56  {
   11.57      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   11.58 @@ -359,6 +407,8 @@
   11.59          return -1;
   11.60      }
   11.61  
   11.62 +    X11_CheckXInput2(_this);
   11.63 +
   11.64      if (X11_InitKeyboard(_this) != 0) {
   11.65          return -1;
   11.66      }
    12.1 --- a/src/video/x11/SDL_x11video.h	Fri May 25 18:21:22 2012 -0400
    12.2 +++ b/src/video/x11/SDL_x11video.h	Wed May 30 11:25:35 2012 -0400
    12.3 @@ -37,8 +37,8 @@
    12.4  #if SDL_VIDEO_DRIVER_X11_XINERAMA
    12.5  #include <X11/extensions/Xinerama.h>
    12.6  #endif
    12.7 -#if SDL_VIDEO_DRIVER_X11_XINPUT
    12.8 -#include <X11/extensions/XInput.h>
    12.9 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
   12.10 +#include <X11/extensions/XInput2.h>
   12.11  #endif
   12.12  #if SDL_VIDEO_DRIVER_X11_XRANDR
   12.13  #include <X11/extensions/Xrandr.h>
   12.14 @@ -93,6 +93,15 @@
   12.15  
   12.16      SDL_Scancode key_layout[256];
   12.17      SDL_bool selection_waiting;
   12.18 +    
   12.19 +    /* Opcode returned XQueryExtension 
   12.20 +     * It will be used in event processing
   12.21 +     * to know that the event came from
   12.22 +     * this extension */ 
   12.23 +#if SDL_VIDEO_DRIVER_X11_XINPUT2
   12.24 +    int xinput_opcode;
   12.25 +#endif
   12.26 +    
   12.27  } SDL_VideoData;
   12.28  
   12.29  extern SDL_bool X11_UseDirectColorVisuals(void);
    13.1 --- a/test/Makefile.in	Fri May 25 18:21:22 2012 -0400
    13.2 +++ b/test/Makefile.in	Wed May 30 11:25:35 2012 -0400
    13.3 @@ -22,6 +22,7 @@
    13.4  	testiconv$(EXE) \
    13.5  	testime$(EXE) \
    13.6  	testintersections$(EXE) \
    13.7 +	testrelative$(EXE) \
    13.8  	testjoystick$(EXE) \
    13.9  	testkeys$(EXE) \
   13.10  	testloadso$(EXE) \
   13.11 @@ -71,6 +72,9 @@
   13.12  testintersections$(EXE): $(srcdir)/testintersections.c $(srcdir)/common.c
   13.13  	$(CC) -o $@ $(srcdir)/testintersections.c $(srcdir)/common.c $(CFLAGS) $(LIBS)
   13.14  
   13.15 +testrelative$(EXE): $(srcdir)/testrelative.c $(srcdir)/common.c
   13.16 +	$(CC) -o $@ $(srcdir)/testrelative.c $(srcdir)/common.c $(CFLAGS) $(LIBS)
   13.17 +
   13.18  testdraw2$(EXE): $(srcdir)/testdraw2.c $(srcdir)/common.c
   13.19  	$(CC) -o $@ $(srcdir)/testdraw2.c $(srcdir)/common.c $(CFLAGS) $(LIBS)
   13.20  
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/testrelative.c	Wed May 30 11:25:35 2012 -0400
    14.3 @@ -0,0 +1,95 @@
    14.4 +/*
    14.5 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
    14.6 +
    14.7 +  This software is provided 'as-is', without any express or implied
    14.8 +  warranty.  In no event will the authors be held liable for any damages
    14.9 +  arising from the use of this software.
   14.10 +
   14.11 +  Permission is granted to anyone to use this software for any purpose,
   14.12 +  including commercial applications, and to alter it and redistribute it
   14.13 +  freely.
   14.14 +*/
   14.15 +
   14.16 +/* Simple program:  Test relative mouse motion */
   14.17 +
   14.18 +#include <stdlib.h>
   14.19 +#include <stdio.h>
   14.20 +#include <time.h>
   14.21 +
   14.22 +#include "common.h"
   14.23 +
   14.24 +
   14.25 +static CommonState *state;
   14.26 +static SDL_Rect rect;
   14.27 +
   14.28 +static void
   14.29 +DrawRects(SDL_Renderer * renderer)
   14.30 +{
   14.31 +    SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
   14.32 +    SDL_RenderFillRect(renderer,&rect);
   14.33 +}
   14.34 +
   14.35 +int
   14.36 +main(int argc, char *argv[])
   14.37 +{
   14.38 +    int i, done;
   14.39 +    SDL_Event event;
   14.40 +
   14.41 + 
   14.42 +    /* Initialize test framework */
   14.43 +    state = CommonCreateState(argv, SDL_INIT_VIDEO);
   14.44 +    if (!state) {
   14.45 +        return 1;
   14.46 +    }
   14.47 +    if (!CommonInit(state)) {
   14.48 +        return 2;
   14.49 +    }
   14.50 +
   14.51 +    /* Create the windows and initialize the renderers */
   14.52 +    for (i = 0; i < state->num_windows; ++i) {
   14.53 +        SDL_Renderer *renderer = state->renderers[i];
   14.54 +        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
   14.55 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   14.56 +        SDL_RenderClear(renderer);
   14.57 +    }
   14.58 +
   14.59 +    srand((unsigned int)time(NULL));
   14.60 +    SDL_SetRelativeMouseMode(SDL_TRUE);
   14.61 +
   14.62 +    rect.x = DEFAULT_WINDOW_WIDTH / 2;
   14.63 +    rect.y = DEFAULT_WINDOW_HEIGHT / 2;
   14.64 +    rect.w = 10;
   14.65 +    rect.h = 10;
   14.66 +    /* Main render loop */
   14.67 +    done = 0;
   14.68 +    while (!done) {
   14.69 +        /* Check for events */
   14.70 +        while (SDL_PollEvent(&event)) {
   14.71 +            CommonEvent(state, &event, &done);
   14.72 +            switch(event.type) {
   14.73 +                case SDL_MOUSEMOTION:
   14.74 +                {
   14.75 +                    /*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/
   14.76 +                    rect.x += event.motion.xrel;
   14.77 +                    rect.y += event.motion.yrel;
   14.78 +
   14.79 +                }
   14.80 +                break;
   14.81 +            }
   14.82 +        }
   14.83 +        for (i = 0; i < state->num_windows; ++i) {
   14.84 +            SDL_Renderer *renderer = state->renderers[i];
   14.85 +            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   14.86 +            SDL_RenderClear(renderer);
   14.87 +
   14.88 +            DrawRects(renderer);
   14.89 +
   14.90 +            SDL_RenderPresent(renderer);
   14.91 +        }
   14.92 +    }
   14.93 +
   14.94 +    CommonQuit(state);
   14.95 +    return 0;
   14.96 +}
   14.97 +
   14.98 +/* vi: set ts=4 sw=4 expandtab: */