From a150fdfc35279c8a144c86f32436e5070f5abd95 Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Fri, 25 Apr 2025 19:44:30 +0200 Subject: [PATCH] Adding per-monitor DPI awareness by using glfwGetWindowContentScale instead of glfwGetMonitorContentScale and ensuring that the window is also resized appropriately by using GLFW_SCALE_TO_MONITOR --- profiler/src/BackendGlfw.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/profiler/src/BackendGlfw.cpp b/profiler/src/BackendGlfw.cpp index 04369994..f7bae6a1 100644 --- a/profiler/src/BackendGlfw.cpp +++ b/profiler/src/BackendGlfw.cpp @@ -80,6 +80,9 @@ Backend::Backend( const char* title, const std::function& redraw, const # if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 4 ) glfwWindowHint( GLFW_WIN32_KEYBOARD_MENU, 1 ); # endif +# if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 ) + glfwWindowHint( GLFW_SCALE_TO_MONITOR, 1 ); +# endif #endif s_window = glfwCreateWindow( m_winPos.w, m_winPos.h, title, NULL, NULL ); if( !s_window ) exit( 1 ); @@ -200,14 +203,10 @@ void Backend::SetTitle( const char* title ) float Backend::GetDpiScale() { #if GLFW_VERSION_MAJOR > 3 || ( GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR >= 3 ) - auto monitor = glfwGetWindowMonitor( s_window ); - if( !monitor ) monitor = glfwGetPrimaryMonitor(); - if( monitor ) - { - float x, y; - glfwGetMonitorContentScale( monitor, &x, &y ); - return x; - } -#endif + float x, y; + glfwGetWindowContentScale( s_window, &x, &y ); + return x; +#else return 1; +#endif }