Better attempt to detect available X11 XInput2 features.

Fixes Bugzilla #2306.
This commit is contained in:
Ryan C. Gordon 2014-03-02 02:00:40 -05:00
parent fc0daeba75
commit afc74d9843

View File

@ -60,16 +60,18 @@ static void parse_valuators(const double *input_values,unsigned char *mask,int m
} }
} }
static SDL_bool static int
xinput2_version_okay(Display *display, const int major, const int minor) query_xinput2_version(Display *display, int major, int minor)
{ {
int outmajor = major; /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */
int outminor = minor; X11_XIQueryVersion(display, &major, &minor);
if (X11_XIQueryVersion(display, &outmajor, &outminor) != Success) { return ((major * 1000) + minor);
return SDL_FALSE; }
}
return ( ((outmajor * 1000) + outminor) >= ((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 */ #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
@ -79,9 +81,11 @@ X11_InitXinput2(_THIS)
#if SDL_VIDEO_DRIVER_X11_XINPUT2 #if SDL_VIDEO_DRIVER_X11_XINPUT2
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
int version = 0;
XIEventMask eventmask; XIEventMask eventmask;
unsigned char mask[3] = { 0,0,0 }; unsigned char mask[3] = { 0,0,0 };
int event, err; int event, err;
/* /*
* Initialize XInput 2 * Initialize XInput 2
* According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
@ -96,16 +100,16 @@ X11_InitXinput2(_THIS)
return; /* X server does not have XInput at all */ return; /* X server does not have XInput at all */
} }
if (!xinput2_version_okay(data->display, 2, 0)) { /* We need at least 2.2 for Multitouch, 2.0 otherwise. */
return; /* X server does not support the version we want */ 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. */
} }
xinput2_initialized = 1; xinput2_initialized = 1;
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH /* Multitouch needs XInput 2.2 */
if (xinput2_version_okay(data->display, 2, 2)) { /* Multitouch needs XInput 2.2 */ xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
xinput2_multitouch_supported = 1;
}
#endif #endif
/* Enable Raw motion events for this display */ /* Enable Raw motion events for this display */