get display DPI info to scale mouse movement

This commit is contained in:
Quantum authored and Geoffrey McRae committed 2021-01-05 09:03:29 +11:00
1 parent 0bd5f0b2f1
commit 7e4d323427
10 files changed
+123 -36

No files matched your search

@@ -7,6 +7,7 @@ include_directories(
add_library(lg_common_platform_code STATIC
crash.c
dpi.c
sysinfo.c
thread.c
event.c
+37
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;
}