21 #include "../../SDL_internal.h" 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;
64 query_xinput2_version(Display *
display,
int major,
int minor)
67 X11_XIQueryVersion(display, &major, &minor);
68 return ((major * 1000) + minor);
72 xinput2_version_atleast(
const int version,
const int wantmajor,
const int wantminor)
74 return ( version >= ((wantmajor * 1000) + wantminor) );
81 #if SDL_VIDEO_DRIVER_X11_XINPUT2 85 XIEventMask eventmask;
86 unsigned char mask[3] = { 0,0,0 };
98 if (!SDL_X11_HAVE_XINPUT2 ||
99 !X11_XQueryExtension(
data->display,
"XInputExtension", &xinput2_opcode, &event, &err)) {
104 version = query_xinput2_version(
data->display, 2, 2);
105 if (!xinput2_version_atleast(version, 2, 0)) {
109 xinput2_initialized = 1;
111 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 112 xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
116 eventmask.deviceid = XIAllMasterDevices;
117 eventmask.mask_len =
sizeof(
mask);
118 eventmask.mask =
mask;
120 XISetMask(mask, XI_RawMotion);
122 if (X11_XISelectEvents(
data->display,DefaultRootWindow(
data->display),&eventmask,1) != Success) {
131 #if SDL_VIDEO_DRIVER_X11_XINPUT2 132 if(cookie->extension != xinput2_opcode) {
135 switch(cookie->evtype) {
137 const XIRawEvent *rawev = (
const XIRawEvent*)cookie->data;
139 double relative_coords[2];
140 static Time prev_time = 0;
141 static double prev_rel_coords[2];
143 if (!mouse->relative_mode || mouse->relative_mode_warp) {
147 parse_valuators(rawev->raw_values,rawev->valuators.mask,
148 rawev->valuators.mask_len,relative_coords,2);
150 if ((rawev->time == prev_time) && (relative_coords[0] == prev_rel_coords[0]) && (relative_coords[1] == prev_rel_coords[1])) {
154 SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(
int)relative_coords[0],(
int)relative_coords[1]);
155 prev_rel_coords[0] = relative_coords[0];
156 prev_rel_coords[1] = relative_coords[1];
157 prev_time = rawev->time;
161 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 162 case XI_TouchBegin: {
163 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
165 SDL_TRUE, xev->event_x, xev->event_y, 1.0);
170 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
172 SDL_FALSE, xev->event_x, xev->event_y, 1.0);
176 case XI_TouchUpdate: {
177 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
179 xev->event_x, xev->event_y, 1.0);
192 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 196 info = X11_XIQueryDevice(data->
display, XIAllDevices, &ndevices);
198 for (i = 0; i < ndevices; i++) {
199 XIDeviceInfo *dev = &info[
i];
200 for (
j = 0;
j < dev->num_classes;
j++) {
202 XIAnyClassInfo *
class = dev->classes[
j];
203 XITouchClassInfo *
t = (XITouchClassInfo*)
class;
206 if (class->type != XITouchClass)
209 touchId = t->sourceid;
213 X11_XIFreeDeviceInfo(info);
220 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 222 XIEventMask eventmask;
223 unsigned char mask[3] = { 0,0,0 };
233 eventmask.deviceid = XIAllMasterDevices;
234 eventmask.mask_len =
sizeof(
mask);
235 eventmask.mask =
mask;
237 XISetMask(mask, XI_TouchBegin);
238 XISetMask(mask, XI_TouchUpdate);
239 XISetMask(mask, XI_TouchEnd);
241 X11_XISelectEvents(data->
display,window_data->
xwindow,&eventmask,1);
249 #if SDL_VIDEO_DRIVER_X11_XINPUT2 250 return xinput2_initialized;
259 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 260 return xinput2_initialized && xinput2_multitouch_supported;
SDL_Mouse * SDL_GetMouse(void)
struct wl_display * display
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLdouble GLdouble GLdouble GLdouble top
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)
GLsizei const GLfloat * value
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
The type used to identify a window.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)