get display DPI info to scale mouse movement

This commit is contained in:
Quantum
2021-01-04 16:01:24 -05:00
committed by Geoffrey McRae
parent 0bd5f0b2f1
commit 7e4d323427
10 changed files with 123 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ include_directories(
add_library(lg_common_platform_code STATIC
crash.c
dpi.c
sysinfo.c
thread.c
event.c

View File

@@ -0,0 +1,37 @@
#include "common/dpi.h"
#include "common/windebug.h"
typedef enum MONITOR_DPI_TYPE {
MDT_EFFECTIVE_DPI,
MDT_ANGULAR_DPI,
MDT_RAW_DPI,
MDT_DEFAULT
} MONITOR_DPI_TYPE;
typedef HRESULT (WINAPI *GetDpiForMonitor_t)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT * dpiX, UINT * dpiY);
UINT monitor_dpi(HMONITOR hMonitor)
{
HMODULE shcore = LoadLibraryA("shcore.dll");
if (!shcore)
{
DEBUG_ERROR("Could not load shcore.dll");
return DPI_100_PERCENT;
}
GetDpiForMonitor_t GetDpiForMonitor = (GetDpiForMonitor_t) GetProcAddress(shcore, "GetDpiForMonitor");
if (!GetDpiForMonitor)
{
DEBUG_ERROR("Could not find GetDpiForMonitor");
return DPI_100_PERCENT;
}
UINT dpiX, dpiY;
HRESULT status = GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
if (FAILED(status))
{
DEBUG_WINERROR("GetDpiForMonitor failed", status);
return DPI_100_PERCENT;
}
return dpiX;
}