]> granicus.if.org Git - nethack/commitdiff
Fix panic "Unexpected DpiAwareness state" in Windows 10 for mingw32 version.
authorFeiyun Wang <feiyunw@yahoo.com>
Tue, 25 Jan 2022 02:17:30 +0000 (10:17 +0800)
committernhmall <nhmall@nethack.org>
Thu, 27 Jan 2022 23:33:52 +0000 (18:33 -0500)
sys/windows/win10.c

index 98bd5ae3c756fedd15f182b1acc2d0498d6602cc..6e610d4ea8012b2106cc44c4ad9fad8d869064fe 100644 (file)
@@ -9,6 +9,7 @@
 #include "hack.h"
 
 typedef DPI_AWARENESS_CONTEXT(WINAPI *GetThreadDpiAwarenessContextProc)(VOID);
+typedef DPI_AWARENESS_CONTEXT(WINAPI *SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT);
 typedef BOOL(WINAPI *AreDpiAwarenessContextsEqualProc)(
     DPI_AWARENESS_CONTEXT dpiContextA, DPI_AWARENESS_CONTEXT dpiContextB);
 typedef UINT(WINAPI *GetDpiForWindowProc)(HWND hwnd);
@@ -17,6 +18,7 @@ typedef LONG (WINAPI *GetCurrentPackageFullNameProc)(UINT32 *packageFullNameLeng
 
 typedef struct {
     BOOL Valid;
+    SetThreadDpiAwarenessContextProc SetThreadDpiAwarenessContext;
     GetThreadDpiAwarenessContextProc GetThreadDpiAwarenessContext;
     AreDpiAwarenessContextsEqualProc AreDpiAwarenessContextsEqual;
     GetDpiForWindowProc GetDpiForWindow;
@@ -34,6 +36,10 @@ void win10_init(void)
         if (hUser32 == NULL) 
             panic("Unable to load user32.dll");
 
+        gWin10.SetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "SetThreadDpiAwarenessContext");
+        if (gWin10.SetThreadDpiAwarenessContext == NULL)
+            panic("Unable to get address of SetThreadDpiAwarenessContext()");
+
         gWin10.GetThreadDpiAwarenessContext = (GetThreadDpiAwarenessContextProc) GetProcAddress(hUser32, "GetThreadDpiAwarenessContext");
         if (gWin10.GetThreadDpiAwarenessContext == NULL)
             panic("Unable to get address of GetThreadDpiAwarenessContext()");
@@ -63,6 +69,10 @@ void win10_init(void)
     }
 
     if (gWin10.Valid) {
+        if (!gWin10.SetThreadDpiAwarenessContext(
+                DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2))
+            panic("Unable to set DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2");
+
         if (!gWin10.AreDpiAwarenessContextsEqual(
                 gWin10.GetThreadDpiAwarenessContext(),
                 DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2))