[idd] helper: send message over pipe when settings changed

This commit is contained in:
Quantum
2026-06-05 00:00:45 -04:00
committed by Geoffrey McRae
parent e4e211f07a
commit 0664e510a2
8 changed files with 50 additions and 9 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -64,6 +64,8 @@ class CConfigWindow : public CWindow
std::unique_ptr<CCheckbox> m_prefNoGPU;
std::function<void()> m_onDestroy;
std::function<void()> m_onSettingChange;
double m_scale;
Microsoft::WRL::Wrappers::HandleT<FontTraits> 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<void()> func) { m_onDestroy = std::move(func); }
void onSettingChange(std::function<void()> func) { m_onSettingChange = std::move(func); }
};

View File

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

View File

@@ -20,6 +20,7 @@
#pragma once
#include "CWindow.h"
#include <functional>
#include <memory>
#include <optional>
@@ -37,6 +38,8 @@ class CNotifyWindow : public CWindow
bool closeRequested;
std::unique_ptr<CConfigWindow> m_config;
std::function<void()> 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<void()> func) { m_onSettingChange = std::move(func); }
};

View File

@@ -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");

View File

@@ -59,6 +59,8 @@ public:
bool Init();
void DeInit();
bool IsRunning() { return m_running; }
void ReloadSettings();
};
extern CPipeClient g_pipe;

View File

@@ -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");