From 29ae6362557002464d1b5b5862b44b935fc78603 Mon Sep 17 00:00:00 2001 From: glitchbear <161911268+glitchybear@users.noreply.github.com> Date: Sun, 24 Nov 2024 12:04:10 -0600 Subject: [PATCH] Testing refresh rate being selected based on fetching the preferred display rather than primary. --- src/archutils/Win32/GraphicsWindow.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/archutils/Win32/GraphicsWindow.cpp b/src/archutils/Win32/GraphicsWindow.cpp index 6a7043aefa..27ce1968bc 100644 --- a/src/archutils/Win32/GraphicsWindow.cpp +++ b/src/archutils/Win32/GraphicsWindow.cpp @@ -286,8 +286,7 @@ void GraphicsWindow::CreateGraphicsWindow( const VideoModeParams &p, bool bForce { return (mode.dmFields & DM_PELSWIDTH) && (mode.dmFields & DM_PELSHEIGHT) && (mode.dmFields & DM_DISPLAYFREQUENCY) - && (mode.dmBitsPerPel >= 32 || !(mode.dmFields & DM_BITSPERPEL) - && (mode.dmFields & DM_POSITION)); + && (mode.dmBitsPerPel >= 32 || !(mode.dmFields & DM_BITSPERPEL)); }; g_CurrentParams = p; @@ -305,7 +304,8 @@ void GraphicsWindow::CreateGraphicsWindow( const VideoModeParams &p, bool bForce pos.y = 0; // Look for the preferred display's position. - if (EnumDisplaySettingsEx(p.sDisplayId, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode) ) + if (EnumDisplaySettingsEx(p.sDisplayId, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode) + && (devmode.dmFields & DM_POSITION)) { pos = devmode.dmPosition; resetDeviceMode(devmode); @@ -384,19 +384,21 @@ void GraphicsWindow::CreateGraphicsWindow( const VideoModeParams &p, bool bForce * Otherwise the window will be centered on the last display option that was hovered before selecting Windowed in Options*/ if( p.windowed && !p.bWindowIsFullscreenBorderless) { - if (EnumDisplaySettingsEx(NULL, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode)) + if (EnumDisplaySettingsEx(NULL, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode) + && (devmode.dmFields & DM_POSITION)) { WindowRect.left = devmode.dmPosition.x; WindowRect.top = devmode.dmPosition.y; WindowRect.right = devmode.dmPosition.x + devmode.dmPelsWidth; WindowRect.bottom = devmode.dmPosition.y + devmode.dmPelsHeight; - resetDeviceMode(devmode); } x = WindowRect.left + (WindowRect.right - WindowRect.left - iWidth) / 2; y = WindowRect.top + (WindowRect.bottom - WindowRect.top - iHeight) / 2; } + resetDeviceMode(devmode); + /* Move and resize the window. SWP_FRAMECHANGED causes the above * SetWindowLong to take effect. */ if( !SetWindowPos( g_hWndMain, HWND_NOTOPMOST, x, y, iWidth, iHeight, SWP_FRAMECHANGED|SWP_SHOWWINDOW ) ) @@ -567,8 +569,7 @@ void GraphicsWindow::GetDisplaySpecs( DisplaySpecs &out ) auto deviceModeIsValid = [=]( const DEVMODE& mode ) { return (mode.dmFields & DM_PELSWIDTH) && (mode.dmFields & DM_PELSHEIGHT) && (mode.dmFields & DM_DISPLAYFREQUENCY) - && (mode.dmBitsPerPel >= 32 || !(mode.dmFields & DM_BITSPERPEL) - && (mode.dmFields & DM_POSITION)); + && (mode.dmBitsPerPel >= 32 || !(mode.dmFields & DM_BITSPERPEL)); }; DEVMODE devmode; @@ -609,7 +610,8 @@ void GraphicsWindow::GetDisplaySpecs( DisplaySpecs &out ) // Get the current display mode // Set the ENUM_CURRENT_SETTINGS flag so that we only store DisplaySpecs for valid displays - if (EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode)) + if (EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, &devmode, 0) && deviceModeIsValid(devmode) + && (devmode.dmFields & DM_POSITION)) { DisplayMode m = { devmode.dmPelsWidth, devmode.dmPelsHeight, static_cast (devmode.dmDisplayFrequency) }; RectI bounds = { devmode.dmPosition.x, devmode.dmPosition.y, static_cast (m.width), static_cast (m.height) }; @@ -625,6 +627,7 @@ void GraphicsWindow::GetDisplaySpecs( DisplaySpecs &out ) LOG->Warn("Could not retrieve *any* DisplaySpec's!"); ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd); + resetDeviceMode(devmode); } /*