src/video/winrt/SDL_winrtvideo.cpp
changeset 9964 bcb6bd590d03
parent 9952 54b2eeb48c7d
child 9993 e05d46c27ce3
     1.1 --- a/src/video/winrt/SDL_winrtvideo.cpp	Fri Dec 18 18:49:35 2015 -0800
     1.2 +++ b/src/video/winrt/SDL_winrtvideo.cpp	Tue Dec 22 00:58:47 2015 -0500
     1.3 @@ -505,6 +505,32 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +static bool
     1.8 +WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow)
     1.9 +{
    1.10 +    /* WinRT does not appear to offer API(s) to determine window-activation state,
    1.11 +       at least not that I am aware of in Win8 - Win10.  As such, SDL tracks this
    1.12 +       itself, via window-activation events.
    1.13 +       
    1.14 +       If there *is* an API to track this, it should probably get used instead
    1.15 +       of the following hack (that uses "SDLHelperWindowActivationState").
    1.16 +         -- DavidL.
    1.17 +    */
    1.18 +    if (coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
    1.19 +        CoreWindowActivationState activationState = \
    1.20 +            safe_cast<CoreWindowActivationState>(coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
    1.21 +        return (activationState != CoreWindowActivationState::Deactivated);
    1.22 +    }
    1.23 +
    1.24 +    /* Assume that non-SDL tracked windows are active, although this should
    1.25 +       probably be avoided, if possible.
    1.26 +       
    1.27 +       This might not even be possible, in normal SDL use, at least as of
    1.28 +       this writing (Dec 22, 2015; via latest hg.libsdl.org/SDL clone)  -- DavidL
    1.29 +    */
    1.30 +    return true;
    1.31 +}
    1.32 +
    1.33  int
    1.34  WINRT_CreateWindow(_THIS, SDL_Window * window)
    1.35  {
    1.36 @@ -645,12 +671,7 @@
    1.37          );
    1.38  
    1.39          /* Try detecting if the window is active */
    1.40 -        bool isWindowActive = true;     /* Presume the window is active, unless we've been told otherwise */
    1.41 -        if (data->coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
    1.42 -            CoreWindowActivationState activationState = \
    1.43 -                safe_cast<CoreWindowActivationState>(data->coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
    1.44 -            isWindowActive = (activationState != CoreWindowActivationState::Deactivated);
    1.45 -        }
    1.46 +        bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
    1.47          if (isWindowActive) {
    1.48              SDL_SetKeyboardFocus(window);
    1.49          }
    1.50 @@ -681,13 +702,16 @@
    1.51  {
    1.52  #if NTDDI_VERSION >= NTDDI_WIN10
    1.53      SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
    1.54 -    if (fullscreen) {
    1.55 -        if (!data->appView->IsFullScreenMode) {
    1.56 -            data->appView->TryEnterFullScreenMode();    // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
    1.57 -        }
    1.58 -    } else {
    1.59 -        if (data->appView->IsFullScreenMode) {
    1.60 -            data->appView->ExitFullScreenMode();
    1.61 +    bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
    1.62 +    if (isWindowActive) {
    1.63 +        if (fullscreen) {
    1.64 +            if (!data->appView->IsFullScreenMode) {
    1.65 +                data->appView->TryEnterFullScreenMode();    // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
    1.66 +            }
    1.67 +        } else {
    1.68 +            if (data->appView->IsFullScreenMode) {
    1.69 +                data->appView->ExitFullScreenMode();
    1.70 +            }
    1.71          }
    1.72      }
    1.73  #endif