Fix no mouse if touch device present in X11

Plus several improvements in this area.

Sadly, grabbing has been disabled until a better solution is found.

Fixes #14427.
This commit is contained in:
Pedro J. Estébanez 2017-12-10 07:05:17 +01:00
parent a5b3c9cae0
commit ef64bfd687

View file

@ -195,14 +195,13 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XIDeviceInfo *dev = &info[i];
if (!dev->enabled)
continue;
/*if (dev->use != XIMasterPointer)
continue;*/
if (!(dev->use == XIMasterPointer || dev->use == XIFloatingSlave))
continue;
bool direct_touch = false;
for (int j = 0; j < dev->num_classes; j++) {
if (dev->classes[j]->type == XITouchClass && ((XITouchClassInfo *)dev->classes[j])->mode == XIDirectTouch) {
direct_touch = true;
printf("%d) %d %s\n", i, dev->attachment, dev->name);
break;
}
}
@ -215,7 +214,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XIFreeDeviceInfo(info);
if (!touch.devices.size()) {
fprintf(stderr, "No suitable touch device found\n");
fprintf(stderr, "No touch devices found\n");
}
}
}
@ -359,7 +358,7 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
// Must be alive after this block
static unsigned char mask_data[XIMaskLen(XI_LASTEVENT)] = {};
touch.event_mask.deviceid = XIAllMasterDevices;
touch.event_mask.deviceid = XIAllDevices;
touch.event_mask.mask_len = sizeof(mask_data);
touch.event_mask.mask = mask_data;
@ -370,12 +369,14 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
XISelectEvents(x11_display, x11_window, &touch.event_mask, 1);
XIClearMask(touch.event_mask.mask, XI_TouchOwnership);
// Disabled by now since grabbing also blocks mouse events
// (they are received as extended events instead of standard events)
/*XIClearMask(touch.event_mask.mask, XI_TouchOwnership);
// Grab touch devices to avoid OS gesture interference
for (int i = 0; i < touch.devices.size(); ++i) {
XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
}
}*/
}
#endif
@ -1512,7 +1513,7 @@ void OS_X11::process_xevents() {
#ifdef TOUCH_ENABLED
if (XGetEventData(x11_display, &event.xcookie)) {
if (event.xcookie.extension == touch.opcode) {
if (event.xcookie.type == GenericEvent && event.xcookie.extension == touch.opcode) {
XIDeviceEvent *event_data = (XIDeviceEvent *)event.xcookie.data;
int index = event_data->detail;
@ -1521,7 +1522,8 @@ void OS_X11::process_xevents() {
switch (event_data->evtype) {
case XI_TouchBegin: // Fall-through
XIAllowTouchEvents(x11_display, event_data->deviceid, event_data->detail, x11_window, XIAcceptTouch);
// Disabled hand-in-hand with the grabbing
//XIAllowTouchEvents(x11_display, event_data->deviceid, event_data->detail, x11_window, XIAcceptTouch);
case XI_TouchEnd: {
@ -1567,9 +1569,8 @@ void OS_X11::process_xevents() {
} break;
}
}
XFreeEventData(x11_display, &event.xcookie);
}
XFreeEventData(x11_display, &event.xcookie);
#endif
switch (event.type) {
@ -1615,10 +1616,10 @@ void OS_X11::process_xevents() {
GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime);
}
#ifdef TOUCH_ENABLED
// Grab touch devices to avoid OS gesture interference
for (int i = 0; i < touch.devices.size(); ++i) {
// Grab touch devices to avoid OS gesture interference
/*for (int i = 0; i < touch.devices.size(); ++i) {
XIGrabDevice(x11_display, touch.devices[i], x11_window, CurrentTime, None, XIGrabModeAsync, XIGrabModeAsync, False, &touch.event_mask);
}
}*/
#endif
if (xic) {
XSetICFocus(xic);
@ -1638,9 +1639,9 @@ void OS_X11::process_xevents() {
}
#ifdef TOUCH_ENABLED
// Ungrab touch devices so input works as usual while we are unfocused
for (int i = 0; i < touch.devices.size(); ++i) {
/*for (int i = 0; i < touch.devices.size(); ++i) {
XIUngrabDevice(x11_display, touch.devices[i], CurrentTime);
}
}*/
// Release every pointer to avoid sticky points
for (Map<int, Vector2>::Element *E = touch.state.front(); E; E = E->next()) {