mirror of https://github.com/doitsujin/dxvk
[dxgi] Leave fullscreen mode when window looses focus
This commit is contained in:
parent
1a5afc77b1
commit
a454ac20b3
|
@ -215,7 +215,7 @@ namespace dxvk {
|
|||
return hr;
|
||||
}
|
||||
|
||||
frontendSwapChain = new DxgiSwapChain(this, presenter.ptr(), hWnd, &desc, &fsDesc);
|
||||
frontendSwapChain = new DxgiSwapChain(this, presenter.ptr(), hWnd, &desc, &fsDesc, pDevice);
|
||||
} else {
|
||||
Logger::err("DXGI: CreateSwapChainForHwnd: Unsupported device type");
|
||||
return DXGI_ERROR_UNSUPPORTED;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "../util/util_misc.h"
|
||||
|
||||
#include <d3d12.h>
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
DxgiSwapChain::DxgiSwapChain(
|
||||
|
@ -11,14 +13,17 @@ namespace dxvk {
|
|||
IDXGIVkSwapChain* pPresenter,
|
||||
HWND hWnd,
|
||||
const DXGI_SWAP_CHAIN_DESC1* pDesc,
|
||||
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc)
|
||||
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc,
|
||||
IUnknown* pDevice)
|
||||
: m_factory (pFactory),
|
||||
m_window (hWnd),
|
||||
m_desc (*pDesc),
|
||||
m_descFs (*pFullscreenDesc),
|
||||
m_presentCount(0u),
|
||||
m_presenter (pPresenter),
|
||||
m_monitor (wsi::getWindowMonitor(m_window)) {
|
||||
m_monitor (wsi::getWindowMonitor(m_window)),
|
||||
m_is_d3d12(SUCCEEDED(pDevice->QueryInterface(__uuidof(ID3D12CommandQueue), reinterpret_cast<void**>(&Com<ID3D12CommandQueue>())))) {
|
||||
|
||||
if (FAILED(m_presenter->GetAdapter(__uuidof(IDXGIAdapter), reinterpret_cast<void**>(&m_adapter))))
|
||||
throw DxvkError("DXGI: Failed to get adapter for present device");
|
||||
|
||||
|
@ -214,7 +219,9 @@ namespace dxvk {
|
|||
BOOL* pFullscreen,
|
||||
IDXGIOutput** ppTarget) {
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
|
||||
if (!m_is_d3d12 && !m_descFs.Windowed && wsi::isOccluded(m_window))
|
||||
SetFullscreenState(FALSE, nullptr);
|
||||
if (pFullscreen != nullptr)
|
||||
*pFullscreen = !m_descFs.Windowed;
|
||||
|
||||
|
@ -287,6 +294,16 @@ namespace dxvk {
|
|||
if (SyncInterval > 4)
|
||||
return DXGI_ERROR_INVALID_CALL;
|
||||
|
||||
if (!m_is_d3d12 && wsi::isMinimized(m_window))
|
||||
return DXGI_STATUS_OCCLUDED;
|
||||
|
||||
if (!m_descFs.Windowed && wsi::isOccluded(m_window))
|
||||
{
|
||||
if (!(PresentFlags & DXGI_PRESENT_TEST))
|
||||
SetFullscreenState(FALSE, nullptr);
|
||||
return DXGI_STATUS_OCCLUDED;
|
||||
}
|
||||
|
||||
std::lock_guard<dxvk::recursive_mutex> lockWin(m_lockWindow);
|
||||
std::lock_guard<dxvk::mutex> lockBuf(m_lockBuffer);
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace dxvk {
|
|||
IDXGIVkSwapChain* pPresenter,
|
||||
HWND hWnd,
|
||||
const DXGI_SWAP_CHAIN_DESC1* pDesc,
|
||||
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc);
|
||||
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc,
|
||||
IUnknown* pDevice);
|
||||
|
||||
~DxgiSwapChain();
|
||||
|
||||
|
@ -189,7 +190,9 @@ namespace dxvk {
|
|||
|
||||
HMONITOR m_monitor;
|
||||
wsi::DxvkWindowState m_windowState;
|
||||
|
||||
|
||||
bool m_is_d3d12;
|
||||
|
||||
HRESULT EnterFullscreenMode(
|
||||
IDXGIOutput1 *pTarget);
|
||||
|
||||
|
|
|
@ -124,6 +124,18 @@ namespace dxvk::wsi {
|
|||
return window != nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool isMinimized(HWND hWindow) {
|
||||
GLFWwindow* window = fromHwnd(hWindow);
|
||||
return glfwGetWindowAttrib(window, GLFW_ICONIFIED) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool isOccluded(HWND hWindow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void updateFullscreenWindow(
|
||||
HMONITOR hMonitor,
|
||||
HWND hWindow,
|
||||
|
@ -141,4 +153,4 @@ namespace dxvk::wsi {
|
|||
return glfwCreateWindowSurface(instance, window, nullptr, pSurface);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,17 @@ namespace dxvk::wsi {
|
|||
}
|
||||
|
||||
|
||||
bool isMinimized(HWND hWindow) {
|
||||
SDL_Window* window = fromHwnd(hWindow);
|
||||
return (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool isOccluded(HWND hWindow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void updateFullscreenWindow(
|
||||
HMONITOR hMonitor,
|
||||
HWND hWindow,
|
||||
|
|
|
@ -253,6 +253,16 @@ namespace dxvk::wsi {
|
|||
}
|
||||
|
||||
|
||||
bool isMinimized(HWND hWindow) {
|
||||
return (::GetWindowLongW(hWindow, GWL_STYLE) & WS_MINIMIZE) != 0;
|
||||
}
|
||||
|
||||
|
||||
bool isOccluded(HWND hWindow) {
|
||||
return ::GetForegroundWindow() != hWindow;
|
||||
}
|
||||
|
||||
|
||||
void updateFullscreenWindow(
|
||||
HMONITOR hMonitor,
|
||||
HWND hWindow,
|
||||
|
|
|
@ -99,6 +99,22 @@ namespace dxvk::wsi {
|
|||
*/
|
||||
bool isWindow(HWND hWindow);
|
||||
|
||||
/**
|
||||
* \brief Is window minimized?
|
||||
*
|
||||
* \param [in] hWindow The window
|
||||
* \returns Is window minimized?
|
||||
*/
|
||||
bool isMinimized(HWND hWindow);
|
||||
|
||||
/**
|
||||
* \brief Is window occluded?
|
||||
*
|
||||
* \param [in] hWindow The window
|
||||
* \returns Is window occluded?
|
||||
*/
|
||||
bool isOccluded(HWND hWindow);
|
||||
|
||||
/**
|
||||
* \brief Update a fullscreen window's position/size
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue