From 83c0c5e9e8bbd80be23b3cb61b2efaa99a383978 Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 15 Jul 2024 11:45:44 +0900 Subject: [PATCH] Video: Fixed resolution/size issues when entering exclusive fullscreen mode --- UI/Windows/MainWindow.axaml.cs | 6 ++++-- Windows/Renderer.cpp | 36 +++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/UI/Windows/MainWindow.axaml.cs b/UI/Windows/MainWindow.axaml.cs index 49119d7a4..48cb94a39 100644 --- a/UI/Windows/MainWindow.axaml.cs +++ b/UI/Windows/MainWindow.axaml.cs @@ -506,11 +506,13 @@ public void ToggleFullscreen() return; } - WindowState = WindowState.FullScreen; - Task.Run(() => { EmuApi.SetExclusiveFullscreenMode(true, TryGetPlatformHandle()?.Handle ?? IntPtr.Zero); _preventFullscreenToggle = false; + + Dispatcher.UIThread.Post(() => { + WindowState = WindowState.FullScreen; + }); }); } else { WindowState = WindowState.FullScreen; diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 1d0b590a0..019174f0e 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -64,7 +64,8 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) _screenWidth != rendererSize.Width || _newFullscreen != _fullscreen || _useSrgbTextureFormat != cfg.UseSrgbTextureFormat || - (_fullscreen && _fullscreenRefreshRate != refreshRate) + (_fullscreen && _fullscreenRefreshRate != refreshRate) || + (_fullscreen && (_realScreenHeight != _monitorHeight || _realScreenWidth != _monitorWidth)) ); }; @@ -100,8 +101,15 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height) _screenWidth = rendererSize.Width; if(_fullscreen) { - _realScreenHeight = _monitorHeight; - _realScreenWidth = _monitorWidth; + if(_realScreenHeight != _monitorHeight) { + _realScreenHeight = _monitorHeight; + needReset = true; + } + + if(_realScreenWidth != _monitorWidth) { + _realScreenWidth = _monitorWidth; + needReset = true; + } //Ensure the screen width/height is smaller or equal to the fullscreen resolution, no matter the requested scale if(_monitorHeight < _screenHeight || _monitorWidth < _screenWidth) { @@ -349,6 +357,28 @@ HRESULT Renderer::InitDevice() MessageManager::Log("SetFullscreenState(false) failed - Error:" + std::to_string(hr)); return hr; } + } else { + //Get actual monitor resolution (which might differ from the one that was requested) + HMONITOR monitor = MonitorFromWindow(_hWnd, MONITOR_DEFAULTTOPRIMARY); + MONITORINFO info = {}; + info.cbSize = sizeof(MONITORINFO); + GetMonitorInfo(monitor, &info); + + uint32_t monitorWidth = info.rcMonitor.right - info.rcMonitor.left; + uint32_t monitorHeight = info.rcMonitor.bottom - info.rcMonitor.top; + + if(_monitorHeight != monitorHeight || _monitorWidth != monitorWidth) { + MessageManager::Log( + "Requested resolution (" + std::to_string(_monitorWidth) + "x" + std::to_string(_monitorHeight) + + ") is not available. Resetting to nearest match instead: " + + std::to_string(monitorWidth) + "x" + std::to_string(monitorHeight) + ); + _monitorWidth = monitorWidth; + _monitorHeight = monitorHeight; + + //Make UI wait until this 2nd reset is over + _resetCounter--; + } } }