Skip to content

Commit 9bbea6a

Browse files
committedSep 29, 2022
(#136) Limit calls to SetThreadDpiAwarenessContext to Windows 10 clients
1 parent c5ca716 commit 9bbea6a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

Diff for: ‎src/win32/screengrab.cc

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#include "../screengrab.h"
22
#include "../endian.h"
3+
#include <VersionHelpers.h>
34

45
MMRect getScaledRect(MMRect input)
56
{
6-
// Configure DPI awareness to fetch unscaled display size
7-
DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
87
size_t scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
98
size_t scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
10-
// Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect
11-
SetThreadDpiAwarenessContext(initialDpiAwareness);
9+
// Configure DPI awareness to fetch unscaled display size
10+
if (IsWindows10OrGreater() && !IsWindowsServer()) {
11+
// Re-query desktop dimensions after setting the DPI awareness context
12+
// Only to this on Windows 10 client platforms, since earlier versions of Windows and Windows Server do not support this call
13+
DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
14+
scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
15+
scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
16+
// Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect
17+
SetThreadDpiAwarenessContext(initialDpiAwareness);
18+
}
1219
size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
1320
size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
1421

0 commit comments

Comments
 (0)