mirror of
https://github.com/glfw/glfw.git
synced 2025-06-08 00:34:56 +00:00
Add better backward compatibility when not remote desktop
This commit is contained in:
parent
d3890d2e0e
commit
152e476adb
@ -431,6 +431,9 @@ typedef struct _GLFWwindowWin32
|
||||
// The last received cursor position, regardless of source
|
||||
int lastCursorPosX, lastCursorPosY;
|
||||
|
||||
// Indicate if the process was started behind Remote Destop
|
||||
BOOL isRemoteSession;
|
||||
|
||||
// An invisible cursor, needed for special cases (see WM_INPUT handler)
|
||||
HCURSOR blankCursor;
|
||||
|
||||
|
@ -236,6 +236,7 @@ static void updateCursorImage(_GLFWwindow* window)
|
||||
else
|
||||
//Connected via Remote Desktop, NULL cursor will present SetCursorPos the move the cursor.
|
||||
//using a blank cursor fix that.
|
||||
//When not via Remote Desktop, win32.blankCursor should be NULL
|
||||
SetCursor(window->win32.blankCursor);
|
||||
}
|
||||
|
||||
@ -428,6 +429,64 @@ static void createBlankCursor(_GLFWwindow* window)
|
||||
|
||||
}
|
||||
|
||||
// Check if the session was started in Remote Desktop
|
||||
// Reference: https://learn.microsoft.com/en-us/windows/win32/termserv/detecting-the-terminal-services-environment
|
||||
static BOOL isCurrentRemoteSession()
|
||||
{
|
||||
BOOL fIsRemoteable = FALSE;
|
||||
|
||||
if (GetSystemMetrics(SM_REMOTESESSION))
|
||||
{
|
||||
fIsRemoteable = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
HKEY hRegKey = NULL;
|
||||
LONG lResult;
|
||||
|
||||
lResult = RegOpenKeyEx(
|
||||
HKEY_LOCAL_MACHINE,
|
||||
TEXT("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\"),
|
||||
0, // ulOptions
|
||||
KEY_READ,
|
||||
&hRegKey
|
||||
);
|
||||
|
||||
if (lResult == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dwGlassSessionId;
|
||||
DWORD cbGlassSessionId = sizeof(dwGlassSessionId);
|
||||
DWORD dwType;
|
||||
|
||||
lResult = RegQueryValueEx(
|
||||
hRegKey,
|
||||
TEXT("GlassSessionId"),
|
||||
NULL, // lpReserved
|
||||
&dwType,
|
||||
(BYTE*)&dwGlassSessionId,
|
||||
&cbGlassSessionId
|
||||
);
|
||||
|
||||
if (lResult == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD dwCurrentSessionId;
|
||||
|
||||
if (ProcessIdToSessionId(GetCurrentProcessId(), &dwCurrentSessionId))
|
||||
{
|
||||
fIsRemoteable = (dwCurrentSessionId != dwGlassSessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hRegKey)
|
||||
{
|
||||
RegCloseKey(hRegKey);
|
||||
}
|
||||
}
|
||||
|
||||
return fIsRemoteable;
|
||||
}
|
||||
|
||||
// Retrieves and translates modifier keys
|
||||
//
|
||||
static int getKeyMods(void)
|
||||
@ -957,6 +1016,9 @@ 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 (window->win32.isRemoteSession)
|
||||
{
|
||||
//Remote Desktop Mode...
|
||||
// As per https://github.com/Microsoft/DirectXTK/commit/ef56b63f3739381e451f7a5a5bd2c9779d2a7555
|
||||
// MOUSE_MOVE_ABSOLUTE is a range from 0 through 65535, based on the screen size.
|
||||
// As far as I can tell, absolute mode only occurs over RDP though.
|
||||
@ -977,6 +1039,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
|
||||
|
||||
dx = pos.x - window->win32.lastCursorPosX;
|
||||
dy = pos.y - window->win32.lastCursorPosY;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Normal mode... We should have the right absolute coords in data.mouse
|
||||
dx = data->data.mouse.lLastX - window->win32.lastCursorPosX;
|
||||
dy = data->data.mouse.lLastY - window->win32.lastCursorPosY;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@ -1484,7 +1553,16 @@ static int createNativeWindow(_GLFWwindow* window,
|
||||
window->win32.transparent = GLFW_TRUE;
|
||||
}
|
||||
|
||||
//Check if the current progress was started with Remote Desktop.
|
||||
window->win32.isRemoteSession = isCurrentRemoteSession();
|
||||
|
||||
//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 (window->win32.isRemoteSession)
|
||||
{
|
||||
createBlankCursor(window);
|
||||
}
|
||||
|
||||
_glfwGetWindowSizeWin32(window, &window->win32.width, &window->win32.height);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user