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);
121 XISetMask(mask, XI_RawButtonPress);
122 XISetMask(mask, XI_RawButtonRelease);
124 if (X11_XISelectEvents(
data->display,DefaultRootWindow(
data->display),&eventmask,1) != Success) {
133 #if SDL_VIDEO_DRIVER_X11_XINPUT2
134 if(cookie->extension != xinput2_opcode) {
137 switch(cookie->evtype) {
139 const XIRawEvent *rawev = (
const XIRawEvent*)cookie->data;
141 double relative_coords[2];
142 static Time prev_time = 0;
143 static double prev_rel_coords[2];
147 if (!mouse->relative_mode || mouse->relative_mode_warp) {
151 parse_valuators(rawev->raw_values,rawev->valuators.mask,
152 rawev->valuators.mask_len,relative_coords,2);
154 if ((rawev->time == prev_time) && (relative_coords[0] == prev_rel_coords[0]) && (relative_coords[1] == prev_rel_coords[1])) {
158 SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(
int)relative_coords[0],(
int)relative_coords[1]);
159 prev_rel_coords[0] = relative_coords[0];
160 prev_rel_coords[1] = relative_coords[1];
161 prev_time = rawev->time;
166 case XI_RawButtonPress:
167 case XI_RawButtonRelease:
171 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
172 case XI_TouchBegin: {
173 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
175 SDL_TRUE, xev->event_x, xev->event_y, 1.0);
180 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
182 SDL_FALSE, xev->event_x, xev->event_y, 1.0);
186 case XI_TouchUpdate: {
187 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
189 xev->event_x, xev->event_y, 1.0);
202 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
206 info = X11_XIQueryDevice(data->
display, XIAllDevices, &ndevices);
208 for (i = 0; i < ndevices; i++) {
209 XIDeviceInfo *dev = &info[
i];
210 for (
j = 0;
j < dev->num_classes;
j++) {
212 XIAnyClassInfo *
class = dev->classes[
j];
213 XITouchClassInfo *
t = (XITouchClassInfo*)
class;
216 if (class->type != XITouchClass)
219 touchId = t->sourceid;
223 X11_XIFreeDeviceInfo(info);
230 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
232 XIEventMask eventmask;
233 unsigned char mask[3] = { 0,0,0 };
243 eventmask.deviceid = XIAllMasterDevices;
244 eventmask.mask_len =
sizeof(
mask);
245 eventmask.mask =
mask;
247 XISetMask(mask, XI_TouchBegin);
248 XISetMask(mask, XI_TouchUpdate);
249 XISetMask(mask, XI_TouchEnd);
251 X11_XISelectEvents(data->
display,window_data->
xwindow,&eventmask,1);
259 #if SDL_VIDEO_DRIVER_X11_XINPUT2
260 return xinput2_initialized;
269 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
270 return xinput2_initialized && xinput2_multitouch_supported;
SDL_Mouse * SDL_GetMouse(void)
struct wl_display * display
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble GLdouble top
SDL_bool global_mouse_changed
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
static SDL_VideoDevice * _this
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)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLsizei const GLfloat * value
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)
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.