From 16a283717a60aa84706035d4c8f200e9dc692a2b Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 30 Aug 2025 18:02:55 +0000 Subject: [PATCH] [idd] driver; support custom resolution and refresh rate list Custom modes can now be configured via the registry under HKEY_LOCAL_MACHINE\SOFTWARE\LookingGlass\IDD Create the value "Modes" as a REG_MULTI_SZ with the value as a list of modes, for example: 1024x768@60 1920x1080@60 1920x1080@120* The '*' denotes the preferred mode to default to if one has not been selected by the user. --- idd/LGIdd/CIndirectDeviceContext.cpp | 59 +++++++++------------------- idd/LGIdd/CIndirectDeviceContext.h | 17 +++----- idd/LGIdd/Device.cpp | 1 + idd/LGIdd/LGIdd.vcxproj | 2 + idd/LGIdd/LGIdd.vcxproj.filters | 9 +++++ 5 files changed, 36 insertions(+), 52 deletions(-) diff --git a/idd/LGIdd/CIndirectDeviceContext.cpp b/idd/LGIdd/CIndirectDeviceContext.cpp index 2158fec6..cd8f2d37 100644 --- a/idd/LGIdd/CIndirectDeviceContext.cpp +++ b/idd/LGIdd/CIndirectDeviceContext.cpp @@ -21,6 +21,7 @@ #include "CIndirectDeviceContext.h" #include "CIndirectMonitorContext.h" +#include "CSettings.h" #include "CPlatformInfo.h" #include "CPipeServer.h" #include "CDebug.h" @@ -42,36 +43,14 @@ static const struct LGMPQueueConfig POINTER_QUEUE_CONFIG = 1000 //subTimeout }; -const DWORD DefaultDisplayModes[][3] = +void CIndirectDeviceContext::PopulateDefaultModes() { - {7680, 4800, 120}, {7680, 4320, 120}, {6016, 3384, 120}, {5760, 3600, 120}, - {5760, 3240, 120}, {5120, 2800, 120}, {4096, 2560, 120}, {4096, 2304, 120}, - {3840, 2400, 120}, {3840, 2160, 120}, {3200, 2400, 120}, {3200, 1800, 120}, - {3008, 1692, 120}, {2880, 1800, 120}, {2880, 1620, 120}, {2560, 1600, 120}, - {2560, 1440, 120}, {1920, 1440, 120}, {1920, 1200, 120}, {1920, 1080, 120}, - {1600, 1200, 120}, {1600, 1024, 120}, {1600, 1050, 120}, {1600, 900 , 120}, - {1440, 900 , 120}, {1400, 1050, 120}, {1366, 768 , 120}, {1360, 768 , 120}, - {1280, 1024, 120}, {1280, 960 , 120}, {1280, 800 , 120}, {1280, 768 , 120}, - {1280, 720 , 120}, {1280, 600 , 120}, {1152, 864 , 120}, {1024, 768 , 120}, - {800 , 600 , 120}, {640 , 480 , 120} -}; + g_settings.LoadModes(); -const DWORD DefaultPreferredDisplayMode = 19; - -void CIndirectDeviceContext::PopulateDefaultModes(bool setDefaultMode) -{ - m_displayModes.reserve(m_displayModes.size() + - ARRAYSIZE(DefaultDisplayModes)); - - for (int i = 0; i < ARRAYSIZE(DefaultDisplayModes); ++i) - { - DisplayMode m; - m.width = DefaultDisplayModes[i][0]; - m.height = DefaultDisplayModes[i][1]; - m.refresh = DefaultDisplayModes[i][2]; - m.preferred = setDefaultMode && (i == DefaultPreferredDisplayMode); - m_displayModes.push_back(m); - } + m_displayModes.clear(); + m_displayModes.reserve(g_settings.GetDisplayModes().size()); + for (auto& dm : g_settings.GetDisplayModes()) + m_displayModes.push_back(dm); } void CIndirectDeviceContext::InitAdapter() @@ -79,8 +58,7 @@ void CIndirectDeviceContext::InitAdapter() if (!m_ivshmem.Init() || !m_ivshmem.Open()) return; - m_displayModes.clear(); - PopulateDefaultModes(true); + PopulateDefaultModes(); IDDCX_ADAPTER_CAPS caps = {}; caps.Size = sizeof(caps); @@ -219,10 +197,10 @@ void CIndirectDeviceContext::ReplugMonitor() void CIndirectDeviceContext::OnAssignSwapChain() { - if (m_setCustomMode) + if (m_doSetMode) { - m_setCustomMode = false; - g_pipe.SetDisplayMode(m_customMode.width, m_customMode.height); + m_doSetMode = false; + g_pipe.SetDisplayMode(m_setMode.width, m_setMode.height); //FIXME: refresh } } @@ -318,15 +296,14 @@ NTSTATUS CIndirectDeviceContext::MonitorQueryTargetModes( void CIndirectDeviceContext::SetResolution(int width, int height) { - m_displayModes.clear(); - m_customMode.width = width; - m_customMode.height = height; - m_customMode.refresh = 120; - m_customMode.preferred = true; - m_displayModes.push_back(m_customMode); - PopulateDefaultModes(false); + m_setMode.width = width; + m_setMode.height = height; + m_setMode.refresh = 120; //FIXME + m_setMode.preferred = true; + g_settings.SetExtraMode(m_setMode); - m_setCustomMode = true; + PopulateDefaultModes(); + m_doSetMode = true; #if 1 ReplugMonitor(); diff --git a/idd/LGIdd/CIndirectDeviceContext.h b/idd/LGIdd/CIndirectDeviceContext.h index 8bb2088d..86b29a9d 100644 --- a/idd/LGIdd/CIndirectDeviceContext.h +++ b/idd/LGIdd/CIndirectDeviceContext.h @@ -26,6 +26,7 @@ #include #include "CIVSHMEM.h" +#include "CSettings.h" extern "C" { #include "lgmp/host.h" @@ -87,16 +88,10 @@ private: void LGMPTimer(); void ResendCursor(); - struct DisplayMode - { - unsigned width; - unsigned height; - unsigned refresh; - bool preferred; - }; - std::vector m_displayModes; - DisplayMode m_customMode = {}; - bool m_setCustomMode = false; + CSettings::DisplayModes m_displayModes; + + CSettings::DisplayMode m_setMode; + bool m_doSetMode; public: CIndirectDeviceContext(_In_ WDFDEVICE wdfDevice) : @@ -106,7 +101,7 @@ public: bool SetupLGMP(size_t alignSize); - void PopulateDefaultModes(bool setDefaultMode); + void PopulateDefaultModes(); void InitAdapter(); void FinishInit(UINT connectorIndex); void ReplugMonitor(); diff --git a/idd/LGIdd/Device.cpp b/idd/LGIdd/Device.cpp index 50808bfc..f26ad64a 100644 --- a/idd/LGIdd/Device.cpp +++ b/idd/LGIdd/Device.cpp @@ -32,6 +32,7 @@ #include "CDebug.h" #include "CIndirectDeviceContext.h" #include "CIndirectMonitorContext.h" +#include "CSettings.h" WDFDEVICE l_wdfDevice = nullptr; diff --git a/idd/LGIdd/LGIdd.vcxproj b/idd/LGIdd/LGIdd.vcxproj index 0c936c05..4e4f9e6c 100644 --- a/idd/LGIdd/LGIdd.vcxproj +++ b/idd/LGIdd/LGIdd.vcxproj @@ -51,6 +51,7 @@ + @@ -68,6 +69,7 @@ + diff --git a/idd/LGIdd/LGIdd.vcxproj.filters b/idd/LGIdd/LGIdd.vcxproj.filters index 8219c646..a14c45fe 100644 --- a/idd/LGIdd/LGIdd.vcxproj.filters +++ b/idd/LGIdd/LGIdd.vcxproj.filters @@ -80,6 +80,11 @@ Header Files + + + + Header Files + @@ -128,5 +133,9 @@ Source Files + + + Source Files + \ No newline at end of file