Fix alt-tabbing out of full screen on Windows. (#5288)

Signed-off-by: bosnichd <bosnichd@amazon.com>
This commit is contained in:
bosnichd
2021-11-04 11:17:52 -06:00
committed by GitHub
parent 0b7bff79d3
commit 600bb5b34e
2 changed files with 23 additions and 3 deletions
@@ -54,6 +54,7 @@ namespace AzFramework
RECT m_windowRectToRestoreOnFullScreenExit; //!< The position and size of the window to restore when exiting full screen.
UINT m_windowStyleToRestoreOnFullScreenExit; //!< The style(s) of the window to restore when exiting full screen.
bool m_isInBorderlessWindowFullScreenState = false; //!< Was a borderless window used to enter full screen state?
bool m_shouldEnterFullScreenStateOnActivate = false; //!< Should we enter full screen state when the window is activated?
using GetDpiForWindowType = UINT(HWND hwnd);
GetDpiForWindowType* m_getDpiFunction = nullptr;
@@ -249,6 +250,28 @@ namespace AzFramework
AzFramework::RawInputNotificationBusWindows::Broadcast(&AzFramework::RawInputNotificationsWindows::OnRawInputCodeUnitUTF16Event, codeUnitUTF16);
break;
}
case WM_ACTIVATE:
{
// Alt-tabbing out of the app while it is in a full screen state does not
// work unless we explicitly exit the full screen state upon deactivation,
// in which case we want to enter full screen state again upon activation.
const bool windowIsNowInactive = (LOWORD(wParam) == WA_INACTIVE);
const bool windowFullScreenState = nativeWindowImpl->GetFullScreenState();
if (windowIsNowInactive &&
windowFullScreenState)
{
nativeWindowImpl->m_shouldEnterFullScreenStateOnActivate = true;
nativeWindowImpl->SetFullScreenState(false);
}
else if (!windowIsNowInactive &&
!windowFullScreenState &&
nativeWindowImpl->m_shouldEnterFullScreenStateOnActivate)
{
nativeWindowImpl->m_shouldEnterFullScreenStateOnActivate = false;
nativeWindowImpl->SetFullScreenState(true);
}
break;
}
case WM_SYSKEYDOWN:
{
// Handle ALT+ENTER to toggle full screen unless exclsuive full screen
@@ -82,9 +82,6 @@ namespace AZ
// ALT+ENTER fullscreen switching using IDXGIFactory::MakeWindowAssociation (see also implementation of SwapChain::PresentInternal).
// You must call the MakeWindowAssociation method after the creation of the swap chain, and on the factory object associated with the
// target HWND swap chain, which you can guarantee by calling the IDXGIObject::GetParent method on the swap chain to locate the factory.
//
// ToDo: ATOM-14673 We should handle ALT+ENTER in the windows message loop and call AzFramework::NativeWindow::ToggleFullScreenState in
// response, but that will have to wait until the WndProc function moves out of CrySystem (ideally into AzFramework::ApplicationWindows).
IDXGIFactoryX* parentFactory = nullptr;
m_swapChain->GetParent(__uuidof(IDXGIFactoryX), (void **)&parentFactory);
DX12::AssertSuccess(parentFactory->MakeWindowAssociation(reinterpret_cast<HWND>(window), DXGI_MWA_NO_ALT_ENTER));