From fa65dcf24cee01dc25c1abb304d8fae80114d3dc Mon Sep 17 00:00:00 2001 From: RT2 Date: Sat, 17 Aug 2024 13:13:10 +0200 Subject: [PATCH] Backends: SDL2, SDL3: Replace Win32 hack with SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN hint. (#7896) --- backends/imgui_impl_sdl2.cpp | 6 +++++- backends/imgui_impl_sdl3.cpp | 8 +------- docs/CHANGELOG.txt | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index d038cb80d..eeef0c788 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -116,6 +116,7 @@ #define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4) #define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6) #define SDL_HAS_DISPLAY_EVENT SDL_VERSION_ATLEAST(2,0,9) +#define SDL_HAS_SHOW_WINDOW_ACTIVATION_HINT SDL_VERSION_ATLEAST(2,0,18) #if !SDL_HAS_VULKAN static const Uint32 SDL_WINDOW_VULKAN = 0x10000000; #endif @@ -1012,7 +1013,11 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport) ex_style |= WS_EX_TOOLWINDOW; ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); } +#endif +#if SDL_HAS_SHOW_WINDOW_ACTIVATION_HINT + SDL_SetHint(SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "1" : "0"); +#elif defined(_WIN32) // SDL hack: SDL always activate/focus windows :/ if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) { @@ -1020,7 +1025,6 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport) return; } #endif - SDL_ShowWindow(vd->Window); } diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index c54589487..035ee7b17 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -952,15 +952,9 @@ static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport) ex_style |= WS_EX_TOOLWINDOW; ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); } - - // SDL hack: SDL always activate/focus windows :/ - if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) - { - ::ShowWindow(hwnd, SW_SHOWNA); - return; - } #endif + SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "0" : "1"); SDL_ShowWindow(vd->Window); } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 380217c41..8f0076efd 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -58,6 +58,9 @@ Docking+Viewports Branch: to allow backends to alter the default per-viewport work-area. (#7823) - Backends: don't report monitors with DpiScale of 0, which seemed to be reported for virtual monitors instead by accessibility drivers. (#7902) [@nicolasnoble] +- Backends: SDL2, SDL3: using SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN to support the + ImGuiViewportFlags_NoFocusOnAppearing flag, instead of using a Win32-specific hack. + (#7896) [@RT2Code] -----------------------------------------------------------------------