Support useRawInput option on windows

This commit is contained in:
Nathan Poirier 2018-12-14 03:34:30 +01:00
parent ec6eb3cb83
commit ac55b04da2
No known key found for this signature in database
GPG Key ID: 94C1CE923BD6A70C

View File

@ -290,7 +290,7 @@ static void disableCursor(_GLFWwindow* window)
centerCursor(window); centerCursor(window);
updateClipRect(window); updateClipRect(window);
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) if (window->useRawInput && !RegisterRawInputDevices(&rid, 1, sizeof(rid)))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to register raw input device"); "Win32: Failed to register raw input device");
@ -310,7 +310,7 @@ static void enableCursor(_GLFWwindow* window)
_glfw.win32.restoreCursorPosY); _glfw.win32.restoreCursorPosY);
updateCursorImage(window); updateCursorImage(window);
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) if (window->useRawInput && !RegisterRawInputDevices(&rid, 1, sizeof(rid)))
{ {
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR, _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
"Win32: Failed to remove raw input device"); "Win32: Failed to remove raw input device");
@ -825,8 +825,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// Disabled cursor motion input is provided by WM_INPUT // Disabled cursor motion input is provided by WM_INPUT
if (window->cursorMode == GLFW_CURSOR_DISABLED) if (window->cursorMode == GLFW_CURSOR_DISABLED)
{
if (_glfw.win32.disabledCursorWindow != window || window->useRawInput)
break; break;
const int dx = x - window->win32.lastCursorPosX;
const int dy = y - window->win32.lastCursorPosY;
_glfwInputCursorPos(window,
window->virtualCursorPosX + dx,
window->virtualCursorPosY + dy);
}
else
_glfwInputCursorPos(window, x, y); _glfwInputCursorPos(window, x, y);
window->win32.lastCursorPosX = x; window->win32.lastCursorPosX = x;
@ -856,7 +865,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
int dx, dy; int dx, dy;
// Only process input when disabled cursor mode is applied // Only process input when disabled cursor mode is applied
if (_glfw.win32.disabledCursorWindow != window) if (_glfw.win32.disabledCursorWindow != window || !window->useRawInput)
break; break;
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
@ -1845,8 +1854,15 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled) void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
{ {
if (window->useRawInput != enabled)
{
int update = (_glfw.win32.disabledCursorWindow == window);
if (update)
enableCursor(window);
window->useRawInput = enabled; window->useRawInput = enabled;
// TODO if (update)
disableCursor(window);
}
} }
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)