[idd] helper: clean up exclusive monitor timer and respect setting

This commit is contained in:
Quantum
2026-07-18 15:09:25 -04:00
committed by Geoffrey McRae
parent f3d5c7e185
commit f8d9574709
3 changed files with 23 additions and 13 deletions

View File

@@ -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<bool()> func)
void CNotifyWindow::onEnsureOnlyDisplay(std::function<bool()> func)
{
m_onDisplayChange = std::move(func);
m_onEnsureOnlyDisplay = std::move(func);
scheduleDisplayCheck(DISPLAY_SETTLE_DELAY);
}

View File

@@ -39,7 +39,7 @@ class CNotifyWindow : public CWindow
std::unique_ptr<CConfigWindow> m_config;
std::function<void()> m_onSettingChange;
std::function<bool()> m_onDisplayChange;
std::function<bool()> 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<void()> func) { m_onSettingChange = std::move(func); }
void onDisplayChange(std::function<bool()> func);
void onEnsureOnlyDisplay(std::function<bool()> func);
};

View File

@@ -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();
});