From f3dc5167043928651863a2b126cf9c03f155599d Mon Sep 17 00:00:00 2001 From: Simon Anciaux <14198779+mrmixer@users.noreply.github.com> Date: Mon, 15 Apr 2024 17:54:41 +0200 Subject: [PATCH] Disable DXGI monitoring the message queue for Alt+Enter fullscreen switch. Switching that way instead of calling toggle_fullscreen, causes issue when trying to Alt+Tab. Also users might want to use Alt+Enter for other things. Changed how DXGI factory is handled. I retrieve the one associated with the current DXGI device and adapter instead of creating a new one. Fixed missing new line in the log at 1 location. --- code/platform_win32/win32_4ed.cpp | 2 +- code/platform_win32/win32_dx11.cpp | 43 +++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/code/platform_win32/win32_4ed.cpp b/code/platform_win32/win32_4ed.cpp index 64c735f9..007e25f4 100644 --- a/code/platform_win32/win32_4ed.cpp +++ b/code/platform_win32/win32_4ed.cpp @@ -1744,7 +1744,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_style |= WS_MAXIMIZE; } log_os(" windowed dimensions: %d, %d\n" - " initially maximized: %d", + " initially maximized: %d\n", window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, ((window_style & WS_MAXIMIZE) != 0)); diff --git a/code/platform_win32/win32_dx11.cpp b/code/platform_win32/win32_dx11.cpp index 65cbb533..7f75733b 100644 --- a/code/platform_win32/win32_dx11.cpp +++ b/code/platform_win32/win32_dx11.cpp @@ -50,6 +50,8 @@ win32_gl_create_window(HWND *wnd_out, DWORD style, RECT rect){ ID3D11Device* base_device = 0; ID3D11DeviceContext* base_device_context = 0; + IDXGIDevice1* dxgi_device = 0; + IDXGIAdapter* dxgi_adapter = 0; IDXGIFactory2* dxgi_factory = 0; ID3D11BlendState* blend_state = 0; @@ -176,11 +178,29 @@ win32_gl_create_window(HWND *wnd_out, DWORD style, RECT rect){ log_os( " sRBG back buffer supported.\n" ); } - log_os( " Creating a IDXGIFactory2...\n" ); - hr = CreateDXGIFactory( __uuidof( IDXGIFactory2 ), ( void** ) &dxgi_factory ); + log_os( " Getting a IDXGIFactory2...\n" ); + + log_os( " Qurey for the IDXGIDevice1...\n" ); + hr = device->QueryInterface( __uuidof( IDXGIDevice1 ), ( void** ) &dxgi_device ); if ( FAILED( hr ) ) { - log_os( " Failed.\n" ); + log_os( " Failed.\n" ); + break; + } + + log_os( " Getting the IDXGIAdapter...\n" ); + dxgi_device->GetAdapter( &dxgi_adapter ); + + if ( FAILED( hr ) ) { + log_os( " Failed.\n" ); + break; + } + + log_os( " Getting the IDXGIFactor2...\n" ); + dxgi_adapter->GetParent( __uuidof( IDXGIFactory2 ), ( void** ) &dxgi_factory ); + + if ( FAILED( hr ) ) { + log_os( " Failed.\n" ); break; } @@ -203,6 +223,13 @@ win32_gl_create_window(HWND *wnd_out, DWORD style, RECT rect){ break; } + log_os( " Prevent DXGI handling ALT + ENTER...\n" ); + hr = dxgi_factory->MakeWindowAssociation( wnd, DXGI_MWA_NO_ALT_ENTER ); + + if ( FAILED( hr ) ) { + log_os( " Failed.\n" ); + } + // NOTE(simon, 28/02/24): We setup alpha blending here as it's always on in 4coder. D3D11_BLEND_DESC blend_state_desc = { }; blend_state_desc.RenderTarget[ 0 ].BlendEnable = TRUE; @@ -393,6 +420,16 @@ win32_gl_create_window(HWND *wnd_out, DWORD style, RECT rect){ base_device_context = 0; } + if ( dxgi_device ) { + dxgi_device->Release( ); + dxgi_device = 0; + } + + if ( dxgi_adapter ) { + dxgi_adapter->Release( ); + dxgi_adapter = 0; + } + if ( dxgi_factory ) { dxgi_factory->Release( ); dxgi_factory = 0;