Fix creating a minimized window in SDL to not cause focus to be stolen (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).
authorSam Lantinga <slouken@libsdl.org>
Tue, 05 Jun 2018 12:46:09 -0700
changeset 120061b7ed3438a7f
parent 12005 94f3f018d3eb
child 12007 ecfb6a793c30
Fix creating a minimized window in SDL to not cause focus to be stolen (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
src/video/SDL_video.c
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/video/SDL_video.c	Fri Jun 01 19:43:53 2018 -0700
     1.2 +++ b/src/video/SDL_video.c	Tue Jun 05 12:46:09 2018 -0700
     1.3 @@ -1322,7 +1322,7 @@
     1.4  }
     1.5  
     1.6  #define CREATE_FLAGS \
     1.7 -    (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)
     1.8 +    (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)
     1.9  
    1.10  static void
    1.11  SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
    1.12 @@ -1480,6 +1480,13 @@
    1.13          return NULL;
    1.14      }
    1.15  
    1.16 +	// Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
    1.17 +	// but it's important or window focus will get broken on windows!
    1.18 +#if !defined(__WIN32__)
    1.19 +	if ( window->flags & SDL_WINDOW_MINIMIZED )
    1.20 +		window->flags &= ~SDL_WINDOW_MINIMIZED;
    1.21 +#endif
    1.22 +
    1.23  #if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
    1.24      /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
    1.25         or not.  The user can choose this, via OS-provided UI, but this can't
     2.1 --- a/src/video/windows/SDL_windowswindow.c	Fri Jun 01 19:43:53 2018 -0700
     2.2 +++ b/src/video/windows/SDL_windowswindow.c	Tue Jun 05 12:46:09 2018 -0700
     2.3 @@ -97,6 +97,10 @@
     2.4          if (window->flags & SDL_WINDOW_RESIZABLE) {
     2.5              style |= STYLE_RESIZABLE;
     2.6          }
     2.7 +
     2.8 +		/* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
     2.9 +		if ( window->flags & SDL_WINDOW_MINIMIZED )
    2.10 +			style |= WS_MINIMIZE;
    2.11      }
    2.12      return style;
    2.13  }
    2.14 @@ -335,6 +339,9 @@
    2.15      /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
    2.16      SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
    2.17  
    2.18 +	if ( window->flags & SDL_WINDOW_MINIMIZED )
    2.19 +		ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
    2.20 +
    2.21      if (!(window->flags & SDL_WINDOW_OPENGL)) {
    2.22          return 0;
    2.23      }