Add GLFW_RAW_INPUT and glfwRawInputSupported

This adds runtime per-window control of whether accelerated or raw mouse
motion is provided when the cursor is disabled.

Fixes #1400.
Closes #1401.
This commit is contained in:
Nathan Poirier
2018-12-14 03:08:25 +01:00
committed by Camilla Löwy
parent 5f9cbd0ebc
commit 9e29f556fd
11 changed files with 157 additions and 14 deletions
+22 -3
View File
@@ -526,7 +526,7 @@ static void updateCursorImage(_GLFWwindow* window)
//
static void disableCursor(_GLFWwindow* window)
{
if (_glfw.x11.xi.available)
if (_glfw.x11.xi.available && window->useRawInput)
{
XIEventMask em;
unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
@@ -557,7 +557,7 @@ static void disableCursor(_GLFWwindow* window)
//
static void enableCursor(_GLFWwindow* window)
{
if (_glfw.x11.xi.available)
if (_glfw.x11.xi.available && window->useRawInput)
{
XIEventMask em;
unsigned char mask[] = { 0 };
@@ -1183,6 +1183,7 @@ static void processEvent(XEvent *event)
_GLFWwindow* window = _glfw.x11.disabledCursorWindow;
if (window &&
window->useRawInput &&
event->xcookie.extension == _glfw.x11.xi.majorOpcode &&
XGetEventData(_glfw.x11.display, &event->xcookie) &&
event->xcookie.evtype == XI_RawMotion)
@@ -1483,7 +1484,7 @@ static void processEvent(XEvent *event)
{
if (_glfw.x11.disabledCursorWindow != window)
return;
if (_glfw.x11.xi.available)
if (_glfw.x11.xi.available && window->useRawInput)
return;
const int dx = x - window->x11.lastCursorPosX;
@@ -2652,6 +2653,24 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
PropModeReplace, (unsigned char*) &value, 1);
}
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
{
if (window->useRawInput != enabled)
{
int update = (_glfw.x11.disabledCursorWindow == window && _glfw.x11.xi.available);
if (update)
enableCursor(window);
window->useRawInput = enabled;
if (update)
disableCursor(window);
}
}
GLFWbool _glfwPlatformRawInputSupported(void)
{
return _glfw.x11.xi.available;
}
void _glfwPlatformPollEvents(void)
{
_GLFWwindow* window;