From ef62aa7333bc2c1f6f40664cb2f3408dc18b2c79 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 5 May 2025 19:03:50 +0200 Subject: [PATCH] Backends: SDL3: macOS: Fixed secondary-viewports not appearing on a different monitor than the main viewport. --- backends/imgui_impl_sdl3.cpp | 10 ++++++++++ docs/CHANGELOG.txt | 2 ++ 2 files changed, 12 insertions(+) diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index 330f34278..7773b95f6 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -24,6 +24,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) // 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2025-05-06: [Docking] macOS: fixed secondary viewports not appearing on other monitors before of parenting. // 2025-04-09: [Docking] Revert update monitors and work areas information every frame. Only do it on Windows. (#8415, #8558) // 2025-04-22: IME: honor ImGuiPlatformImeData->WantTextInput as an alternative way to call SDL_StartTextInput(), without IME being necessarily visible. // 2025-04-09: Don't attempt to call SDL_CaptureMouse() on drivers where we don't call SDL_GetGlobalMouseState(). (#8561) @@ -1014,7 +1015,9 @@ static void ImGui_ImplSDL3_CreateWindow(ImGuiViewport* viewport) sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) ? SDL_WINDOW_UTILITY : 0; sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0; vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags); +#ifndef __APPLE__ // On Mac, SDL3 Parenting appears to prevent viewport from appearing in another monitor SDL_SetWindowParent(vd->Window, vd->ParentWindow); +#endif SDL_SetWindowPosition(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y); vd->WindowOwned = true; if (use_opengl) @@ -1061,14 +1064,20 @@ static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport) } #endif +#ifdef __APPLE__ + SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, "1"); // Otherwise new window appear under +#else SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "0" : "1"); +#endif SDL_ShowWindow(vd->Window); } static void ImGui_ImplSDL3_UpdateWindow(ImGuiViewport* viewport) { ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; + IM_UNUSED(vd); +#ifndef __APPLE__ // On Mac, SDL3 Parenting appears to prevent viewport from appearing in another monitor // Update SDL3 parent if it changed _after_ creation. // This is for advanced apps that are manipulating ParentViewportID manually. SDL_Window* new_parent = ImGui_ImplSDL3_GetSDLWindowFromViewportID(viewport->ParentViewportId); @@ -1077,6 +1086,7 @@ static void ImGui_ImplSDL3_UpdateWindow(ImGuiViewport* viewport) vd->ParentWindow = new_parent; SDL_SetWindowParent(vd->Window, vd->ParentWindow); } +#endif } static ImVec2 ImGui_ImplSDL3_GetWindowPos(ImGuiViewport* viewport) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 85deea60a..5d8896278 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -125,6 +125,8 @@ Docking+Viewports Branch: - Backends: SDL2, SDL3: revert updating monitors and work areas info every frame. Only do it on Windows to detect task-bar resize until we get an adequate event for it. (#8415, #8558) +- Backends: SDL3: macOS: Fixed secondary-viewports not appearing on a different + monitor than the main viewport. Because SDL_SetWindowParent() seems to restrict it. - Backends: GLFW: Disable multi-viewports under Wayland (require GLFW 3.4). (#8587)