From 416fe35c67352dd23ad698d8f732545caee3d82d Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Fri, 28 Dec 2018 21:40:36 +0100 Subject: add per-monitor dpi support --- alf/alfdpiaware.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 alf/alfdpiaware.cpp (limited to 'alf/alfdpiaware.cpp') 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; + } +} -- cgit v1.2.3