summaryrefslogtreecommitdiff
path: root/alf/alfdpiaware.cpp
blob: de265b7ce778c87fe294b5020bf9aa9439e60989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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:
            //FIXME: per-monitor DPI awareness is broken on ANSI builds
#ifdef UNICODE
            ALF_SetPerMonitorAwareness();
            return;
#endif
        case ALF_DPI_AWARENESS_SYSTEM_AWARE:
            ALF_SetSystemDpiAwareness();
            return;
        default:
            // unaware, or could not set awareness
            return;
    }
}