src/video/winrt/SDL_winrtvideo.cpp
changeset 9964 bcb6bd590d03
parent 9952 54b2eeb48c7d
child 9993 e05d46c27ce3
equal deleted inserted replaced
9963:8da3e4d25202 9964:bcb6bd590d03
   501         if ((apply & mask) & SDL_WINDOW_FULLSCREEN) {
   501         if ((apply & mask) & SDL_WINDOW_FULLSCREEN) {
   502             window->last_fullscreen_flags = window->flags;  // seems necessary to programmatically un-fullscreen, via SDL APIs
   502             window->last_fullscreen_flags = window->flags;  // seems necessary to programmatically un-fullscreen, via SDL APIs
   503         }
   503         }
   504         window->flags = (window->flags & ~mask) | (apply & mask);
   504         window->flags = (window->flags & ~mask) | (apply & mask);
   505     }
   505     }
       
   506 }
       
   507 
       
   508 static bool
       
   509 WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow)
       
   510 {
       
   511     /* WinRT does not appear to offer API(s) to determine window-activation state,
       
   512        at least not that I am aware of in Win8 - Win10.  As such, SDL tracks this
       
   513        itself, via window-activation events.
       
   514        
       
   515        If there *is* an API to track this, it should probably get used instead
       
   516        of the following hack (that uses "SDLHelperWindowActivationState").
       
   517          -- DavidL.
       
   518     */
       
   519     if (coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
       
   520         CoreWindowActivationState activationState = \
       
   521             safe_cast<CoreWindowActivationState>(coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
       
   522         return (activationState != CoreWindowActivationState::Deactivated);
       
   523     }
       
   524 
       
   525     /* Assume that non-SDL tracked windows are active, although this should
       
   526        probably be avoided, if possible.
       
   527        
       
   528        This might not even be possible, in normal SDL use, at least as of
       
   529        this writing (Dec 22, 2015; via latest hg.libsdl.org/SDL clone)  -- DavidL
       
   530     */
       
   531     return true;
   506 }
   532 }
   507 
   533 
   508 int
   534 int
   509 WINRT_CreateWindow(_THIS, SDL_Window * window)
   535 WINRT_CreateWindow(_THIS, SDL_Window * window)
   510 {
   536 {
   643             window,
   669             window,
   644             0xffffffff      /* Update any window flag(s) that WINRT_UpdateWindow can handle */
   670             0xffffffff      /* Update any window flag(s) that WINRT_UpdateWindow can handle */
   645         );
   671         );
   646 
   672 
   647         /* Try detecting if the window is active */
   673         /* Try detecting if the window is active */
   648         bool isWindowActive = true;     /* Presume the window is active, unless we've been told otherwise */
   674         bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
   649         if (data->coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
       
   650             CoreWindowActivationState activationState = \
       
   651                 safe_cast<CoreWindowActivationState>(data->coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
       
   652             isWindowActive = (activationState != CoreWindowActivationState::Deactivated);
       
   653         }
       
   654         if (isWindowActive) {
   675         if (isWindowActive) {
   655             SDL_SetKeyboardFocus(window);
   676             SDL_SetKeyboardFocus(window);
   656         }
   677         }
   657     }
   678     }
   658  
   679  
   679 void
   700 void
   680 WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   701 WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   681 {
   702 {
   682 #if NTDDI_VERSION >= NTDDI_WIN10
   703 #if NTDDI_VERSION >= NTDDI_WIN10
   683     SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
   704     SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
   684     if (fullscreen) {
   705     bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
   685         if (!data->appView->IsFullScreenMode) {
   706     if (isWindowActive) {
   686             data->appView->TryEnterFullScreenMode();    // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
   707         if (fullscreen) {
   687         }
   708             if (!data->appView->IsFullScreenMode) {
   688     } else {
   709                 data->appView->TryEnterFullScreenMode();    // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
   689         if (data->appView->IsFullScreenMode) {
   710             }
   690             data->appView->ExitFullScreenMode();
   711         } else {
       
   712             if (data->appView->IsFullScreenMode) {
       
   713                 data->appView->ExitFullScreenMode();
       
   714             }
   691         }
   715         }
   692     }
   716     }
   693 #endif
   717 #endif
   694 }
   718 }
   695 
   719