Browse Source

Backends: SDL2, SDL3: Replace Win32 hack with SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN hint. (#7896)

RT2 1 year ago
parent
commit
fa65dcf24c
3 changed files with 9 additions and 8 deletions
  1. 5 1
      backends/imgui_impl_sdl2.cpp
  2. 1 7
      backends/imgui_impl_sdl3.cpp
  3. 3 0
      docs/CHANGELOG.txt

+ 5 - 1
backends/imgui_impl_sdl2.cpp

@@ -116,6 +116,7 @@
 #define SDL_HAS_PER_MONITOR_DPI             SDL_VERSION_ATLEAST(2,0,4)
 #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_VULKAN                      SDL_VERSION_ATLEAST(2,0,6)
 #define SDL_HAS_DISPLAY_EVENT               SDL_VERSION_ATLEAST(2,0,9)
 #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
 #if !SDL_HAS_VULKAN
 static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
 static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
 #endif
 #endif
@@ -1012,7 +1013,11 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
         ex_style |= WS_EX_TOOLWINDOW;
         ex_style |= WS_EX_TOOLWINDOW;
         ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
         ::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 :/
     // SDL hack: SDL always activate/focus windows :/
     if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
     if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
     {
     {
@@ -1020,7 +1025,6 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
         return;
         return;
     }
     }
 #endif
 #endif
-
     SDL_ShowWindow(vd->Window);
     SDL_ShowWindow(vd->Window);
 }
 }
 
 

+ 1 - 7
backends/imgui_impl_sdl3.cpp

@@ -952,15 +952,9 @@ static void ImGui_ImplSDL3_ShowWindow(ImGuiViewport* viewport)
         ex_style |= WS_EX_TOOLWINDOW;
         ex_style |= WS_EX_TOOLWINDOW;
         ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
         ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
     }
     }
-
-    // SDL hack: SDL always activate/focus windows :/
-    if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
-    {
-        ::ShowWindow(hwnd, SW_SHOWNA);
-        return;
-    }
 #endif
 #endif
 
 
+    SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "0" : "1");
     SDL_ShowWindow(vd->Window);
     SDL_ShowWindow(vd->Window);
 }
 }
 
 

+ 3 - 0
docs/CHANGELOG.txt

@@ -58,6 +58,9 @@ Docking+Viewports Branch:
   to allow backends to alter the default per-viewport work-area. (#7823)
   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
 - Backends: don't report monitors with DpiScale of 0, which seemed to be reported
   for virtual monitors instead by accessibility drivers. (#7902) [@nicolasnoble]
   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]
 
 
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------