Skip to content

Commit

Permalink
win32: fix detection of the "multimonitor aware" HiDPI mode on Window…
Browse files Browse the repository at this point in the history
…s 8.1 [p=2724812]
  • Loading branch information
cfillion committed Oct 24, 2023
1 parent 220656b commit a3b09e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions src/win32_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "win32_window.hpp"

#include <imgui/imgui.h>
#include <shellscalingapi.h> // GetProcessDpiAwareness for Windows 8.1

// Windows 10 Anniversary Update (1607) and newer
static FuncImport<decltype(SetThreadDpiAwarenessContext)>
Expand Down Expand Up @@ -53,19 +54,31 @@ static bool isPerMonitorDpiAware()
return *result;

// Windows 10 Anniversary Update (1607) and newer
static FuncImport<decltype(GetThreadDpiAwarenessContext)>
FuncImport<decltype(GetThreadDpiAwarenessContext)>
_GetThreadDpiAwarenessContext
{ L"User32.dll", "GetThreadDpiAwarenessContext" };
static FuncImport<decltype(GetAwarenessFromDpiAwarenessContext)>
FuncImport<decltype(GetAwarenessFromDpiAwarenessContext)>
_GetAwarenessFromDpiAwarenessContext
{ L"User32.dll", "GetAwarenessFromDpiAwarenessContext" };
if(_GetThreadDpiAwarenessContext && _GetAwarenessFromDpiAwarenessContext) {
const DPI_AWARENESS_CONTEXT context { _GetThreadDpiAwarenessContext() };
const DPI_AWARENESS awareness { _GetAwarenessFromDpiAwarenessContext(context) };
result = awareness == DPI_AWARENESS_PER_MONITOR_AWARE;
return *result;
}

if(!_GetThreadDpiAwarenessContext || !_GetAwarenessFromDpiAwarenessContext)
return false;
// Windows 8.1
FuncImport<decltype(GetProcessDpiAwareness)>
_GetProcessDpiAwareness { L"Shcore.dll", "GetProcessDpiAwareness" };
if(_GetProcessDpiAwareness) {
PROCESS_DPI_AWARENESS awareness {};
if(FAILED(_GetProcessDpiAwareness(nullptr, &awareness)))
return false;
result = awareness == PROCESS_PER_MONITOR_DPI_AWARE;
return *result;
}

const DPI_AWARENESS_CONTEXT context { _GetThreadDpiAwarenessContext() };
const DPI_AWARENESS awareness { _GetAwarenessFromDpiAwarenessContext(context) };
result = awareness == DPI_AWARENESS_PER_MONITOR_AWARE;
result = false;
return *result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "win32_unicode.hpp"

#include <reaper_plugin_secrets.h>
#include <ShellScalingApi.h> // GetDpiForMonitor
#include <shellscalingapi.h> // GetDpiForMonitor
#define GetThemeColor Win32_GetThemeColor // solve conflict with REAPER API
#include <dwmapi.h> // Dwm* functions for compositing
#undef GetThemeColor
Expand Down

0 comments on commit a3b09e1

Please sign in to comment.