So I am trying to handle Alt+Tab in DirectX12 while in fullscreen correctly. The way I want it to behave is upon alt tab in fullscreen it is supposed to minimize the screen and then when you unminimize it is supposed to go back into fullscreen. (As this is what every modern video game does that handles it properly). So I expected this when using the SetFullscreenState swap chain method. However it transitions from fullscreen into windowed mode when Alt + Tab
is pressed, which isn't desired.
I know I can use ShowWindow
to take it to minimized by detecting WM_SIZE
and a bool tracking what state the user wants the window to be in (fullscreen or not), to achieve the final result. However, you can clearly see the transition from fullscreen into the windowed mode before minimizing it and clearly see the minimization animation. Which is not what I see in other applications. So how do I use SetFullscreenState
correctly so that Alt+Tab minimizes the screen without the whole to window transition then minimization animation.
What I do:
isFullscreen = !isFullscreen;
if( !FlushCommandQueue() ) //flushes the command queue
{
CloseProgram();
return;
}
swapChain->SetFullscreenState(isFullscreen?TRUE:FALSE, NULL);
then in the WM_SIZE handling
u32 temp_screen_width = LOWORD( LParam );
u32 temp_screen_height = HIWORD( LParam );
bool wasMinimized = isMinimized;
if( WParam == SIZE_MINIMIZED || temp_screen_width == 0 || temp_screen_height == 0)
{
isMinimized = true;
}
else
{
isMinimized = false;
}
screen_width = max( 1, temp_screen_width );
screen_height = max( 1, temp_screen_height );
viewport.Width = (f32)screen_width;
viewport.Height = (f32)screen_height;
scissorRect.right = screen_width;
scissorRect.bottom = screen_height;
if( swapChain )
{
BOOL fullscreenState;
BOOL currentState = isFullscreen ? TRUE : FALSE;
swapChain->GetFullscreenState( &fullscreenState, NULL );
if( fullscreenState != currentState )
{
if( !wasMinimized )
{
ShowWindow(Window,SW_MINIMIZE);
}
}
ResizeBuffers();
UpdateCurrentFrame();
DrawScene();
UpdateCurrentFrame();
}