Mac and Linux SDL2 binary snapshots
Edward Rudd
2014-03-08 e2b6e957100030b4c9e8d720157b0a34195e6dcb
source/src/video/x11/SDL_x11xinput2.c
@@ -1,6 +1,6 @@
/*
  Simple DirectMedia Layer
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
@@ -18,7 +18,7 @@
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_X11
@@ -59,6 +59,20 @@
        z++;
    }
}
static int
query_xinput2_version(Display *display, int major, int minor)
{
    /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */
    X11_XIQueryVersion(display, &major, &minor);
    return ((major * 1000) + minor);
}
static SDL_bool
xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
{
    return ( version >= ((wantmajor * 1000) + wantminor) );
}
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
void
@@ -67,14 +81,11 @@
#if SDL_VIDEO_DRIVER_X11_XINPUT2
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    int version = 0;
    XIEventMask eventmask;
    unsigned char mask[3] = { 0,0,0 };
    int event, err;
    int major = 2, minor = 0;
    int outmajor,outminor;
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    minor = 2;
#endif
    /*
    * Initialize XInput 2
    * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
@@ -86,26 +97,19 @@
    */
    if (!SDL_X11_HAVE_XINPUT2 ||
        !X11_XQueryExtension(data->display, "XInputExtension", &xinput2_opcode, &event, &err)) {
        return;
        return; /* X server does not have XInput at all */
    }
    outmajor = major;
    outminor = minor;
    if (X11_XIQueryVersion(data->display, &outmajor, &outminor) != Success) {
        return;
    /* We need at least 2.2 for Multitouch, 2.0 otherwise. */
    version = query_xinput2_version(data->display, 2, 2);
    if (!xinput2_version_atleast(version, 2, 0)) {
        return; /* X server does not support the version we want at all. */
    }
    /* Check supported version */
    if(outmajor * 1000 + outminor < major * 1000 + minor) {
        /* X server does not support the version we want */
        return;
    }
    xinput2_initialized = 1;
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    /* XInput 2.2 */
    if(outmajor * 1000 + outminor >= major * 1000 + minor) {
        xinput2_multitouch_supported = 1;
    }
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH  /* Multitouch needs XInput 2.2 */
    xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
#endif
    /* Enable  Raw motion events for this display */
@@ -134,7 +138,7 @@
            SDL_Mouse *mouse = SDL_GetMouse();
            double relative_cords[2];
            if (!mouse->relative_mode) {
            if (!mouse->relative_mode || mouse->relative_mode_warp) {
                return 0;
            }