From aa8e09d7f1481641792e3bb6419acda896af62ae Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Fri, 4 Sep 2020 16:26:31 +0100 Subject: [PATCH] Backends: GLFW: workaround for cases where glfwGetMonitorWorkarea fails (#3457) --- examples/imgui_impl_glfw.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp index e7dc10ca..caded5c4 100644 --- a/examples/imgui_impl_glfw.cpp +++ b/examples/imgui_impl_glfw.cpp @@ -442,16 +442,16 @@ static void ImGui_ImplGlfw_UpdateMonitors() int x, y; glfwGetMonitorPos(glfw_monitors[n], &x, &y); const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]); -#if GLFW_HAS_MONITOR_WORK_AREA - monitor.MainPos = ImVec2((float)x, (float)y); - monitor.MainSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); - int w, h; - glfwGetMonitorWorkarea(glfw_monitors[n], &x, &y, &w, &h); - monitor.WorkPos = ImVec2((float)x, (float)y);; - monitor.WorkSize = ImVec2((float)w, (float)h); -#else monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y); monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height); +#if GLFW_HAS_MONITOR_WORK_AREA + int w, h; + glfwGetMonitorWorkarea(glfw_monitors[n], &x, &y, &w, &h); + if (w > 0 && h > 0) // Workaround a small GLFW issue reporting zero on monitor changes: https://github.com/glfw/glfw/pull/1761 + { + monitor.WorkPos = ImVec2((float)x, (float)y); + 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.