From adf693c061dcf8f500828578752fed66e7467d92 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 21 Apr 2023 15:10:44 +0200 Subject: [PATCH] Viewports: added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant). --- backends/imgui_impl_glfw.cpp | 1 + backends/imgui_impl_osx.mm | 1 + backends/imgui_impl_sdl2.cpp | 1 + backends/imgui_impl_sdl3.cpp | 1 + backends/imgui_impl_win32.cpp | 1 + docs/CHANGELOG.txt | 5 +++++ imgui.h | 3 ++- 7 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index bf8187a08..9dcdc2b95 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -906,6 +906,7 @@ static void ImGui_ImplGlfw_UpdateMonitors() glfwGetMonitorContentScale(glfw_monitors[n], &x_scale, &y_scale); monitor.DpiScale = x_scale; #endif + 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_osx.mm b/backends/imgui_impl_osx.mm index fbd41f5e3..4deeeaf52 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -1048,6 +1048,7 @@ static void ImGui_ImplOSX_UpdateMonitors() imgui_monitor.WorkPos = ImVec2(visibleFrame.origin.x, visibleFrame.origin.y); imgui_monitor.WorkSize = ImVec2(visibleFrame.size.width, visibleFrame.size.height); imgui_monitor.DpiScale = screen.backingScaleFactor; + imgui_monitor.PlatformHandle = (__bridge_retained void*)screen; platform_io.Monitors.push_back(imgui_monitor); } diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index 80cfdfb05..e58e0386c 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -718,6 +718,7 @@ static void ImGui_ImplSDL2_UpdateMonitors() if (!SDL_GetDisplayDPI(n, &dpi, nullptr, nullptr)) monitor.DpiScale = dpi / 96.0f; #endif + 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 50b8be652..c57eb0986 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -643,6 +643,7 @@ static void ImGui_ImplSDL3_UpdateMonitors() // DpiScale to cocoa_window.backingScaleFactor here. const SDL_DisplayMode* display_mode = SDL_GetCurrentDisplayMode(display_id); monitor.DpiScale = display_mode->display_scale; + monitor.PlatformHandle = (void*)(intptr_t)n; platform_io.Monitors.push_back(monitor); } } diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index 2574fcd75..d24c655d8 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -404,6 +404,7 @@ static BOOL CALLBACK ImGui_ImplWin32_UpdateMonitors_EnumFunc(HMONITOR monitor, H imgui_monitor.WorkPos = ImVec2((float)info.rcWork.left, (float)info.rcWork.top); imgui_monitor.WorkSize = ImVec2((float)(info.rcWork.right - info.rcWork.left), (float)(info.rcWork.bottom - info.rcWork.top)); imgui_monitor.DpiScale = ImGui_ImplWin32_GetDpiScaleForMonitor(monitor); + imgui_monitor.PlatformHandle = (void*)monitor; ImGuiPlatformIO& io = ImGui::GetPlatformIO(); if (info.dwFlags & MONITORINFOF_PRIMARY) io.Monitors.push_front(imgui_monitor); diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d36814bb1..002bb5b7b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -122,6 +122,11 @@ Other changes: - Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] +Docking+Viewports Branch: + +- Viewports: added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant), + for usage by user code. + ----------------------------------------------------------------------- VERSION 1.89.5 (Released 2023-04-13) diff --git a/imgui.h b/imgui.h index afacfb7cf..cefcd2291 100644 --- a/imgui.h +++ b/imgui.h @@ -3250,7 +3250,8 @@ struct ImGuiPlatformMonitor ImVec2 MainPos, MainSize; // Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) ImVec2 WorkPos, WorkSize; // Coordinates without task bars / side bars / menu bars. Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. float DpiScale; // 1.0f = 96 DPI - ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; } + void* PlatformHandle; // Backend dependant data (e.g. HMONITOR, GLFWmonitor*, SDL Display Index, NSScreen*) + ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; PlatformHandle = NULL; } }; // (Optional) Support for IME (Input Method Editor) via the io.SetPlatformImeDataFn() function.