mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 16:44:11 +00:00
Added initial XInput2 cursor motion.
This commit is contained in:
@@ -213,6 +213,21 @@ static GLboolean createWindow(_GLFWwindow* window,
|
||||
XFree(hints);
|
||||
}
|
||||
|
||||
if (_glfw.x11.xi2.available)
|
||||
{
|
||||
// Select for XInput2 events
|
||||
|
||||
XIEventMask eventmask;
|
||||
unsigned char mask[] = { 0 };
|
||||
|
||||
eventmask.deviceid = 2;
|
||||
eventmask.mask_len = sizeof(mask);
|
||||
eventmask.mask = mask;
|
||||
XISetMask(mask, XI_Motion);
|
||||
|
||||
XISelectEvents(_glfw.x11.display, window->x11.handle, &eventmask, 1);
|
||||
}
|
||||
|
||||
_glfwPlatformSetWindowTitle(window, wndconfig->title);
|
||||
|
||||
XRRSelectInput(_glfw.x11.display, window->x11.handle,
|
||||
@@ -699,6 +714,53 @@ static void processEvent(XEvent *event)
|
||||
case DestroyNotify:
|
||||
return;
|
||||
|
||||
case GenericEvent:
|
||||
{
|
||||
if (event->xcookie.extension == _glfw.x11.xi2.majorOpcode &&
|
||||
XGetEventData(_glfw.x11.display, &event->xcookie))
|
||||
{
|
||||
if (event->xcookie.evtype == XI_Motion)
|
||||
{
|
||||
XIDeviceEvent* data = (XIDeviceEvent*) event->xcookie.data;
|
||||
|
||||
window = _glfwFindWindowByHandle(data->event);
|
||||
if (window)
|
||||
{
|
||||
if (data->event_x != window->x11.cursorPosX ||
|
||||
data->event_y != window->x11.cursorPosY)
|
||||
{
|
||||
// The cursor was moved by something other than GLFW
|
||||
|
||||
double x, y;
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
if (_glfw.focusedWindow != window)
|
||||
break;
|
||||
|
||||
x = data->event_x - window->x11.cursorPosX;
|
||||
y = data->event_y - window->x11.cursorPosY;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = data->event_x;
|
||||
y = data->event_y;
|
||||
}
|
||||
|
||||
window->x11.cursorPosX = data->event_x;
|
||||
window->x11.cursorPosY = data->event_y;
|
||||
window->x11.cursorCentered = GL_FALSE;
|
||||
|
||||
_glfwInputCursorMotion(window, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XFreeEventData(_glfw.x11.display, &event->xcookie);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
switch (event->type - _glfw.x11.randr.eventBase)
|
||||
|
||||
Reference in New Issue
Block a user