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) );
77 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 80 double in_x,
double in_y,
float *out_x,
float *out_y)
89 *out_x = in_x / (d->
window->
w - 1);
94 *out_y = in_y / (d->
window->
h - 1);
110 #if SDL_VIDEO_DRIVER_X11_XINPUT2 114 XIEventMask eventmask;
115 unsigned char mask[3] = { 0,0,0 };
127 if (!SDL_X11_HAVE_XINPUT2 ||
128 !X11_XQueryExtension(
data->display,
"XInputExtension", &xinput2_opcode, &event, &err)) {
133 version = query_xinput2_version(
data->display, 2, 2);
134 if (!xinput2_version_atleast(version, 2, 0)) {
138 xinput2_initialized = 1;
140 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 141 xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
145 eventmask.deviceid = XIAllMasterDevices;
146 eventmask.mask_len =
sizeof(
mask);
147 eventmask.mask =
mask;
149 XISetMask(mask, XI_RawMotion);
150 XISetMask(mask, XI_RawButtonPress);
151 XISetMask(mask, XI_RawButtonRelease);
153 if (X11_XISelectEvents(
data->display,DefaultRootWindow(
data->display),&eventmask,1) != Success) {
162 #if SDL_VIDEO_DRIVER_X11_XINPUT2 163 if(cookie->extension != xinput2_opcode) {
166 switch(cookie->evtype) {
168 const XIRawEvent *rawev = (
const XIRawEvent*)cookie->data;
170 double relative_coords[2];
171 static Time prev_time = 0;
172 static double prev_rel_coords[2];
176 if (!mouse->relative_mode || mouse->relative_mode_warp) {
180 parse_valuators(rawev->raw_values,rawev->valuators.mask,
181 rawev->valuators.mask_len,relative_coords,2);
183 if ((rawev->time == prev_time) && (relative_coords[0] == prev_rel_coords[0]) && (relative_coords[1] == prev_rel_coords[1])) {
187 SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(
int)relative_coords[0],(
int)relative_coords[1]);
188 prev_rel_coords[0] = relative_coords[0];
189 prev_rel_coords[1] = relative_coords[1];
190 prev_time = rawev->time;
195 case XI_RawButtonPress:
196 case XI_RawButtonRelease:
200 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 201 case XI_TouchBegin: {
202 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
204 xinput2_normalize_touch_coordinates(videodata, xev->event,
205 xev->event_x, xev->event_y, &x, &
y);
211 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
213 xinput2_normalize_touch_coordinates(videodata, xev->event,
214 xev->event_x, xev->event_y, &x, &
y);
219 case XI_TouchUpdate: {
220 const XIDeviceEvent *xev = (
const XIDeviceEvent *) cookie->data;
222 xinput2_normalize_touch_coordinates(videodata, xev->event,
223 xev->event_x, xev->event_y, &x, &
y);
237 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 241 info = X11_XIQueryDevice(data->
display, XIAllDevices, &ndevices);
243 for (i = 0; i < ndevices; i++) {
244 XIDeviceInfo *dev = &info[
i];
245 for (
j = 0;
j < dev->num_classes;
j++) {
247 XIAnyClassInfo *
class = dev->classes[
j];
248 XITouchClassInfo *
t = (XITouchClassInfo*)
class;
251 if (class->type != XITouchClass)
254 touchId = t->sourceid;
258 X11_XIFreeDeviceInfo(info);
265 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 267 XIEventMask eventmask;
268 unsigned char mask[3] = { 0,0,0 };
278 eventmask.deviceid = XIAllMasterDevices;
279 eventmask.mask_len =
sizeof(
mask);
280 eventmask.mask =
mask;
282 XISetMask(mask, XI_TouchBegin);
283 XISetMask(mask, XI_TouchUpdate);
284 XISetMask(mask, XI_TouchEnd);
286 X11_XISelectEvents(data->
display,window_data->
xwindow,&eventmask,1);
294 #if SDL_VIDEO_DRIVER_X11_XINPUT2 295 return xinput2_initialized;
304 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 305 return xinput2_initialized && xinput2_multitouch_supported;
SDL_Mouse * SDL_GetMouse(void)
GLint GLint GLint GLint GLint x
struct wl_display * display
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
SDL_WindowData ** windowlist
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
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
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)
GLsizei const GLfloat * value
GLint GLint GLint GLint GLint GLint y
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)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.