|
@@ -666,20 +666,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
const int x = GET_X_LPARAM(lParam);
|
|
|
const int y = GET_Y_LPARAM(lParam);
|
|
|
|
|
|
+ // Disabled cursor motion input is provided by WM_INPUT
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
- {
|
|
|
- const int dx = x - window->win32.lastCursorPosX;
|
|
|
- const int dy = y - window->win32.lastCursorPosY;
|
|
|
-
|
|
|
- if (_glfw.win32.disabledCursorWindow != window)
|
|
|
- break;
|
|
|
+ break;
|
|
|
|
|
|
- _glfwInputCursorPos(window,
|
|
|
- window->virtualCursorPosX + dx,
|
|
|
- window->virtualCursorPosY + dy);
|
|
|
- }
|
|
|
- else
|
|
|
- _glfwInputCursorPos(window, x, y);
|
|
|
+ _glfwInputCursorPos(window, x, y);
|
|
|
|
|
|
window->win32.lastCursorPosX = x;
|
|
|
window->win32.lastCursorPosY = y;
|
|
@@ -700,6 +691,56 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ case WM_INPUT:
|
|
|
+ {
|
|
|
+ UINT size;
|
|
|
+ HRAWINPUT ri = (HRAWINPUT) lParam;
|
|
|
+ RAWINPUT* data;
|
|
|
+ int dx, dy;
|
|
|
+
|
|
|
+ // Only process input when disabled cursor mode is applied
|
|
|
+ if (_glfw.win32.disabledCursorWindow != window)
|
|
|
+ break;
|
|
|
+
|
|
|
+ GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
|
|
+ if (size > _glfw.win32.rawInputSize)
|
|
|
+ {
|
|
|
+ free(_glfw.win32.rawInput);
|
|
|
+ _glfw.win32.rawInput = calloc(size, 1);
|
|
|
+ _glfw.win32.rawInputSize = size;
|
|
|
+ }
|
|
|
+
|
|
|
+ size = _glfw.win32.rawInputSize;
|
|
|
+ if (GetRawInputData(ri, RID_INPUT,
|
|
|
+ _glfw.win32.rawInput, &size,
|
|
|
+ sizeof(RAWINPUTHEADER)) == (UINT) -1)
|
|
|
+ {
|
|
|
+ _glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
+ "Win32: Failed to retrieve raw input data");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ data = _glfw.win32.rawInput;
|
|
|
+ if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
|
|
|
+ {
|
|
|
+ dx = data->data.mouse.lLastX - window->win32.lastCursorPosX;
|
|
|
+ dy = data->data.mouse.lLastY - window->win32.lastCursorPosY;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dx = data->data.mouse.lLastX;
|
|
|
+ dy = data->data.mouse.lLastY;
|
|
|
+ }
|
|
|
+
|
|
|
+ _glfwInputCursorPos(window,
|
|
|
+ window->virtualCursorPosX + dx,
|
|
|
+ window->virtualCursorPosY + dy);
|
|
|
+
|
|
|
+ window->win32.lastCursorPosX += dx;
|
|
|
+ window->win32.lastCursorPosY += dy;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
case WM_MOUSELEAVE:
|
|
|
{
|
|
|
window->win32.cursorTracked = GLFW_FALSE;
|
|
@@ -1527,20 +1568,36 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|
|
{
|
|
|
if (mode == GLFW_CURSOR_DISABLED)
|
|
|
{
|
|
|
+ const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
|
|
|
+
|
|
|
_glfw.win32.disabledCursorWindow = window;
|
|
|
_glfwPlatformGetCursorPos(window,
|
|
|
&_glfw.win32.restoreCursorPosX,
|
|
|
&_glfw.win32.restoreCursorPosY);
|
|
|
centerCursor(window);
|
|
|
updateClipRect(window);
|
|
|
+
|
|
|
+ if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
|
|
+ {
|
|
|
+ _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
+ "Win32: Failed to register raw input device");
|
|
|
+ }
|
|
|
}
|
|
|
else if (_glfw.win32.disabledCursorWindow == window)
|
|
|
{
|
|
|
+ const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL };
|
|
|
+
|
|
|
_glfw.win32.disabledCursorWindow = NULL;
|
|
|
updateClipRect(NULL);
|
|
|
_glfwPlatformSetCursorPos(window,
|
|
|
_glfw.win32.restoreCursorPosX,
|
|
|
_glfw.win32.restoreCursorPosY);
|
|
|
+
|
|
|
+ if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
|
|
+ {
|
|
|
+ _glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
+ "Win32: Failed to remove raw input device");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (cursorInClientArea(window))
|