From 41d436f0fe1687e534ef3c0e44d855c224648730 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 27 Jul 2023 11:56:53 -0700
Subject: [PATCH] Use SetWindowPos to show windows when
SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN is set to avoid activating the parent
window when showing a child window
---
src/video/windows/SDL_windowswindow.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index c49bda245c44..076cccee3e4d 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -845,7 +845,6 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
DWORD style;
HWND hwnd;
- int nCmdShow;
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE);
@@ -855,13 +854,16 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
hwnd = window->driverdata->hwnd;
- nCmdShow = bActivate ? SW_SHOW : SW_SHOWNA;
style = GetWindowLong(hwnd, GWL_EXSTYLE);
if (style & WS_EX_NOACTIVATE) {
- nCmdShow = SW_SHOWNOACTIVATE;
bActivate = SDL_FALSE;
}
- ShowWindow(hwnd, nCmdShow);
+ if (bActivate) {
+ ShowWindow(hwnd, SW_SHOW);
+ } else {
+ /* Use SetWindowPos instead of ShowWindow to avoid activating the parent window if this is a child window */
+ SetWindowPos(hwnd, NULL, 0, 0, 0, 0, window->driverdata->copybits_flag | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
+ }
if (window->flags & SDL_WINDOW_POPUP_MENU && bActivate) {
if (window->parent == SDL_GetKeyboardFocus()) {