diff --git a/README.md b/README.md index f229bc37..aeeca6cf 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ used by the tests and examples and are not required to build the library. - Added `GLFW_CONTEXT_NO_ERROR` context hint for `GL_KHR_no_error` support - Added `GLFW_TRUE` and `GLFW_FALSE` as client API independent boolean values - Removed dependency on external OpenGL or OpenGL ES headers + - [Win32] Added support for Windows 8.1 per-monitor DPI - [Cocoa] Removed support for OS X 10.6 - [X11] Bugfix: Monitor connection and disconnection events were not reported - [X11] Bugfix: Decoding of UTF-8 text from XIM could continue past the end diff --git a/src/win32_init.c b/src/win32_init.c index cd749b40..3831a76d 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -99,6 +99,13 @@ static GLFWbool initLibraries(void) GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush"); } + _glfw.win32.shcore.instance = LoadLibraryW(L"shcore.dll"); + if (_glfw.win32.shcore.instance) + { + _glfw.win32.shcore.SetProcessDPIAwareness = (SETPROCESSDPIAWARENESS_T) + GetProcAddress(_glfw.win32.shcore.instance, "SetProcessDPIAwareness"); + } + return GLFW_TRUE; } @@ -114,6 +121,9 @@ static void terminateLibraries(void) if (_glfw.win32.dwmapi.instance) FreeLibrary(_glfw.win32.dwmapi.instance); + + if (_glfw.win32.shcore.instance) + FreeLibrary(_glfw.win32.shcore.instance); } // Create key code translation tables @@ -328,7 +338,9 @@ int _glfwPlatformInit(void) createKeyTables(); - if (_glfw_SetProcessDPIAware) + if (_glfw_SetProcessDPIAwareness) + _glfw_SetProcessDPIAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + else if (_glfw_SetProcessDPIAware) _glfw_SetProcessDPIAware(); if (!_glfwRegisterWindowClass()) diff --git a/src/win32_platform.h b/src/win32_platform.h index d1f17ac9..718f5a1e 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -86,6 +86,9 @@ #ifndef UNICODE_NOCHAR #define UNICODE_NOCHAR 0xFFFF #endif +#ifndef WM_DPICHANGED + #define WM_DPICHANGED 0x02E0 +#endif #if WINVER < 0x0601 typedef struct tagCHANGEFILTERSTRUCT @@ -99,6 +102,15 @@ typedef struct tagCHANGEFILTERSTRUCT #endif #endif /*Windows 7*/ +#ifndef DPI_ENUMS_DECLARED +typedef enum PROCESS_DPI_AWARENESS +{ + PROCESS_DPI_UNAWARE = 0, + PROCESS_SYSTEM_DPI_AWARE = 1, + PROCESS_PER_MONITOR_DPI_AWARE = 2 +} PROCESS_DPI_AWARENESS; +#endif /*DPI_ENUMS_DECLARED*/ + // winmm.dll function pointer typedefs typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT); typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO); @@ -121,6 +133,10 @@ typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID); #define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled #define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush +// shcore.dll function pointer typedefs +typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS); +#define _glfw_SetProcessDPIAwareness _glfw.win32.shcore.SetProcessDPIAwareness + #include "win32_tls.h" #include "winmm_joystick.h" @@ -191,6 +207,12 @@ typedef struct _GLFWlibraryWin32 DWMFLUSH_T DwmFlush; } dwmapi; + // shcore.dll + struct { + HINSTANCE instance; + SETPROCESSDPIAWARENESS_T SetProcessDPIAwareness; + } shcore; + } _GLFWlibraryWin32; diff --git a/src/win32_window.c b/src/win32_window.c index a341c5e5..9881d2d6 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -584,6 +584,19 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, break; } + case WM_DPICHANGED: + { + RECT* rect = (RECT*) lParam; + SetWindowPos(window->win32.handle, + HWND_TOP, + rect->left, + rect->top, + rect->right - rect->left, + rect->bottom - rect->top, + SWP_NOACTIVATE | SWP_NOZORDER); + break; + } + case WM_DEVICECHANGE: { if (DBT_DEVNODES_CHANGED == wParam)