Skip to content

Commit

Permalink
Fix creating a minimized window in SDL to not cause focus to be stole…
Browse files Browse the repository at this point in the history
…n (because ShowWindow( hwnd, SW_MINIMIZE ) would be called after creation, thus changing focus to the prior window based on some per-app list in windows, rather than the window being created with WS_MINIMIZED to start with).

This means we have to consider SDL_WINDOW_MINIMIZED a window creation flag, but on non-windows platforms we just remove it and let the normal FinishWindowCreation re-apply and do the minimize as I have no idea what is right on them or if anything should change.

CR: Phil
  • Loading branch information
slouken committed Jun 5, 2018
1 parent 1d25135 commit 9d6ac3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/video/SDL_video.c
Expand Up @@ -1322,7 +1322,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
}

#define CREATE_FLAGS \
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN)
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED)

static void
SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
Expand Down Expand Up @@ -1480,6 +1480,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
return NULL;
}

// Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
// but it's important or window focus will get broken on windows!
#if !defined(__WIN32__)
if ( window->flags & SDL_WINDOW_MINIMIZED )
window->flags &= ~SDL_WINDOW_MINIMIZED;
#endif

#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
/* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
or not. The user can choose this, via OS-provided UI, but this can't
Expand Down
7 changes: 7 additions & 0 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -97,6 +97,10 @@ GetWindowStyle(SDL_Window * window)
if (window->flags & SDL_WINDOW_RESIZABLE) {
style |= STYLE_RESIZABLE;
}

/* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
if ( window->flags & SDL_WINDOW_MINIMIZED )
style |= WS_MINIMIZE;
}
return style;
}
Expand Down Expand Up @@ -335,6 +339,9 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
/* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);

if ( window->flags & SDL_WINDOW_MINIMIZED )
ShowWindow( hwnd, SW_SHOWMINNOACTIVE );

if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
}
Expand Down

0 comments on commit 9d6ac3d

Please sign in to comment.