microsoft / DirectX-Graphics-Samples

This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.
MIT License
6.07k stars 2.03k forks source link

[Fullscreen] Fullscreen alt-tab behavior #814

Open Vincent-P opened 1 year ago

Vincent-P commented 1 year ago

Hello, Recently I had to implement a D3D12 rendering backend at work. I used the fullscreen sample to implement fullscreen behavior and I had a few issues. Most notably some users were complaining that Alt-tabbing did not work properly in fullscreen (e.g You cannot switch to a window on the same screen as the fullscreen window)

After a bit of debugging I found the culprit: https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12Fullscreen/src/Win32Application.cpp#L155

The sample uses HWND_TOPMOST when switching to fullscreen. As stated in the documentation (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos), it breaks standard alt-tab behavior ("The window maintains its topmost position even when it is deactivated. "). I believe it should be HWND_TOP instead?

If the original intent is to have a topmost window, it would be great to have a comment explaining the difference between HWND_TOP and HWND_TOPMOST.

sebmerry commented 1 year ago

Hi @Vincent-P, I agree with you, breaking alt-tab behavior is not intended. That's not a great customer experience. :)

DXGI handles this case on your behalf when using SetFullscreenState() - it will kick the window out of fullscreen. However, this sample is showing how SetFullscreenState() isn't actually needed if you want to manage the window yourself. In this case, HWND_TOP provides a much better customer experience! If you want to make a PR I'd be happy to review it.