|
1 | 1 | #include "../screengrab.h" |
2 | 2 | #include "../endian.h" |
3 | 3 | #include <stdlib.h> /* malloc() */ |
| 4 | +#include <VersionHelpers.h> |
4 | 5 |
|
5 | 6 | MMRect getScaledRect(MMRect input) |
6 | 7 | { |
7 | | - // Configure DPI awareness to fetch unscaled display size |
8 | | - DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); |
9 | 8 | size_t scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN); |
10 | 9 | size_t scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN); |
11 | | - // Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect |
12 | | - SetThreadDpiAwarenessContext(initialDpiAwareness); |
| 10 | + // Configure DPI awareness to fetch unscaled display size |
| 11 | + if (IsWindows10OrGreater() && !IsWindowsServer()) { |
| 12 | + // Re-query desktop dimensions after setting the DPI awareness context |
| 13 | + // Only to this on Windows 10 client platforms, since earlier versions of Windows and Windows Server do not support this call |
| 14 | + DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); |
| 15 | + scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN); |
| 16 | + scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN); |
| 17 | + // Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect |
| 18 | + SetThreadDpiAwarenessContext(initialDpiAwareness); |
| 19 | + } |
13 | 20 | size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN); |
14 | 21 | size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN); |
15 | 22 |
|
16 | 23 | double scaleX = (double)(desktopWidth / (double)scaledDesktopWidth); |
17 | 24 | double scaleY = (double)(desktopHeight / (double)scaledDesktopHeight); |
18 | 25 |
|
19 | 26 | return MMRectMake( |
20 | | - input.origin.x / scaleX, |
21 | | - input.origin.y / scaleY, |
22 | | - input.size.width / scaleX, |
| 27 | + input.origin.x / scaleX, |
| 28 | + input.origin.y / scaleY, |
| 29 | + input.size.width / scaleX, |
23 | 30 | input.size.height / scaleY |
24 | 31 | ); |
25 | 32 | } |
|
0 commit comments