From d93868bcf3be1b585dd60205feb340a9cfa59772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 7 Feb 2024 00:59:58 +0100 Subject: [PATCH] Win32: Fix handling of local absolute raw motion The implementation for how to handle absolute raw motion remotely is just how to handle absolute raw motion, period. --- src/win32_init.c | 3 --- src/win32_platform.h | 2 -- src/win32_window.c | 46 +++++++++++++++++--------------------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/win32_init.c b/src/win32_init.c index 4a75cce6..824e383c 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -698,9 +698,6 @@ int _glfwInitWin32(void) if (!createHelperWindow()) return GLFW_FALSE; - // Check if the current process was started via Remote Desktop - _glfw.win32.isRemoteSession = GetSystemMetrics(SM_REMOTESESSION) > 0; - _glfwPollMonitorsWin32(); return GLFW_TRUE; } diff --git a/src/win32_platform.h b/src/win32_platform.h index 43ab3232..feecb753 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -458,8 +458,6 @@ typedef struct _GLFWlibraryWin32 RAWINPUT* rawInput; int rawInputSize; UINT mouseTrailSize; - // Indicate if the process was started behind Remote Destop - BOOL isRemoteSession; // The cursor handle to use to hide the cursor (NULL or a transparent cursor) HCURSOR blankCursor; diff --git a/src/win32_window.c b/src/win32_window.c index d522e788..e6a9496c 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -929,38 +929,28 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l data = _glfw.win32.rawInput; if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) { - if (_glfw.win32.isRemoteSession) + POINT pos = {0}; + int width, height; + + if (data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) { - // NOTE: According to DirectXTK, when running via Remote Desktop, raw - // mouse motion is provided as MOUSE_MOVE_ABSOLUTE and - // MOUSE_VIRTUAL_DESKTOP. - - int width, height; - - if (data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) - { - width = GetSystemMetrics(SM_CXVIRTUALSCREEN); - height = GetSystemMetrics(SM_CYVIRTUALSCREEN); - } - else - { - width = GetSystemMetrics(SM_CXSCREEN); - height = GetSystemMetrics(SM_CYSCREEN); - } - - POINT pos; - pos.x = (int) ((data->data.mouse.lLastX / 65535.f) * width); - pos.y = (int) ((data->data.mouse.lLastY / 65535.f) * height); - ScreenToClient(window->win32.handle, &pos); - - dx = pos.x - window->win32.lastCursorPosX; - dy = pos.y - window->win32.lastCursorPosY; + pos.x += GetSystemMetrics(SM_XVIRTUALSCREEN); + pos.y += GetSystemMetrics(SM_YVIRTUALSCREEN); + width = GetSystemMetrics(SM_CXVIRTUALSCREEN); + height = GetSystemMetrics(SM_CYVIRTUALSCREEN); } else { - dx = data->data.mouse.lLastX - window->win32.lastCursorPosX; - dy = data->data.mouse.lLastY - window->win32.lastCursorPosY; + width = GetSystemMetrics(SM_CXSCREEN); + height = GetSystemMetrics(SM_CYSCREEN); } + + pos.x += (int) ((data->data.mouse.lLastX / 65535.f) * width); + pos.y += (int) ((data->data.mouse.lLastY / 65535.f) * height); + ScreenToClient(window->win32.handle, &pos); + + dx = pos.x - window->win32.lastCursorPosX; + dy = pos.y - window->win32.lastCursorPosY; } else { @@ -1324,7 +1314,7 @@ static int createNativeWindow(_GLFWwindow* window, } } - if (_glfw.win32.isRemoteSession) + if (GetSystemMetrics(SM_REMOTESESSION)) { // NOTE: On Remote Desktop, setting the cursor to NULL does not hide it // HACK: Create a transparent cursor and always set that instead of NULL