Better attempt to detect available X11 XInput2 features.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 02 Mar 2014 02:00:40 -0500
changeset 8283176891c01b3c
parent 8282 484d2404c472
child 8284 a2910aa6c056
Better attempt to detect available X11 XInput2 features.

Fixes Bugzilla #2306.
src/video/x11/SDL_x11xinput2.c
     1.1 --- a/src/video/x11/SDL_x11xinput2.c	Sun Mar 02 01:59:25 2014 -0500
     1.2 +++ b/src/video/x11/SDL_x11xinput2.c	Sun Mar 02 02:00:40 2014 -0500
     1.3 @@ -60,16 +60,18 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static int
     1.8 +query_xinput2_version(Display *display, int major, int minor)
     1.9 +{
    1.10 +    /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */
    1.11 +    X11_XIQueryVersion(display, &major, &minor);
    1.12 +    return ((major * 1000) + minor);
    1.13 +}
    1.14 +
    1.15  static SDL_bool
    1.16 -xinput2_version_okay(Display *display, const int major, const int minor)
    1.17 +xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
    1.18  {
    1.19 -    int outmajor = major;
    1.20 -    int outminor = minor;
    1.21 -    if (X11_XIQueryVersion(display, &outmajor, &outminor) != Success) {
    1.22 -        return SDL_FALSE;
    1.23 -    }
    1.24 -
    1.25 -    return ( ((outmajor * 1000) + outminor) >= ((major * 1000) + minor) );
    1.26 +    return ( version >= ((wantmajor * 1000) + wantminor) );
    1.27  }
    1.28  #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    1.29  
    1.30 @@ -79,9 +81,11 @@
    1.31  #if SDL_VIDEO_DRIVER_X11_XINPUT2
    1.32      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.33  
    1.34 +    int version = 0;
    1.35      XIEventMask eventmask;
    1.36      unsigned char mask[3] = { 0,0,0 };
    1.37      int event, err;
    1.38 +
    1.39      /*
    1.40      * Initialize XInput 2
    1.41      * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
    1.42 @@ -96,16 +100,16 @@
    1.43          return; /* X server does not have XInput at all */
    1.44      }
    1.45  
    1.46 -    if (!xinput2_version_okay(data->display, 2, 0)) {
    1.47 -        return; /* X server does not support the version we want */
    1.48 +    /* We need at least 2.2 for Multitouch, 2.0 otherwise. */
    1.49 +    version = query_xinput2_version(data->display, 2, 2);
    1.50 +    if (!xinput2_version_atleast(version, 2, 0)) {
    1.51 +        return; /* X server does not support the version we want at all. */
    1.52      }
    1.53  
    1.54      xinput2_initialized = 1;
    1.55  
    1.56 -#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    1.57 -    if (xinput2_version_okay(data->display, 2, 2)) {  /* Multitouch needs XInput 2.2 */
    1.58 -        xinput2_multitouch_supported = 1;
    1.59 -    }
    1.60 +#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH  /* Multitouch needs XInput 2.2 */
    1.61 +    xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
    1.62  #endif
    1.63  
    1.64      /* Enable  Raw motion events for this display */