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

This commit is contained in:
Sam Lantinga
2023-07-27 11:56:53 -07:00
parent 0dc85f3078
commit 41d436f0fe

View File

@@ -845,7 +845,6 @@ void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
{ {
DWORD style; DWORD style;
HWND hwnd; HWND hwnd;
int nCmdShow;
SDL_bool bActivate = SDL_GetHintBoolean(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, SDL_TRUE); 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; hwnd = window->driverdata->hwnd;
nCmdShow = bActivate ? SW_SHOW : SW_SHOWNA;
style = GetWindowLong(hwnd, GWL_EXSTYLE); style = GetWindowLong(hwnd, GWL_EXSTYLE);
if (style & WS_EX_NOACTIVATE) { if (style & WS_EX_NOACTIVATE) {
nCmdShow = SW_SHOWNOACTIVATE;
bActivate = SDL_FALSE; 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->flags & SDL_WINDOW_POPUP_MENU && bActivate) {
if (window->parent == SDL_GetKeyboardFocus()) { if (window->parent == SDL_GetKeyboardFocus()) {