Browse Source

Backends: GLFW: Preserve monitor list when there are no monitor. (#5683)

ocornut 2 years ago
parent
commit
19b436f68d
2 changed files with 7 additions and 1 deletions
  1. 5 1
      backends/imgui_impl_glfw.cpp
  2. 2 0
      docs/CHANGELOG.txt

+ 5 - 1
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;

+ 2 - 0
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.