From 19b436f68da9ceaef3684900c90ec7a9622f941a Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 25 May 2023 15:38:35 +0200 Subject: [PATCH] Backends: GLFW: Preserve monitor list when there are no monitor. (#5683) --- backends/imgui_impl_glfw.cpp | 6 +++++- docs/CHANGELOG.txt | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 9dcdc2b9..bd9f32b6 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -877,10 +877,14 @@ static void ImGui_ImplGlfw_UpdateMonitors() { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + bd->WantUpdateMonitors = false; + int monitors_count = 0; GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count); + if (monitors_count) // Preserve existing monitor list if there are none. Happens on macOS sleeping (#5683) + return; + platform_io.Monitors.resize(0); - bd->WantUpdateMonitors = false; for (int n = 0; n < monitors_count; n++) { ImGuiPlatformMonitor monitor; diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index fc9d309b..1f922b8b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -165,6 +165,8 @@ Docking+Viewports Branch: main viewport, due to platform-side handling changes. Regression from 1.89.5 (#6299) - Viewports: Added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant), for usage by user code. +- Backends: GLFW: Preserve monitor list when there are no monitor, may briefly + happen when recovering from macOS sleeping mode. (#5683) [@Guistac] - Backends: SDL2: Update monitor list when receiving a display event. (#6348) Note however that SDL2 currently doesn't have an event for a DPI/Scaling change, so monitor data won't be updated in this situation.