mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-04 17:43:45 +00:00
Fixed Windows KVM bug when you have multiple displays with differing DPI settings
This commit is contained in:
@@ -131,64 +131,6 @@ void kvm_slave_OnRawForwardLog(ILibRemoteLogging sender, ILibRemoteLogging_Modul
|
||||
}
|
||||
#endif
|
||||
|
||||
void kvm_inspect_displays(RECT* r, int rLen)
|
||||
{
|
||||
MONITORINFOEX minfo;
|
||||
HMONITOR hmon;
|
||||
POINT p;
|
||||
int deviceid;
|
||||
int vx = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
||||
int vy = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
||||
int vw = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
||||
int vh = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
||||
|
||||
memset(r, 0, sizeof(RECT)*rLen);
|
||||
|
||||
for (p.y = vy; p.y < (vy + vh); ++p.y)
|
||||
{
|
||||
for (p.x = vx; p.x < (vx + vw); ++p.x)
|
||||
{
|
||||
hmon = MonitorFromPoint(p, MONITOR_DEFAULTTONULL);
|
||||
if (hmon != NULL)
|
||||
{
|
||||
memset(&minfo, 0, sizeof(minfo));
|
||||
minfo.cbSize = sizeof(minfo);
|
||||
GetMonitorInfoA(hmon, &minfo);
|
||||
sscanf_s(minfo.szDevice, "\\\\.\\DISPLAY%d", &deviceid);
|
||||
|
||||
if (r[deviceid].left == r[deviceid].right)
|
||||
{
|
||||
// Not set yet
|
||||
r[deviceid].left = p.x;
|
||||
r[deviceid].right = p.x - 1;
|
||||
}
|
||||
else if (r[deviceid].right < p.x)
|
||||
{
|
||||
// Determining Width
|
||||
r[deviceid].right = p.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already determined width, so we can FFWD
|
||||
p.x = r[deviceid].right;
|
||||
}
|
||||
if (r[deviceid].top == r[deviceid].bottom)
|
||||
{
|
||||
// Not set yet
|
||||
r[deviceid].top = p.y;
|
||||
r[deviceid].bottom = p.y - 1;
|
||||
}
|
||||
else if (r[deviceid].bottom < p.y)
|
||||
{
|
||||
// Determining Heigth
|
||||
r[deviceid].bottom = p.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void kvm_setupSasPermissions()
|
||||
{
|
||||
DWORD dw = 3;
|
||||
@@ -844,6 +786,7 @@ DWORD WINAPI kvm_server_mainloop(LPVOID parm)
|
||||
ILibKVM_WriteHandler writeHandler = (ILibKVM_WriteHandler)((void**)parm)[0];
|
||||
void *reserved = ((void**)parm)[1];
|
||||
|
||||
|
||||
#ifdef _WINSERVICE
|
||||
if (!kvmConsoleMode)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,6 @@ limitations under the License.
|
||||
|
||||
typedef ILibTransport_DoneState(*ILibKVM_WriteHandler)(char *buffer, int bufferLen, void *reserved);
|
||||
|
||||
void kvm_inspect_displays(RECT* r, int rLen);
|
||||
int kvm_relay_feeddata(char* buf, int len, ILibKVM_WriteHandler writeHandler, void *reserved);
|
||||
void kvm_pause(int pause);
|
||||
int kvm_relay_setup(char* exePath, void *processPipeMgr, ILibKVM_WriteHandler writeHandler, void *reserved);
|
||||
|
||||
@@ -20,6 +20,7 @@ limitations under the License.
|
||||
#include <Windows.h>
|
||||
#include <WinBase.h>
|
||||
#include "wincrypto.h"
|
||||
#include <shellscalingapi.h>
|
||||
#endif
|
||||
|
||||
#include "agentcore.h"
|
||||
@@ -3566,6 +3567,15 @@ MeshAgentHostContainer* MeshAgent_Create(MeshCommand_AuthInfo_CapabilitiesMask c
|
||||
MeshAgentHostContainer* retVal = (MeshAgentHostContainer*)ILibMemory_Allocate(sizeof(MeshAgentHostContainer), 0, NULL, NULL);
|
||||
#ifdef WIN32
|
||||
SYSTEM_POWER_STATUS stats;
|
||||
|
||||
if ((retVal->shCore = (void*)LoadLibraryExA((LPCSTR)"Shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)) != NULL)
|
||||
{
|
||||
if ((retVal->dpiAwareness = (void*)GetProcAddress((HMODULE)retVal->shCore, (LPCSTR)"SetProcessDpiAwareness")) == NULL)
|
||||
{
|
||||
FreeLibrary(retVal->shCore);
|
||||
retVal->shCore = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
retVal->agentID = (AgentIdentifiers)MESH_AGENTID;
|
||||
@@ -4445,7 +4455,15 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && defined(_LINKVM) && !defined(WINSERVICE)
|
||||
SetProcessDPIAware();
|
||||
if (agentHost->dpiAwareness != NULL)
|
||||
{
|
||||
printf("Setting DPIAwareness to per monitor\n");
|
||||
agentHost->dpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((paramLen == 1 && strcmp(param[0], "--slave") == 0) || (paramLen == 2 && strcmp(param[1], "--slave") == 0)) { MeshAgent_Slave(agentHost); return 0; }
|
||||
@@ -4660,6 +4678,12 @@ void MeshAgent_Destroy(MeshAgentHostContainer* agent)
|
||||
|
||||
if (agent->masterDb != NULL) { ILibSimpleDataStore_Close(agent->masterDb); agent->masterDb = NULL; }
|
||||
if (agent->chain != NULL) { ILibChain_DestroyEx(agent->chain); agent->chain = NULL; }
|
||||
#ifdef WIN32
|
||||
if (agent->shCore != NULL)
|
||||
{
|
||||
FreeLibrary((HMODULE)agent->shCore);
|
||||
}
|
||||
#endif
|
||||
free(agent);
|
||||
}
|
||||
void MeshAgent_Stop(MeshAgentHostContainer *agent)
|
||||
|
||||
@@ -139,6 +139,10 @@ typedef enum MeshAgentHost_BatteryInfo
|
||||
|
||||
extern char* MeshAgentHost_BatteryInfo_STRINGS[];
|
||||
|
||||
#ifdef WIN32
|
||||
typedef HRESULT (*DpiAwarenessFunc)(PROCESS_DPI_AWARENESS);
|
||||
#endif
|
||||
|
||||
typedef struct MeshAgentHostContainer
|
||||
{
|
||||
void* chain;
|
||||
@@ -156,6 +160,11 @@ typedef struct MeshAgentHostContainer
|
||||
ILibWebClient_StateObject controlChannel;
|
||||
struct sockaddr_in6* proxyServer;
|
||||
|
||||
#ifdef WIN32
|
||||
void *shCore;
|
||||
DpiAwarenessFunc dpiAwareness;
|
||||
#endif
|
||||
|
||||
int localScript;
|
||||
int version;
|
||||
int capabilities; // Extra agent capabilities indicated to the server from MeshCommand_AuthInfo_CapabilitiesMask
|
||||
|
||||
Reference in New Issue
Block a user