Skip to content

Commit

Permalink
Use DPI awareness from window
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 5, 2024
1 parent 28e5b92 commit 9622266
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ PyImaging_DisplayModeWin32(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */
/* Windows screen grabber */

typedef HANDLE(__stdcall *Func_GetWindowDpiAwarenessContext)(HANDLE);
typedef HANDLE(__stdcall *Func_SetThreadDpiAwarenessContext)(HANDLE);

PyObject *
Expand All @@ -330,6 +331,7 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
PyObject *buffer;
HANDLE dpiAwareness;
HMODULE user32;
Func_GetWindowDpiAwarenessContext GetWindowDpiAwarenessContext_function;
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;

if (!PyArg_ParseTuple(
Expand Down Expand Up @@ -358,8 +360,19 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
SetThreadDpiAwarenessContext_function = (Func_SetThreadDpiAwarenessContext
)GetProcAddress(user32, "SetThreadDpiAwarenessContext");
if (SetThreadDpiAwarenessContext_function != NULL) {
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE)-3);
if (screens == -1) {
GetWindowDpiAwarenessContext_function = (Func_GetWindowDpiAwarenessContext
)GetProcAddress(user32, "GetWindowDpiAwarenessContext");
DPI_AWARENESS_CONTEXT dpiAwarenessContext =
GetWindowDpiAwarenessContext_function(wnd);
if (dpiAwarenessContext != NULL) {
dpiAwareness =
SetThreadDpiAwarenessContext_function(dpiAwarenessContext);
}
} else {
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE)-3);
}
}

if (screens == 1) {
Expand Down

0 comments on commit 9622266

Please sign in to comment.