diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-28 21:40:36 +0100 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-28 21:40:36 +0100 |
| commit | 416fe35c67352dd23ad698d8f732545caee3d82d (patch) | |
| tree | 3a328b3e30d8ed0048fa342547efab413e971872 /alf/alfdpiaware.cpp | |
| parent | a5f3ea9ac12fccbc9faf3f152d4dfbe7f263268e (diff) | |
add per-monitor dpi support
Diffstat (limited to 'alf/alfdpiaware.cpp')
| -rw-r--r-- | alf/alfdpiaware.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/alf/alfdpiaware.cpp b/alf/alfdpiaware.cpp new file mode 100644 index 0000000..8f998f7 --- /dev/null +++ b/alf/alfdpiaware.cpp @@ -0,0 +1,46 @@ +#include "alfpriv.h" + +typedef BOOL (WINAPI *PSetProcessDpiAwarenessContext)(HANDLE); +typedef BOOL (WINAPI *PSetProcessDPIAware)(void); + +static void +ALF_SetSystemDpiAwareness(void) +{ + HMODULE user32 = GetModuleHandleA("user32.dll"); + + PSetProcessDPIAware p = (PSetProcessDPIAware) + (void*)GetProcAddress(user32, "SetProcessDPIAware"); + if (p) { + p(); + } +} + +static void +ALF_SetPerMonitorAwareness(void) +{ + HMODULE user32 = GetModuleHandleA("user32.dll"); + + PSetProcessDpiAwarenessContext p = (PSetProcessDpiAwarenessContext) + (void*)GetProcAddress(user32, "SetProcessDpiAwarenessContext"); + + if (p && p((HANDLE)-4)) /* DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 */ + return; + + ALF_SetSystemDpiAwareness(); +} + +void +ALF_SetDpiAwareness(ALFDpiAwareness awareness) +{ + switch (awareness) { + case ALF_DPI_AWARENESS_PER_MONITOR_AWARE_V2: + ALF_SetPerMonitorAwareness(); + return; + case ALF_DPI_AWARENESS_SYSTEM_AWARE: + ALF_SetSystemDpiAwareness(); + return; + default: + // unaware, or could not set awareness + return; + } +} |
