23 #if SDL_VIDEO_DRIVER_X11
27 #include "../../events/SDL_mouse_c.h"
28 #include "../../events/SDL_touch_c.h"
32 #if SDL_VIDEO_DRIVER_X11_XINPUT2
33 static int xinput2_initialized = 0;
35 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
36 static int xinput2_multitouch_supported = 0;
43 static int xinput2_opcode;
45 static void parse_valuators(
const double *input_values,
unsigned char *
mask,
int mask_len,
46 double *output_values,
int output_values_len) {
48 int top = mask_len * 8;
52 SDL_memset(output_values,0,output_values_len *
sizeof(
double));
53 for (; i < top &&
z < output_values_len; i++) {
54 if (XIMaskIsSet(mask, i)) {
55 const int value = (
int) *input_values;
67 #if SDL_VIDEO_DRIVER_X11_XINPUT2
70 XIEventMask eventmask;
71 unsigned char mask[3] = { 0,0,0 };
73 int major = 2, minor = 0;
74 int outmajor,outminor;
75 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
87 if (!SDL_X11_HAVE_XINPUT2 ||
88 !XQueryExtension(
data->display,
"XInputExtension", &xinput2_opcode, &event, &err)) {
94 if (XIQueryVersion(
data->display, &outmajor, &outminor) != Success) {
99 if(outmajor * 1000 + outminor < major * 1000 + minor) {
103 xinput2_initialized = 1;
104 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
106 if(outmajor * 1000 + outminor >= major * 1000 + minor) {
107 xinput2_multitouch_supported = 1;
112 eventmask.deviceid = XIAllMasterDevices;
113 eventmask.mask_len =
sizeof(
mask);
114 eventmask.mask =
mask;
116 XISetMask(mask, XI_RawMotion);
118 if (XISelectEvents(
data->display,DefaultRootWindow(
data->display),&eventmask,1) != Success) {
126 unsigned long serial;
138 #if SDL_VIDEO_DRIVER_X11_XINPUT2
139 if(cookie->extension != xinput2_opcode) {
142 switch(cookie->evtype) {
144 const XIRawEvent *rawev = (
const XIRawEvent*)cookie->data;
146 double relative_cords[2];
148 if (!mouse->relative_mode) {
152 parse_valuators(rawev->raw_values,rawev->valuators.mask,
153 rawev->valuators.mask_len,relative_cords,2);
154 SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(
int)relative_cords[0],(
int)relative_cords[1]);
158 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
159 case XI_TouchBegin: {
160 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
162 SDL_TRUE, xev->event_x, xev->event_y, 1.0);
167 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
169 SDL_FALSE, xev->event_x, xev->event_y, 1.0);
173 case XI_TouchUpdate: {
174 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
176 xev->event_x, xev->event_y, 1.0);
189 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
193 info = XIQueryDevice(data->
display, XIAllMasterDevices, &ndevices);
195 for (i = 0; i < ndevices; i++) {
196 XIDeviceInfo *dev = &info[
i];
197 for (
j = 0;
j < dev->num_classes;
j++) {
199 XIAnyClassInfo *
class = dev->classes[
j];
200 XITouchClassInfo *
t = (XITouchClassInfo*)
class;
203 if (class->type != XITouchClass)
206 touchId = t->sourceid;
212 XIFreeDeviceInfo(info);
219 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
221 XIEventMask eventmask;
222 unsigned char mask[3] = { 0,0,0 };
232 eventmask.deviceid = XIAllMasterDevices;
233 eventmask.mask_len =
sizeof(
mask);
234 eventmask.mask =
mask;
236 XISetMask(mask, XI_TouchBegin);
237 XISetMask(mask, XI_TouchUpdate);
238 XISetMask(mask, XI_TouchEnd);
248 #if SDL_VIDEO_DRIVER_X11_XINPUT2
249 return xinput2_initialized;
258 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
259 return xinput2_initialized && xinput2_multitouch_supported;
SDL_Mouse * SDL_GetMouse(void)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
static SDL_VideoDevice * _this
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
GLfloat GLfloat GLfloat top
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
EGLSurface EGLint void ** value
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLint GLint GLint z
SDL_Touch * SDL_GetTouch(SDL_TouchID id)