Query version for X11 XInput2 multitouch separately from base XInput2.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 20 Nov 2013 21:17:26 -0500
changeset 80195d85b2186aae
parent 8018 cff03048babd
child 8020 1e390ba95c43
Query version for X11 XInput2 multitouch separately from base XInput2.
src/video/x11/SDL_x11xinput2.c
     1.1 --- a/src/video/x11/SDL_x11xinput2.c	Wed Nov 20 12:51:18 2013 -0300
     1.2 +++ b/src/video/x11/SDL_x11xinput2.c	Wed Nov 20 21:17:26 2013 -0500
     1.3 @@ -59,6 +59,18 @@
     1.4          z++;
     1.5      }
     1.6  }
     1.7 +
     1.8 +static SDL_bool
     1.9 +xinput2_version_okay(Display *display, const int major, const int minor)
    1.10 +{
    1.11 +    int outmajor = major;
    1.12 +    int outminor = minor;
    1.13 +    if (X11_XIQueryVersion(display, &outmajor, &outminor) != Success) {
    1.14 +        return SDL_FALSE;
    1.15 +    }
    1.16 +
    1.17 +    return ( ((outmajor * 1000) + outminor) >= ((major * 1000) + minor) );
    1.18 +}
    1.19  #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    1.20  
    1.21  void
    1.22 @@ -70,11 +82,6 @@
    1.23      XIEventMask eventmask;
    1.24      unsigned char mask[3] = { 0,0,0 };
    1.25      int event, err;
    1.26 -    int major = 2, minor = 0;
    1.27 -    int outmajor,outminor;
    1.28 -#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    1.29 -    minor = 2;
    1.30 -#endif
    1.31      /*
    1.32      * Initialize XInput 2
    1.33      * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
    1.34 @@ -86,24 +93,17 @@
    1.35      */
    1.36      if (!SDL_X11_HAVE_XINPUT2 ||
    1.37          !X11_XQueryExtension(data->display, "XInputExtension", &xinput2_opcode, &event, &err)) {
    1.38 -        return;
    1.39 +        return; /* X server does not have XInput at all */
    1.40      }
    1.41  
    1.42 -    outmajor = major;
    1.43 -    outminor = minor;
    1.44 -    if (X11_XIQueryVersion(data->display, &outmajor, &outminor) != Success) {
    1.45 -        return;
    1.46 +    if (!xinput2_version_okay(data->display, 2, 0)) {
    1.47 +        return; /* X server does not support the version we want */
    1.48      }
    1.49  
    1.50 -    /* Check supported version */
    1.51 -    if(outmajor * 1000 + outminor < major * 1000 + minor) {
    1.52 -        /* X server does not support the version we want */
    1.53 -        return;
    1.54 -    }
    1.55      xinput2_initialized = 1;
    1.56 +
    1.57  #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    1.58 -    /* XInput 2.2 */
    1.59 -    if(outmajor * 1000 + outminor >= major * 1000 + minor) {
    1.60 +    if (xinput2_version_okay(data->display, 2, 2)) {  /* Multitouch needs XInput 2.2 */
    1.61          xinput2_multitouch_supported = 1;
    1.62      }
    1.63  #endif