From 0664e510a27fda7a1109bfb45334f6ae1a262b4d Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 5 Jun 2026 00:00:45 -0400 Subject: [PATCH] [idd] helper: send message over pipe when settings changed --- idd/LGCommon/PipeMsg.h | 5 +++-- idd/LGIddHelper/CConfigWindow.cpp | 26 +++++++++++++++++++------- idd/LGIddHelper/CConfigWindow.h | 4 ++++ idd/LGIddHelper/CNotifyWindow.cpp | 2 ++ idd/LGIddHelper/CNotifyWindow.h | 5 +++++ idd/LGIddHelper/CPipeClient.cpp | 11 +++++++++++ idd/LGIddHelper/CPipeClient.h | 2 ++ idd/LGIddHelper/main.cpp | 4 ++++ 8 files changed, 50 insertions(+), 9 deletions(-) diff --git a/idd/LGCommon/PipeMsg.h b/idd/LGCommon/PipeMsg.h index 99595c40..f565894d 100644 --- a/idd/LGCommon/PipeMsg.h +++ b/idd/LGCommon/PipeMsg.h @@ -1,4 +1,4 @@ -/** +/** * Looking Glass * Copyright © 2017-2026 The Looking Glass Authors * https://looking-glass.io @@ -31,7 +31,8 @@ struct LGPipeMsg { SETCURSORPOS, SETDISPLAYMODE, - GPUSTATUS + GPUSTATUS, + RELOADSETTINGS } type; union diff --git a/idd/LGIddHelper/CConfigWindow.cpp b/idd/LGIddHelper/CConfigWindow.cpp index 192d583f..23f1e238 100644 --- a/idd/LGIddHelper/CConfigWindow.cpp +++ b/idd/LGIddHelper/CConfigWindow.cpp @@ -291,7 +291,9 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd) m_modeBox->setSel(updateModeList(index)); LRESULT result = m_settings.setModes(*m_modes); - if (result != ERROR_SUCCESS) + if (result == ERROR_SUCCESS) + sendSettingChange(); + else DEBUG_ERROR_HR((HRESULT) result, "Failed to save modes"); } else if (m_modeDelete && hwnd == *m_modeDelete && code == BN_CLICKED && m_modes) @@ -304,20 +306,27 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd) m_modeBox->clear(); m_modes->erase(m_modes->begin() + index); - LRESULT result = m_settings.setModes(*m_modes); - if (result != ERROR_SUCCESS) - DEBUG_ERROR_HR((HRESULT) result, "Failed to save modes"); - updateModeList(); onModeListSelectChange(); + + LRESULT result = m_settings.setModes(*m_modes); + if (result == ERROR_SUCCESS) + sendSettingChange(); + else + DEBUG_ERROR_HR((HRESULT) result, "Failed to save modes"); } else if (m_modeReset && hwnd == *m_modeReset && code == BN_CLICKED && m_modes) { *m_modes = m_settings.getDefaultModes(); - m_settings.setModes(*m_modes); m_modeBox->clear(); updateModeList(); onModeListSelectChange(); + + LRESULT result = m_settings.setModes(*m_modes); + if (result == ERROR_SUCCESS) + sendSettingChange(); + else + DEBUG_ERROR_HR((HRESULT)result, "Failed to save modes"); } else if (m_defRefresh && hwnd == *m_defRefresh && code == EN_CHANGE && m_defaultRefresh) { @@ -332,8 +341,11 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd) } m_defaultRefresh = value; + LRESULT result = m_settings.setDefaultRefresh(value); - if (result != ERROR_SUCCESS) + if (result == ERROR_SUCCESS) + sendSettingChange(); + else DEBUG_ERROR_HR((HRESULT)result, "Failed to default refresh"); } else if (m_prefNoGPU && hwnd == *m_prefNoGPU && code == BN_CLICKED && m_noGPU) diff --git a/idd/LGIddHelper/CConfigWindow.h b/idd/LGIddHelper/CConfigWindow.h index e05aa302..9f302888 100644 --- a/idd/LGIddHelper/CConfigWindow.h +++ b/idd/LGIddHelper/CConfigWindow.h @@ -64,6 +64,8 @@ class CConfigWindow : public CWindow std::unique_ptr m_prefNoGPU; std::function m_onDestroy; + std::function m_onSettingChange; + double m_scale; Microsoft::WRL::Wrappers::HandleT m_font; CRegistrySettings m_settings; @@ -75,6 +77,7 @@ class CConfigWindow : public CWindow void updateFont(); int updateModeList(int wanted = -1); void onModeListSelectChange(); + void sendSettingChange() { if (m_onSettingChange) m_onSettingChange(); } virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override; virtual LRESULT onCreate() override; @@ -87,4 +90,5 @@ public: static bool registerClass(); void onDestroy(std::function func) { m_onDestroy = std::move(func); } + void onSettingChange(std::function func) { m_onSettingChange = std::move(func); } }; diff --git a/idd/LGIddHelper/CNotifyWindow.cpp b/idd/LGIddHelper/CNotifyWindow.cpp index 9d13b0d7..be1977c8 100644 --- a/idd/LGIddHelper/CNotifyWindow.cpp +++ b/idd/LGIddHelper/CNotifyWindow.cpp @@ -140,6 +140,8 @@ LRESULT CNotifyWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y) m_config->onDestroy([this]() { PostMessage(m_hwnd, WM_CLEAN_UP_CONFIG, 0, 0); }); + if (m_onSettingChange) + m_config->onSettingChange(m_onSettingChange); ShowWindow(*m_config, SW_NORMAL); break; } diff --git a/idd/LGIddHelper/CNotifyWindow.h b/idd/LGIddHelper/CNotifyWindow.h index de32101e..3b39254e 100644 --- a/idd/LGIddHelper/CNotifyWindow.h +++ b/idd/LGIddHelper/CNotifyWindow.h @@ -20,6 +20,7 @@ #pragma once #include "CWindow.h" +#include #include #include @@ -37,6 +38,8 @@ class CNotifyWindow : public CWindow bool closeRequested; std::unique_ptr m_config; + std::function m_onSettingChange; + LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y); void registerIcon(); void handleGPUNotification(bool hasGPU); @@ -69,4 +72,6 @@ public: HWND hwndDialog(); void close(); + + void onSettingChange(std::function func) { m_onSettingChange = std::move(func); } }; \ No newline at end of file diff --git a/idd/LGIddHelper/CPipeClient.cpp b/idd/LGIddHelper/CPipeClient.cpp index b0e35382..768eebac 100644 --- a/idd/LGIddHelper/CPipeClient.cpp +++ b/idd/LGIddHelper/CPipeClient.cpp @@ -170,6 +170,17 @@ void CPipeClient::WriteMsg(const LGPipeMsg& msg) FlushFileBuffers(m_pipe.Get()); } +void CPipeClient::ReloadSettings() +{ + if (!m_connected) + return; + + LGPipeMsg msg; + msg.size = sizeof(msg); + msg.type = LGPipeMsg::RELOADSETTINGS; + WriteMsg(msg); +} + void CPipeClient::Thread() { DEBUG_INFO("Pipe thread started"); diff --git a/idd/LGIddHelper/CPipeClient.h b/idd/LGIddHelper/CPipeClient.h index c6e53552..00ba0613 100644 --- a/idd/LGIddHelper/CPipeClient.h +++ b/idd/LGIddHelper/CPipeClient.h @@ -59,6 +59,8 @@ public: bool Init(); void DeInit(); bool IsRunning() { return m_running; } + + void ReloadSettings(); }; extern CPipeClient g_pipe; \ No newline at end of file diff --git a/idd/LGIddHelper/main.cpp b/idd/LGIddHelper/main.cpp index 536fca55..e8999810 100644 --- a/idd/LGIddHelper/main.cpp +++ b/idd/LGIddHelper/main.cpp @@ -120,6 +120,10 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ if (!g_pipe.Init()) return EXIT_FAILURE; + window.onSettingChange([]() { + g_pipe.ReloadSettings(); + }); + HANDLE hWait; if (!RegisterWaitForSingleObject(&hWait, hParent.Get(), DestroyNotifyWindow, &window, INFINITE, WT_EXECUTEONLYONCE)) DEBUG_ERROR_HR(GetLastError(), "Failed to RegisterWaitForSingleObject");