Skip to content

Commit

Permalink
Use SetWindowPos to show windows when SDL_HINT_WINDOW_ACTIVATE_WHEN_S…
Browse files Browse the repository at this point in the history
…HOWN is set to avoid activating the parent window when showing a child window
  • Loading branch information
slouken committed Jul 27, 2023
1 parent 0dc85f3 commit 41d436f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/video/windows/SDL_windowswindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()) {
Expand Down

0 comments on commit 41d436f

Please sign in to comment.