mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +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
|
||||
|
||||
@@ -34,8 +34,8 @@ limitations under the License.
|
||||
#include "microstack/ILibParsers.h"
|
||||
#include "microstack/ILibCrypto.h"
|
||||
#include "meshcore/agentcore.h"
|
||||
|
||||
#include "microscript/ILibDuktape_ScriptContainer.h"
|
||||
#include <shellscalingapi.h>
|
||||
|
||||
#ifndef _MINCORE
|
||||
// #include "../kvm/kvm.h"
|
||||
@@ -984,10 +984,32 @@ int main(int argc, char* argv[])
|
||||
|
||||
#if defined(_LINKVM)
|
||||
if (argc > 1 && strcasecmp(argv[1], "-kvm0") == 0)
|
||||
{
|
||||
{
|
||||
void **parm = (void**)ILibMemory_Allocate(3 * sizeof(void*), 0, 0, NULL);
|
||||
parm[0] = kvm_serviceWriteSink;
|
||||
((int*)&(parm[2]))[0] = 0;
|
||||
|
||||
HMODULE shCORE = LoadLibraryExA((LPCSTR)"Shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
DpiAwarenessFunc dpiAwareness = NULL;
|
||||
if (shCORE != NULL)
|
||||
{
|
||||
if ((dpiAwareness = (DpiAwarenessFunc)GetProcAddress(shCORE, (LPCSTR)"SetProcessDpiAwareness")) == NULL)
|
||||
{
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
}
|
||||
if (dpiAwareness != NULL)
|
||||
{
|
||||
dpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
}
|
||||
|
||||
kvm_server_mainloop((void*)parm);
|
||||
return 0;
|
||||
}
|
||||
@@ -996,6 +1018,29 @@ int main(int argc, char* argv[])
|
||||
void **parm = (void**)ILibMemory_Allocate(3 * sizeof(void*), 0, 0, NULL);
|
||||
parm[0] = kvm_serviceWriteSink;
|
||||
((int*)&(parm[2]))[0] = 1;
|
||||
|
||||
HMODULE shCORE = LoadLibraryExA((LPCSTR)"Shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
DpiAwarenessFunc dpiAwareness = NULL;
|
||||
if (shCORE != NULL)
|
||||
{
|
||||
if ((dpiAwareness = (DpiAwarenessFunc)GetProcAddress(shCORE, (LPCSTR)"SetProcessDpiAwareness")) == NULL)
|
||||
{
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
}
|
||||
if (dpiAwareness != NULL)
|
||||
{
|
||||
dpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
FreeLibrary(shCORE);
|
||||
shCORE = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
}
|
||||
|
||||
|
||||
kvm_server_mainloop((void*)parm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
||||
<dpiAware>true</dpiAware>
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user