mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-06-07 15:24:27 +00:00
[idd] helper: send message over pipe when settings changed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* Looking Glass
|
* Looking Glass
|
||||||
* Copyright © 2017-2026 The Looking Glass Authors
|
* Copyright © 2017-2026 The Looking Glass Authors
|
||||||
* https://looking-glass.io
|
* https://looking-glass.io
|
||||||
@@ -31,7 +31,8 @@ struct LGPipeMsg
|
|||||||
{
|
{
|
||||||
SETCURSORPOS,
|
SETCURSORPOS,
|
||||||
SETDISPLAYMODE,
|
SETDISPLAYMODE,
|
||||||
GPUSTATUS
|
GPUSTATUS,
|
||||||
|
RELOADSETTINGS
|
||||||
}
|
}
|
||||||
type;
|
type;
|
||||||
union
|
union
|
||||||
|
|||||||
@@ -291,7 +291,9 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
|
|||||||
m_modeBox->setSel(updateModeList(index));
|
m_modeBox->setSel(updateModeList(index));
|
||||||
|
|
||||||
LRESULT result = m_settings.setModes(*m_modes);
|
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");
|
DEBUG_ERROR_HR((HRESULT) result, "Failed to save modes");
|
||||||
}
|
}
|
||||||
else if (m_modeDelete && hwnd == *m_modeDelete && code == BN_CLICKED && m_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_modeBox->clear();
|
||||||
m_modes->erase(m_modes->begin() + index);
|
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();
|
updateModeList();
|
||||||
onModeListSelectChange();
|
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)
|
else if (m_modeReset && hwnd == *m_modeReset && code == BN_CLICKED && m_modes)
|
||||||
{
|
{
|
||||||
*m_modes = m_settings.getDefaultModes();
|
*m_modes = m_settings.getDefaultModes();
|
||||||
m_settings.setModes(*m_modes);
|
|
||||||
m_modeBox->clear();
|
m_modeBox->clear();
|
||||||
updateModeList();
|
updateModeList();
|
||||||
onModeListSelectChange();
|
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)
|
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;
|
m_defaultRefresh = value;
|
||||||
|
|
||||||
LRESULT result = m_settings.setDefaultRefresh(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");
|
DEBUG_ERROR_HR((HRESULT)result, "Failed to default refresh");
|
||||||
}
|
}
|
||||||
else if (m_prefNoGPU && hwnd == *m_prefNoGPU && code == BN_CLICKED && m_noGPU)
|
else if (m_prefNoGPU && hwnd == *m_prefNoGPU && code == BN_CLICKED && m_noGPU)
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ class CConfigWindow : public CWindow
|
|||||||
std::unique_ptr<CCheckbox> m_prefNoGPU;
|
std::unique_ptr<CCheckbox> m_prefNoGPU;
|
||||||
|
|
||||||
std::function<void()> m_onDestroy;
|
std::function<void()> m_onDestroy;
|
||||||
|
std::function<void()> m_onSettingChange;
|
||||||
|
|
||||||
double m_scale;
|
double m_scale;
|
||||||
Microsoft::WRL::Wrappers::HandleT<FontTraits> m_font;
|
Microsoft::WRL::Wrappers::HandleT<FontTraits> m_font;
|
||||||
CRegistrySettings m_settings;
|
CRegistrySettings m_settings;
|
||||||
@@ -75,6 +77,7 @@ class CConfigWindow : public CWindow
|
|||||||
void updateFont();
|
void updateFont();
|
||||||
int updateModeList(int wanted = -1);
|
int updateModeList(int wanted = -1);
|
||||||
void onModeListSelectChange();
|
void onModeListSelectChange();
|
||||||
|
void sendSettingChange() { if (m_onSettingChange) m_onSettingChange(); }
|
||||||
|
|
||||||
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
|
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
|
||||||
virtual LRESULT onCreate() override;
|
virtual LRESULT onCreate() override;
|
||||||
@@ -87,4 +90,5 @@ public:
|
|||||||
static bool registerClass();
|
static bool registerClass();
|
||||||
|
|
||||||
void onDestroy(std::function<void()> func) { m_onDestroy = std::move(func); }
|
void onDestroy(std::function<void()> func) { m_onDestroy = std::move(func); }
|
||||||
|
void onSettingChange(std::function<void()> func) { m_onSettingChange = std::move(func); }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ LRESULT CNotifyWindow::onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y)
|
|||||||
m_config->onDestroy([this]() {
|
m_config->onDestroy([this]() {
|
||||||
PostMessage(m_hwnd, WM_CLEAN_UP_CONFIG, 0, 0);
|
PostMessage(m_hwnd, WM_CLEAN_UP_CONFIG, 0, 0);
|
||||||
});
|
});
|
||||||
|
if (m_onSettingChange)
|
||||||
|
m_config->onSettingChange(m_onSettingChange);
|
||||||
ShowWindow(*m_config, SW_NORMAL);
|
ShowWindow(*m_config, SW_NORMAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "CWindow.h"
|
#include "CWindow.h"
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@@ -37,6 +38,8 @@ class CNotifyWindow : public CWindow
|
|||||||
bool closeRequested;
|
bool closeRequested;
|
||||||
std::unique_ptr<CConfigWindow> m_config;
|
std::unique_ptr<CConfigWindow> m_config;
|
||||||
|
|
||||||
|
std::function<void()> m_onSettingChange;
|
||||||
|
|
||||||
LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y);
|
LRESULT onNotifyIcon(UINT uEvent, WORD wIconId, int x, int y);
|
||||||
void registerIcon();
|
void registerIcon();
|
||||||
void handleGPUNotification(bool hasGPU);
|
void handleGPUNotification(bool hasGPU);
|
||||||
@@ -69,4 +72,6 @@ public:
|
|||||||
|
|
||||||
HWND hwndDialog();
|
HWND hwndDialog();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
void onSettingChange(std::function<void()> func) { m_onSettingChange = std::move(func); }
|
||||||
};
|
};
|
||||||
@@ -170,6 +170,17 @@ void CPipeClient::WriteMsg(const LGPipeMsg& msg)
|
|||||||
FlushFileBuffers(m_pipe.Get());
|
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()
|
void CPipeClient::Thread()
|
||||||
{
|
{
|
||||||
DEBUG_INFO("Pipe thread started");
|
DEBUG_INFO("Pipe thread started");
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public:
|
|||||||
bool Init();
|
bool Init();
|
||||||
void DeInit();
|
void DeInit();
|
||||||
bool IsRunning() { return m_running; }
|
bool IsRunning() { return m_running; }
|
||||||
|
|
||||||
|
void ReloadSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CPipeClient g_pipe;
|
extern CPipeClient g_pipe;
|
||||||
@@ -120,6 +120,10 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
|||||||
if (!g_pipe.Init())
|
if (!g_pipe.Init())
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
window.onSettingChange([]() {
|
||||||
|
g_pipe.ReloadSettings();
|
||||||
|
});
|
||||||
|
|
||||||
HANDLE hWait;
|
HANDLE hWait;
|
||||||
if (!RegisterWaitForSingleObject(&hWait, hParent.Get(), DestroyNotifyWindow, &window, INFINITE, WT_EXECUTEONLYONCE))
|
if (!RegisterWaitForSingleObject(&hWait, hParent.Get(), DestroyNotifyWindow, &window, INFINITE, WT_EXECUTEONLYONCE))
|
||||||
DEBUG_ERROR_HR(GetLastError(), "Failed to RegisterWaitForSingleObject");
|
DEBUG_ERROR_HR(GetLastError(), "Failed to RegisterWaitForSingleObject");
|
||||||
|
|||||||
Reference in New Issue
Block a user