From 65857236c79069bfe398f4496ce1edef7c7ac0a5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 11 Jun 2025 18:07:43 +0200 Subject: [PATCH] Backends: GLFW, SDL2, SDL3, update for docking to use helpers. --- backends/imgui_impl_glfw.cpp | 10 +++------- backends/imgui_impl_sdl2.cpp | 15 ++++----------- backends/imgui_impl_sdl3.cpp | 4 +--- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 806e01673..78f595227 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -962,14 +962,10 @@ static void ImGui_ImplGlfw_UpdateMonitors() monitor.WorkSize = ImVec2((float)w, (float)h); } #endif -#if GLFW_HAS_PER_MONITOR_DPI - // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime. - float x_scale, y_scale; - glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); - if (x_scale == 0.0f) + float scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfw_monitors[n]); + if (scale == 0.0f) continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. - monitor.DpiScale = x_scale; -#endif + monitor.DpiScale = scale; monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes" platform_io.Monitors.push_back(monitor); } diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index 5430c4b3f..fd8b898f3 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -956,17 +956,10 @@ static void ImGui_ImplSDL2_UpdateMonitors() monitor.WorkSize = ImVec2((float)r.w, (float)r.h); } #endif -#if SDL_HAS_PER_MONITOR_DPI - // FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set - // DpiScale to cocoa_window.backingScaleFactor here. - float dpi = 0.0f; - if (!SDL_GetDisplayDPI(n, &dpi, nullptr, nullptr)) - { - if (dpi <= 0.0f) - continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. - monitor.DpiScale = dpi / 96.0f; - } -#endif + float dpi_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(n); + if (dpi_scale <= 0.0f) + continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. + monitor.DpiScale = dpi_scale; monitor.PlatformHandle = (void*)(intptr_t)n; platform_io.Monitors.push_back(monitor); } diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index f75864423..8bfdfd613 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -897,9 +897,7 @@ static void ImGui_ImplSDL3_UpdateMonitors() monitor.WorkPos = ImVec2((float)r.x, (float)r.y); monitor.WorkSize = ImVec2((float)r.w, (float)r.h); } - // FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set - // DpiScale to cocoa_window.backingScaleFactor here. - monitor.DpiScale = SDL_GetDisplayContentScale(display_id); + monitor.DpiScale = SDL_GetDisplayContentScale(display_id); // See https://wiki.libsdl.org/SDL3/README-highdpi for details. monitor.PlatformHandle = (void*)(intptr_t)n; if (monitor.DpiScale <= 0.0f) continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902.