Win32: Clean up RDP hidden cursor workaround

This commit is contained in:
Camilla Löwy 2024-02-07 00:31:19 +01:00
parent 6c1e3fd84c
commit 275b92f887
2 changed files with 26 additions and 16 deletions

View File

@ -460,7 +460,7 @@ typedef struct _GLFWlibraryWin32
UINT mouseTrailSize; UINT mouseTrailSize;
// Indicate if the process was started behind Remote Destop // Indicate if the process was started behind Remote Destop
BOOL isRemoteSession; BOOL isRemoteSession;
// An invisible cursor, needed for special cases (see WM_INPUT handler) // The cursor handle to use to hide the cursor (NULL or a transparent cursor)
HCURSOR blankCursor; HCURSOR blankCursor;
struct { struct {

View File

@ -232,10 +232,12 @@ static void updateCursorImage(_GLFWwindow* window)
SetCursor(LoadCursorW(NULL, IDC_ARROW)); SetCursor(LoadCursorW(NULL, IDC_ARROW));
} }
else else
//Connected via Remote Desktop, NULL cursor will present SetCursorPos the move the cursor. {
//using a blank cursor fix that. // NOTE: Via Remote Desktop, setting the cursor to NULL does not hide it.
//When not via Remote Desktop, win32.blankCursor should be NULL // HACK: When running locally, it is set to NULL, but when connected via Remote
// Desktop, this is a transparent cursor.
SetCursor(_glfw.win32.blankCursor); SetCursor(_glfw.win32.blankCursor);
}
} }
// Sets the cursor clip rect to the window content area // Sets the cursor clip rect to the window content area
@ -900,8 +902,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
HRAWINPUT ri = (HRAWINPUT) lParam; HRAWINPUT ri = (HRAWINPUT) lParam;
RAWINPUT* data = NULL; RAWINPUT* data = NULL;
int dx, dy; int dx, dy;
int width, height;
POINT pos;
if (_glfw.win32.disabledCursorWindow != window) if (_glfw.win32.disabledCursorWindow != window)
break; break;
@ -931,15 +931,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
{ {
if (_glfw.win32.isRemoteSession) if (_glfw.win32.isRemoteSession)
{ {
//Remote Desktop Mode... // NOTE: According to DirectXTK, when running via Remote Desktop, raw
// As per https://github.com/Microsoft/DirectXTK/commit/ef56b63f3739381e451f7a5a5bd2c9779d2a7555 // mouse motion is provided as MOUSE_MOVE_ABSOLUTE and
// MOUSE_MOVE_ABSOLUTE is a range from 0 through 65535, based on the screen size. // MOUSE_VIRTUAL_DESKTOP.
// As far as I can tell, absolute mode only occurs over RDP though.
width = GetSystemMetrics((data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) ? SM_CXVIRTUALSCREEN : SM_CXSCREEN);
height = GetSystemMetrics((data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP) ? SM_CYVIRTUALSCREEN : SM_CYSCREEN);
pos.x = (int)((data->data.mouse.lLastX / 65535.0f) * width); int width, height;
pos.y = (int)((data->data.mouse.lLastY / 65535.0f) * 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); ScreenToClient(window->win32.handle, &pos);
dx = pos.x - window->win32.lastCursorPosX; dx = pos.x - window->win32.lastCursorPosX;
@ -947,7 +958,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
} }
else else
{ {
//Normal mode... We should have the right absolute coords in data.mouse
dx = data->data.mouse.lLastX - window->win32.lastCursorPosX; dx = data->data.mouse.lLastX - window->win32.lastCursorPosX;
dy = data->data.mouse.lLastY - window->win32.lastCursorPosY; dy = data->data.mouse.lLastY - window->win32.lastCursorPosY;
} }