Win 32: Fix disabled cursor mode when connected over RDP

Fixes #1276
Based on PR #1279 by @Pokechu22

Co-authored-by: Pokechu22 <8334194+Pokechu22@users.noreply.github.com>
This commit is contained in:
Hilderin
2024-01-28 12:08:27 -05:00
committed by GitHub
parent 8e6c8d7eff
commit c8521b7fda
5 changed files with 90 additions and 4 deletions
+48
View File
@@ -430,6 +430,47 @@ static GLFWbool createHelperWindow(void)
return GLFW_TRUE;
}
// Creates the blank cursor
//
static void createBlankCursor(void)
{
// HACK: Create a transparent cursor as using the NULL cursor breaks
// using SetCursorPos when connected over RDP
int cursorWidth = GetSystemMetrics(SM_CXCURSOR);
int cursorHeight = GetSystemMetrics(SM_CYCURSOR);
unsigned char* andMask = calloc(cursorWidth * cursorHeight / 8, sizeof(unsigned char));
unsigned char* xorMask = calloc(cursorWidth * cursorHeight / 8, sizeof(unsigned char));
if (andMask != NULL && xorMask != NULL) {
memset(andMask, 0xFF, (size_t)(cursorWidth * cursorHeight / 8));
// Cursor creation might fail, but that's fine as we get NULL in that case,
// which serves as an acceptable fallback blank cursor (other than on RDP)
_glfw.win32.blankCursor = CreateCursor(NULL, 0, 0, cursorWidth, cursorHeight, andMask, xorMask);
free(andMask);
free(xorMask);
}
}
// Initialize for remote sessions
//
static void initRemoteSession(void)
{
//Check if the current progress was started with Remote Desktop.
_glfw.win32.isRemoteSession = GetSystemMetrics(SM_REMOTESESSION) > 0;
// With Remote desktop, we need to create a blank cursor because of the cursor is Set to NULL
// if cannot be moved to center in capture mode. If not Remote Desktop win32.blankCursor stays NULL
// and will perform has before (normal).
if (_glfw.win32.isRemoteSession)
{
createBlankCursor();
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
@@ -699,12 +740,19 @@ int _glfwInitWin32(void)
if (!createHelperWindow())
return GLFW_FALSE;
//Some hacks are needed to support Remote Desktop...
initRemoteSession();
_glfwPollMonitorsWin32();
return GLFW_TRUE;
}
void _glfwTerminateWin32(void)
{
if (_glfw.win32.blankCursor)
DestroyCursor(_glfw.win32.blankCursor);
if (_glfw.win32.deviceNotificationHandle)
UnregisterDeviceNotification(_glfw.win32.deviceNotificationHandle);