From b0d544659149f5343b2f002d57ff51f35e3be6e4 Mon Sep 17 00:00:00 2001 From: Marius PvW Date: Wed, 4 Nov 2026 10:23:56 -0500 Subject: [PATCH] Backends: SDL2: create tooltip and popup viewports with SDL_WINDOW_TOOLTIP / SDL_WINDOW_POPUP_MENU. Fallback for sdl2-compat. (#7950) --- backends/imgui_impl_sdl2.cpp | 26 ++++++++++++++++++++++++++ docs/CHANGELOG.txt | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index bcc3b8595..3b407b504 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -26,6 +26,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) // 2026-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2026-11-04: [Docking] Create tooltip and popup viewports with SDL_WINDOW_TOOLTIP / SDL_WINDOW_POPUP_MENU so they do not steal focus and stack above always-on-top windows. Fall back to an always-on-top window when creation fails (sdl2-compat). (#7950) // 2026-08-06: Fixed querying framebuffer scale when using Metal. (#5592) // 2026-07-15: Inputs: restore SDL_StartTextInput()/SDL_StopTextInput() in IME handler for on-screen keyboard support on Android/mobile. (#7636, #9474) // 2026-04-16: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return a minimum of 1.0f, as some Linux setup seems to report <1.0f value and this breaks scaling border size. (#9369) @@ -1152,7 +1153,32 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport) #if SDL_HAS_ALWAYS_ON_TOP sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0; #endif + + // Viewports for short-lived floating windows (tooltips, popups, menus) carry _NoTaskBarIcon + _NoDecoration + // + _NoFocusOnAppearing + _NoFocusOnClick, and among those only tooltips also carry _TopMost + _NoInputs + // (see ImGui::WindowSelectViewport()). Create them with the corresponding SDL window type: + // SDL_WINDOW_TOOLTIP windows never receive input focus, and SDL_WINDOW_POPUP_MENU windows stack above + // SDL_WINDOW_ALWAYS_ON_TOP windows. + if ((viewport->Flags & ImGuiViewportFlags_NoFocusOnClick) && (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) + && (viewport->Flags & ImGuiViewportFlags_NoDecoration) && (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)) + { + if ((viewport->Flags & ImGuiViewportFlags_NoInputs) && (viewport->Flags & ImGuiViewportFlags_TopMost)) + sdl_flags |= SDL_WINDOW_TOOLTIP; + else + sdl_flags |= SDL_WINDOW_POPUP_MENU; + } + vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Pos.x, (int)viewport->Pos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags); + if (vd->Window == nullptr && (sdl_flags & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU))) + { + // sdl2-compat maps tooltip/popup-menu windows onto SDL3 popups, which require a parent window + // and therefore fail in SDL_CreateWindow(); approximate with an always-on-top window. + sdl_flags &= ~(SDL_WINDOW_TOOLTIP | SDL_WINDOW_POPUP_MENU); +#if SDL_HAS_ALWAYS_ON_TOP + sdl_flags |= SDL_WINDOW_ALWAYS_ON_TOP; +#endif + vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Pos.x, (int)viewport->Pos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags); + } vd->WindowOwned = true; if (use_opengl) { diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b5b7ecbaa..aa8e9d0d7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -114,6 +114,10 @@ Docking+Viewports Branch: - Win32: make windows appear with `::SetWindowPos()` w/ `SWP_NOOWNERZORDER` instead of unparenting + `ShowWindow()`. Fixes missing taskbar icon for newly appearing windows that are parented and use `ImGuiViewportFlags_NoFocusOnAppearing`. (#7354, #8669) + - SDL2: create tooltip and popup/menu viewports with `SDL_WINDOW_TOOLTIP` and + `SDL_WINDOW_POPUP_MENU`, so they no longer take focus from the parent window and + stack above `SDL_WINDOW_ALWAYS_ON_TOP` windows. Falls back to an always-on-top + window when creation fails (sdl2-compat requires a parent for those). (#7950)