Backends: GLFW, SDL2, SDL3, update for docking to use helpers.

This commit is contained in:
ocornut
2025-06-11 18:07:43 +02:00
parent 6af6cec23f
commit 65857236c7
3 changed files with 8 additions and 21 deletions

View File

@@ -962,14 +962,10 @@ static void ImGui_ImplGlfw_UpdateMonitors()
monitor.WorkSize = ImVec2((float)w, (float)h); monitor.WorkSize = ImVec2((float)w, (float)h);
} }
#endif #endif
#if GLFW_HAS_PER_MONITOR_DPI float scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfw_monitors[n]);
// 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. if (scale == 0.0f)
float x_scale, y_scale;
glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale);
if (x_scale == 0.0f)
continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902.
monitor.DpiScale = x_scale; monitor.DpiScale = scale;
#endif
monitor.PlatformHandle = (void*)glfw_monitors[n]; // [...] GLFW doc states: "guaranteed to be valid only until the monitor configuration changes" 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); platform_io.Monitors.push_back(monitor);
} }

View File

@@ -956,17 +956,10 @@ static void ImGui_ImplSDL2_UpdateMonitors()
monitor.WorkSize = ImVec2((float)r.w, (float)r.h); monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
} }
#endif #endif
#if SDL_HAS_PER_MONITOR_DPI float dpi_scale = ImGui_ImplSDL2_GetContentScaleForDisplay(n);
// FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set if (dpi_scale <= 0.0f)
// DpiScale to cocoa_window.backingScaleFactor here. continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902.
float dpi = 0.0f; monitor.DpiScale = dpi_scale;
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
monitor.PlatformHandle = (void*)(intptr_t)n; monitor.PlatformHandle = (void*)(intptr_t)n;
platform_io.Monitors.push_back(monitor); platform_io.Monitors.push_back(monitor);
} }

View File

@@ -897,9 +897,7 @@ static void ImGui_ImplSDL3_UpdateMonitors()
monitor.WorkPos = ImVec2((float)r.x, (float)r.y); monitor.WorkPos = ImVec2((float)r.x, (float)r.y);
monitor.WorkSize = ImVec2((float)r.w, (float)r.h); 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 monitor.DpiScale = SDL_GetDisplayContentScale(display_id); // See https://wiki.libsdl.org/SDL3/README-highdpi for details.
// DpiScale to cocoa_window.backingScaleFactor here.
monitor.DpiScale = SDL_GetDisplayContentScale(display_id);
monitor.PlatformHandle = (void*)(intptr_t)n; monitor.PlatformHandle = (void*)(intptr_t)n;
if (monitor.DpiScale <= 0.0f) if (monitor.DpiScale <= 0.0f)
continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902. continue; // Some accessibility applications are declaring virtual monitors with a DPI of 0, see #7902.