From 65005c0dc0612a7ede6bab497393bd023c4b3592 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 2 Jun 2026 19:17:27 +1000 Subject: [PATCH] [idd] all: add default refresh rate setting support --- idd/LGCommon/PipeMsg.h | 1 + idd/LGIdd/CIndirectDeviceContext.cpp | 4 ++-- idd/LGIdd/CPipeServer.cpp | 11 ++++++----- idd/LGIdd/CPipeServer.h | 2 +- idd/LGIdd/CSettings.cpp | 20 ++++++++++++++++++++ idd/LGIdd/CSettings.h | 1 + idd/LGIddHelper/CPipeClient.cpp | 9 +++++---- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/idd/LGCommon/PipeMsg.h b/idd/LGCommon/PipeMsg.h index 17b7712c..cf74d6fe 100644 --- a/idd/LGCommon/PipeMsg.h +++ b/idd/LGCommon/PipeMsg.h @@ -46,6 +46,7 @@ struct LGPipeMsg { uint32_t width; uint32_t height; + uint32_t refresh; } displayMode; }; diff --git a/idd/LGIdd/CIndirectDeviceContext.cpp b/idd/LGIdd/CIndirectDeviceContext.cpp index 7cd61ccb..9c28a7c5 100644 --- a/idd/LGIdd/CIndirectDeviceContext.cpp +++ b/idd/LGIdd/CIndirectDeviceContext.cpp @@ -202,7 +202,7 @@ void CIndirectDeviceContext::OnAssignSwapChain() if (m_doSetMode) { m_doSetMode = false; - g_pipe.SetDisplayMode(m_setMode.width, m_setMode.height); //FIXME: refresh + g_pipe.SetDisplayMode(m_setMode.width, m_setMode.height, m_setMode.refresh); } } @@ -300,7 +300,7 @@ void CIndirectDeviceContext::SetResolution(int width, int height) { m_setMode.width = width; m_setMode.height = height; - m_setMode.refresh = 120; //FIXME + m_setMode.refresh = g_settings.GetDefaultRefresh(); m_setMode.preferred = true; g_settings.SetExtraMode(m_setMode); diff --git a/idd/LGIdd/CPipeServer.cpp b/idd/LGIdd/CPipeServer.cpp index 0e8eb6d4..e71ad500 100644 --- a/idd/LGIdd/CPipeServer.cpp +++ b/idd/LGIdd/CPipeServer.cpp @@ -162,15 +162,16 @@ void CPipeServer::SetCursorPos(uint32_t x, uint32_t y) WriteMsg(msg); } -void CPipeServer::SetDisplayMode(uint32_t width, uint32_t height) +void CPipeServer::SetDisplayMode(uint32_t width, uint32_t height, uint32_t refresh) { if (!m_connected) return; LGPipeMsg msg; - msg.size = sizeof(msg); - msg.type = LGPipeMsg::SETDISPLAYMODE; - msg.displayMode.width = width; - msg.displayMode.height = height; + msg.size = sizeof(msg); + msg.type = LGPipeMsg::SETDISPLAYMODE; + msg.displayMode.width = width; + msg.displayMode.height = height; + msg.displayMode.refresh = refresh; WriteMsg(msg); } \ No newline at end of file diff --git a/idd/LGIdd/CPipeServer.h b/idd/LGIdd/CPipeServer.h index 84896a14..f2fe5a63 100644 --- a/idd/LGIdd/CPipeServer.h +++ b/idd/LGIdd/CPipeServer.h @@ -54,7 +54,7 @@ class CPipeServer void DeInit(); void SetCursorPos(uint32_t x, uint32_t y); - void SetDisplayMode(uint32_t width, uint32_t height); + void SetDisplayMode(uint32_t width, uint32_t height, uint32_t refresh); }; extern CPipeServer g_pipe; \ No newline at end of file diff --git a/idd/LGIdd/CSettings.cpp b/idd/LGIdd/CSettings.cpp index 6f806341..da7934c1 100644 --- a/idd/LGIdd/CSettings.cpp +++ b/idd/LGIdd/CSettings.cpp @@ -166,6 +166,26 @@ bool CSettings::GetExtraMode(DisplayMode& mode) return ParseModeString(extraMode, mode); } +unsigned CSettings::GetDefaultRefresh() const +{ + DWORD refresh = 60; + DWORD cb = sizeof(refresh); + HKEY hKey = nullptr; + + LONG st = RegOpenKeyExW(HKEY_LOCAL_MACHINE, LGIDD_REGKEY, 0, KEY_QUERY_VALUE, &hKey); + if (st == ERROR_SUCCESS) + { + DWORD type = 0; + st = RegGetValueW(hKey, nullptr, L"DefaultRefresh", RRF_RT_REG_DWORD, &type, &refresh, &cb); + RegCloseKey(hKey); + } + + if (st != ERROR_SUCCESS || refresh < 30 || refresh > 1000) + return 60; + + return refresh; +} + bool CSettings::ReadModesValue(std::vector &out) const { HKEY hKey = nullptr; diff --git a/idd/LGIdd/CSettings.h b/idd/LGIdd/CSettings.h index b0bf186d..055e8a74 100644 --- a/idd/LGIdd/CSettings.h +++ b/idd/LGIdd/CSettings.h @@ -41,6 +41,7 @@ class CSettings const DisplayModes& GetDisplayModes() { return m_displayModes; } void SetExtraMode(const DisplayMode & mode); bool GetExtraMode(DisplayMode & mode); + unsigned GetDefaultRefresh() const; private: DisplayModes m_displayModes; diff --git a/idd/LGIddHelper/CPipeClient.cpp b/idd/LGIddHelper/CPipeClient.cpp index f3de02ee..2108f029 100644 --- a/idd/LGIddHelper/CPipeClient.cpp +++ b/idd/LGIddHelper/CPipeClient.cpp @@ -290,10 +290,11 @@ void CPipeClient::HandleSetCursorPos(const LGPipeMsg& msg) void CPipeClient::HandleSetDisplayMode(const LGPipeMsg& msg) { DEVMODE dm = {}; - dm.dmSize = sizeof(dm); - dm.dmPelsWidth = msg.displayMode.width; - dm.dmPelsHeight = msg.displayMode.height; - dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; + dm.dmSize = sizeof(dm); + dm.dmPelsWidth = msg.displayMode.width; + dm.dmPelsHeight = msg.displayMode.height; + dm.dmDisplayFrequency = msg.displayMode.refresh; + dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; LONG result = ChangeDisplaySettingsEx(NULL, &dm, NULL, CDS_UPDATEREGISTRY, NULL); if (result != DISP_CHANGE_SUCCESSFUL)