X11: allow using touchscreen, while pointer is grabbed (see bug #3978)

This commit is contained in:
Sylvain 2021-05-12 23:13:48 +02:00
parent ddc6be3559
commit 531d83bf6a
No known key found for this signature in database
GPG key ID: 5F87E02E5BC0939E
3 changed files with 50 additions and 0 deletions

View file

@ -1623,6 +1623,8 @@ X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
}
}
X11_Xinput2GrabTouch(_this, window);
/* Raise the window if we grab the mouse */
X11_XRaiseWindow(display, data->xwindow);
@ -1632,6 +1634,8 @@ X11_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
}
} else {
X11_XUngrabPointer(display, CurrentTime);
X11_Xinput2UngrabTouch(_this, window);
}
X11_XSync(display, False);
}

View file

@ -343,6 +343,50 @@ X11_Xinput2IsMultitouchSupported()
#endif
}
void
X11_Xinput2GrabTouch(_THIS, SDL_Window *window)
{
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
Display *display = data->videodata->display;
unsigned char mask[4] = { 0, 0, 0, 0 };
XIGrabModifiers mods;
XIEventMask eventmask;
mods.modifiers = XIAnyModifier;
mods.status = 0;
eventmask.deviceid = XIAllDevices;
eventmask.mask_len = sizeof(mask);
eventmask.mask = mask;
XISetMask(eventmask.mask, XI_TouchBegin);
XISetMask(eventmask.mask, XI_TouchUpdate);
XISetMask(eventmask.mask, XI_TouchEnd);
XISetMask(eventmask.mask, XI_Motion);
XIGrabTouchBegin(display, XIAllDevices, data->xwindow, True, &eventmask, 1, &mods);
#endif
}
void
X11_Xinput2UngrabTouch(_THIS, SDL_Window *window)
{
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
Display *display = data->videodata->display;
XIGrabModifiers mods;
mods.modifiers = XIAnyModifier;
mods.status = 0;
XIUngrabTouchBegin(display, XIAllDevices, data->xwindow, 1, &mods);
#endif
}
#endif /* SDL_VIDEO_DRIVER_X11 */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -36,6 +36,8 @@ extern int X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *
extern int X11_Xinput2IsInitialized(void);
extern int X11_Xinput2IsMultitouchSupported(void);
extern void X11_Xinput2SelectTouch(_THIS, SDL_Window *window);
extern void X11_Xinput2GrabTouch(_THIS, SDL_Window *window);
extern void X11_Xinput2UngrabTouch(_THIS, SDL_Window *window);
#endif /* SDL_x11xinput2_h_ */