Skip to content

Commit 45376b1

Browse files
authored
Merge pull request #86 from nut-tree/bugfix/249/scaling_issues
(nut-tree/nut.js#249) Enable DPI awareness when fetching screen conte…
2 parents b166997 + e93d1f0 commit 45376b1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: src/win32/screengrab.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
#include <stdlib.h> /* malloc() */
44

55
MMRect getScaledRect(MMRect input, HDC imageSource) {
6-
BITMAP structBitmapHeader;
7-
memset( &structBitmapHeader, 0, sizeof(BITMAP) );
8-
9-
HGDIOBJ hBitmap = GetCurrentObject(imageSource, OBJ_BITMAP);
10-
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);
11-
6+
// Configure DPI awareness to fetch unscaled display size
7+
DPI_AWARENESS_CONTEXT initialDpiAwareness = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
8+
size_t scaledDesktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
9+
size_t scaledDesktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
10+
// Reset DPI awareness to avoid inconsistencies on future calls to copyMMBitmapFromDisplayInRect
11+
SetThreadDpiAwarenessContext(initialDpiAwareness);
1212
size_t desktopWidth = (size_t)GetSystemMetrics(SM_CXSCREEN);
1313
size_t desktopHeight = (size_t)GetSystemMetrics(SM_CYSCREEN);
1414

15-
double scaleX = (double)(structBitmapHeader.bmWidth / desktopWidth);
16-
double scaleY = (double)(structBitmapHeader.bmHeight / desktopHeight);
15+
double scaleX = (double)(desktopWidth / (double)scaledDesktopWidth);
16+
double scaleY = (double)(desktopHeight / (double)scaledDesktopHeight);
1717

1818
return MMRectMake(input.origin.x, input.origin.y, input.size.width * scaleX, input.size.height * scaleY);
1919
}

0 commit comments

Comments
 (0)