From f8d9574709ad3aec0b0a27547322b82e47d55319 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 18 Jul 2026 15:09:25 -0400 Subject: [PATCH] [idd] helper: clean up exclusive monitor timer and respect setting --- idd/LGIddHelper/CNotifyWindow.cpp | 30 ++++++++++++++++++++---------- idd/LGIddHelper/CNotifyWindow.h | 4 ++-- idd/LGIddHelper/main.cpp | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/idd/LGIddHelper/CNotifyWindow.cpp b/idd/LGIddHelper/CNotifyWindow.cpp index 8677f24e..d85ba592 100644 --- a/idd/LGIddHelper/CNotifyWindow.cpp +++ b/idd/LGIddHelper/CNotifyWindow.cpp @@ -35,7 +35,6 @@ #define ID_DISPLAY_CHECK_TIMER 1 #define DISPLAY_SETTLE_DELAY 250 #define DISPLAY_RETRY_DELAY 1000 -#define DISPLAY_CHECK_INTERVAL 5000 ATOM CNotifyWindow::s_atom = 0; UINT CNotifyWindow::s_taskbarCreated = 0; @@ -96,14 +95,17 @@ LRESULT CNotifyWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; case WM_TIMER: - if (wParam == ID_DISPLAY_CHECK_TIMER) + switch (wParam) { + case ID_DISPLAY_CHECK_TIMER: KillTimer(m_hwnd, ID_DISPLAY_CHECK_TIMER); - const bool success = m_onDisplayChange && m_onDisplayChange(); - scheduleDisplayCheck(success ? DISPLAY_CHECK_INTERVAL : DISPLAY_RETRY_DELAY); - return 0; + if (m_onEnsureOnlyDisplay && m_onEnsureOnlyDisplay()) + DEBUG_INFO("Enforced Looking Glass as the only display"); + else + DEBUG_WARN("Failed to ensure Looking Glass is the only display"); + break; } - return CWindow::handleMessage(uMsg, wParam, lParam); + return 0; default: if (s_taskbarCreated && uMsg == s_taskbarCreated) @@ -262,16 +264,24 @@ void CNotifyWindow::close() void CNotifyWindow::scheduleDisplayCheck(UINT delay) { - if (!m_onDisplayChange) + if (!m_onEnsureOnlyDisplay) + return; + + CRegistrySettings settings; + LSTATUS error = settings.open(); + if (error != ERROR_SUCCESS) + DEBUG_ERROR_HR(error, "Failed to load settings"); + + auto exclusive = settings.getExclusiveMonitor(); + if (!exclusive.has_value() || !exclusive.value()) return; - KillTimer(m_hwnd, ID_DISPLAY_CHECK_TIMER); if (!SetTimer(m_hwnd, ID_DISPLAY_CHECK_TIMER, delay, NULL)) DEBUG_ERROR_HR(GetLastError(), "Failed to schedule primary display check"); } -void CNotifyWindow::onDisplayChange(std::function func) +void CNotifyWindow::onEnsureOnlyDisplay(std::function func) { - m_onDisplayChange = std::move(func); + m_onEnsureOnlyDisplay = std::move(func); scheduleDisplayCheck(DISPLAY_SETTLE_DELAY); } diff --git a/idd/LGIddHelper/CNotifyWindow.h b/idd/LGIddHelper/CNotifyWindow.h index 8ac03dc7..1e49fd74 100644 --- a/idd/LGIddHelper/CNotifyWindow.h +++ b/idd/LGIddHelper/CNotifyWindow.h @@ -39,7 +39,7 @@ class CNotifyWindow : public CWindow std::unique_ptr m_config; std::function m_onSettingChange; - std::function m_onDisplayChange; + std::function m_onEnsureOnlyDisplay; LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y); void registerIcon(); @@ -76,5 +76,5 @@ public: void close(); void onSettingChange(std::function func) { m_onSettingChange = std::move(func); } - void onDisplayChange(std::function func); + void onEnsureOnlyDisplay(std::function func); }; diff --git a/idd/LGIddHelper/main.cpp b/idd/LGIddHelper/main.cpp index 223461f4..d9632a71 100644 --- a/idd/LGIddHelper/main.cpp +++ b/idd/LGIddHelper/main.cpp @@ -124,7 +124,7 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ g_pipe.ReloadSettings(); }); - window.onDisplayChange([]() { + window.onEnsureOnlyDisplay([]() { return g_pipe.EnsureOnlyDisplay(); });