mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-11-17 15:38:45 +00:00
Compare commits
9 Commits
idd-config
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3efe47ffb2 | ||
|
|
4269b5598a | ||
|
|
af207a2fe1 | ||
|
|
3ed08ba56c | ||
|
|
70da98c1a1 | ||
|
|
ed1602fc74 | ||
|
|
f9ecddab98 | ||
|
|
fad7af7740 | ||
|
|
6c70e36cb1 |
17
idd/LGCommon/DefaultDisplayModes.h
Normal file
17
idd/LGCommon/DefaultDisplayModes.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
static const DWORD DefaultDisplayModes[][3] =
|
||||
{
|
||||
{7680, 4800, 120}, {7680, 4320, 120}, {6016, 3384, 120}, {5760, 3600, 120},
|
||||
{5760, 3240, 120}, {5120, 2800, 120}, {4096, 2560, 120}, {4096, 2304, 120},
|
||||
{3840, 2400, 120}, {3840, 2160, 120}, {3200, 2400, 120}, {3200, 1800, 120},
|
||||
{3008, 1692, 120}, {2880, 1800, 120}, {2880, 1620, 120}, {2560, 1600, 120},
|
||||
{2560, 1440, 120}, {1920, 1440, 120}, {1920, 1200, 120}, {1920, 1080, 120},
|
||||
{1600, 1200, 120}, {1600, 1024, 120}, {1600, 1050, 120}, {1600, 900 , 120},
|
||||
{1440, 900 , 120}, {1400, 1050, 120}, {1366, 768 , 120}, {1360, 768 , 120},
|
||||
{1280, 1024, 120}, {1280, 960 , 120}, {1280, 800 , 120}, {1280, 768 , 120},
|
||||
{1280, 720 , 120}, {1280, 600 , 120}, {1152, 864 , 120}, {1024, 768 , 120},
|
||||
{800 , 600 , 120}, {640 , 480 , 120}
|
||||
};
|
||||
|
||||
static const DWORD DefaultPreferredDisplayMode = 19;
|
||||
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LGCommon", "LGCommon", "{AC
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
LGCommon\CDebug.cpp = LGCommon\CDebug.cpp
|
||||
LGCommon\CDebug.h = LGCommon\CDebug.h
|
||||
LGCommon\DefaultDisplayModes.h = LGCommon\DefaultDisplayModes.h
|
||||
LGCommon\PipeMsg.h = LGCommon\PipeMsg.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "CSettings.h"
|
||||
#include "CSettings.h"
|
||||
#include "CDebug.h"
|
||||
#include "DefaultDisplayModes.h"
|
||||
|
||||
#include <wdf.h>
|
||||
|
||||
@@ -7,22 +8,6 @@ CSettings g_settings;
|
||||
|
||||
#define LGIDD_REGKEY L"SOFTWARE\\LookingGlass\\IDD"
|
||||
|
||||
static const DWORD DefaultDisplayModes[][3] =
|
||||
{
|
||||
{7680, 4800, 120}, {7680, 4320, 120}, {6016, 3384, 120}, {5760, 3600, 120},
|
||||
{5760, 3240, 120}, {5120, 2800, 120}, {4096, 2560, 120}, {4096, 2304, 120},
|
||||
{3840, 2400, 120}, {3840, 2160, 120}, {3200, 2400, 120}, {3200, 1800, 120},
|
||||
{3008, 1692, 120}, {2880, 1800, 120}, {2880, 1620, 120}, {2560, 1600, 120},
|
||||
{2560, 1440, 120}, {1920, 1440, 120}, {1920, 1200, 120}, {1920, 1080, 120},
|
||||
{1600, 1200, 120}, {1600, 1024, 120}, {1600, 1050, 120}, {1600, 900 , 120},
|
||||
{1440, 900 , 120}, {1400, 1050, 120}, {1366, 768 , 120}, {1360, 768 , 120},
|
||||
{1280, 1024, 120}, {1280, 960 , 120}, {1280, 800 , 120}, {1280, 768 , 120},
|
||||
{1280, 720 , 120}, {1280, 600 , 120}, {1152, 864 , 120}, {1024, 768 , 120},
|
||||
{800 , 600 , 120}, {640 , 480 , 120}
|
||||
};
|
||||
|
||||
static const DWORD DefaultPreferredDisplayMode = 19;
|
||||
|
||||
CSettings::CSettings()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -57,11 +57,21 @@ void CConfigWindow::updateFont()
|
||||
|
||||
for (HWND child : std::initializer_list<HWND>({
|
||||
*m_version, *m_modeGroup, *m_modeBox, *m_widthLabel, *m_heightLabel, *m_refreshLabel,
|
||||
*m_modeWidth, *m_modeHeight, *m_modeRefresh, *m_modeUpdate,
|
||||
*m_modeWidth, *m_modeHeight, *m_modeRefresh, *m_modeUpdate, *m_modeDelete,
|
||||
*m_autosizeGroup, *m_defRefreshLabel, *m_defRefresh, *m_defRefreshHz,
|
||||
}))
|
||||
SendMessage(child, WM_SETFONT, (WPARAM)m_font.Get(), 1);
|
||||
}
|
||||
|
||||
void CConfigWindow::updateModeList()
|
||||
{
|
||||
m_modeBox->addItem(L"<add new>", -1);
|
||||
|
||||
auto &modes = *m_modes;
|
||||
for (size_t i = 0; i < modes.size(); ++i)
|
||||
m_modeBox->addItem(modes[i].toString(), i);
|
||||
}
|
||||
|
||||
LRESULT CConfigWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
@@ -93,26 +103,31 @@ LRESULT CConfigWindow::onCreate()
|
||||
|
||||
m_modeGroup.reset(new CGroupBox(L"Custom modes", WS_CHILD | WS_VISIBLE, m_hwnd));
|
||||
|
||||
m_modeBox.reset(new CListBox(WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOTIFY, m_hwnd));
|
||||
m_modeBox.reset(new CListBox(WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | LBS_NOTIFY, m_hwnd));
|
||||
if (m_modes)
|
||||
{
|
||||
m_modeBox->addItem(L"<add new>", -1);
|
||||
|
||||
auto &modes = *m_modes;
|
||||
for (size_t i = 0; i < modes.size(); ++i)
|
||||
m_modeBox->addItem(modes[i].toString(), i);
|
||||
}
|
||||
updateModeList();
|
||||
|
||||
m_widthLabel.reset(new CStaticWidget(L"Width:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
m_heightLabel.reset(new CStaticWidget(L"Height:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
m_refreshLabel.reset(new CStaticWidget(L"Refresh:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
|
||||
m_modeWidth.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
|
||||
m_modeHeight.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
|
||||
m_modeRefresh.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
|
||||
m_modeWidth.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_NUMBER, m_hwnd));
|
||||
m_modeHeight.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_NUMBER, m_hwnd));
|
||||
m_modeRefresh.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_NUMBER, m_hwnd));
|
||||
|
||||
m_modeUpdate.reset(new CButton(L"Save", WS_CHILD | WS_VISIBLE, m_hwnd));
|
||||
m_modeUpdate.reset(new CButton(L"Save", WS_CHILD | WS_VISIBLE | WS_TABSTOP, m_hwnd));
|
||||
m_modeDelete.reset(new CButton(L"Delete", WS_CHILD | WS_VISIBLE | WS_TABSTOP, m_hwnd));
|
||||
EnableWindow(*m_modeUpdate, FALSE);
|
||||
EnableWindow(*m_modeDelete, FALSE);
|
||||
|
||||
m_autosizeGroup.reset(new CGroupBox(L"Autosizing", WS_CHILD | WS_VISIBLE, m_hwnd));
|
||||
m_defRefreshLabel.reset(new CStaticWidget(L"Default refresh:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
m_defRefresh.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT | ES_NUMBER | WS_TABSTOP, m_hwnd));
|
||||
m_defRefreshHz.reset(new CStaticWidget(L"Hz", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
|
||||
RECT client = { 0, 0, (LONG)(436 * m_scale), (LONG)(300 * m_scale) };
|
||||
AdjustWindowRect(&client, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
SetWindowPos(m_hwnd, NULL, 0, 0, client.right - client.left, client.bottom - client.top, SWP_NOMOVE | SWP_NOZORDER);
|
||||
|
||||
updateFont();
|
||||
|
||||
@@ -130,6 +145,7 @@ LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
|
||||
{
|
||||
WidgetPositioner pos(m_scale, width, height);
|
||||
pos.pinTopLeftRight(*m_version, 12, 12, 12, 20);
|
||||
|
||||
pos.pinLeftTopBottom(*m_modeGroup, 12, 40, 200, 12);
|
||||
pos.pinLeftTopBottom(*m_modeBox, 24, 64, 176, 120);
|
||||
pos.pinBottomLeft(*m_widthLabel, 24, 96, 50, 20);
|
||||
@@ -139,36 +155,43 @@ LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
|
||||
pos.pinBottomLeft(*m_modeHeight, 75, 72, 50, 20);
|
||||
pos.pinBottomLeft(*m_modeRefresh, 75, 48, 50, 20);
|
||||
pos.pinBottomLeft(*m_modeUpdate, 24, 20, 50, 24);
|
||||
pos.pinBottomLeft(*m_modeDelete, 75, 20, 50, 24);
|
||||
|
||||
pos.pinTopLeft(*m_autosizeGroup, 224, 40, 200, 52);
|
||||
pos.pinTopLeft(*m_defRefreshLabel, 236, 64, 95, 20);
|
||||
pos.pinTopLeft(*m_defRefresh, 331, 64, 63, 20);
|
||||
pos.pinTopLeft(*m_defRefreshHz, 398, 64, 16, 20);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CConfigWindow::onModeListSelectChange()
|
||||
{
|
||||
int sel = m_modeBox->getSel();
|
||||
if (sel == LB_ERR)
|
||||
{
|
||||
EnableWindow(*m_modeUpdate, FALSE);
|
||||
EnableWindow(*m_modeDelete, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = m_modeBox->getData(sel);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
auto &mode = (*m_modes)[index];
|
||||
m_modeWidth->setNumericValue(mode.width);
|
||||
m_modeHeight->setNumericValue(mode.height);
|
||||
m_modeRefresh->setNumericValue(mode.refresh);
|
||||
}
|
||||
EnableWindow(*m_modeUpdate, TRUE);
|
||||
EnableWindow(*m_modeDelete, index >= 0);
|
||||
}
|
||||
|
||||
LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
|
||||
{
|
||||
if (hwnd == *m_modeBox && code == LBN_SELCHANGE && m_modes)
|
||||
{
|
||||
int sel = m_modeBox->getSel();
|
||||
if (sel == LB_ERR)
|
||||
{
|
||||
EnableWindow(*m_modeUpdate, FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int index = m_modeBox->getData(sel);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
auto &mode = (*m_modes)[index];
|
||||
m_modeWidth->setNumericValue(mode.width);
|
||||
m_modeHeight->setNumericValue(mode.height);
|
||||
m_modeRefresh->setNumericValue(mode.refresh);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_modeWidth->setValue(L"");
|
||||
m_modeHeight->setValue(L"");
|
||||
m_modeRefresh->setValue(L"");
|
||||
}
|
||||
EnableWindow(*m_modeUpdate, TRUE);
|
||||
onModeListSelectChange();
|
||||
}
|
||||
else if (hwnd == *m_modeUpdate && code == BN_CLICKED && m_modes)
|
||||
{
|
||||
@@ -178,9 +201,17 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
|
||||
|
||||
int index = m_modeBox->getData(sel);
|
||||
auto &mode = index >= 0 ? (*m_modes)[index] : m_modes->emplace_back();
|
||||
mode.width = m_modeWidth->getNumericValue();
|
||||
mode.height = m_modeHeight->getNumericValue();
|
||||
mode.refresh = m_modeRefresh->getNumericValue();
|
||||
|
||||
try
|
||||
{
|
||||
mode.width = m_modeWidth->getNumericValue();
|
||||
mode.height = m_modeHeight->getNumericValue();
|
||||
mode.refresh = m_modeRefresh->getNumericValue();
|
||||
}
|
||||
catch (std::logic_error&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (index >= 0)
|
||||
m_modeBox->delItem(sel);
|
||||
@@ -189,7 +220,24 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
|
||||
|
||||
LRESULT result = m_settings.setModes(*m_modes);
|
||||
if (result != ERROR_SUCCESS)
|
||||
DEBUG_ERROR_HR(result, "Failed to save modes");
|
||||
DEBUG_ERROR_HR((HRESULT) result, "Failed to save modes");
|
||||
}
|
||||
else if (hwnd == *m_modeDelete && code == BN_CLICKED && m_modes)
|
||||
{
|
||||
int sel = m_modeBox->getSel();
|
||||
if (sel == LB_ERR)
|
||||
return 0;
|
||||
|
||||
int index = m_modeBox->getData(sel);
|
||||
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();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,12 @@ class CConfigWindow : public CWindow
|
||||
std::unique_ptr<CEditWidget> m_modeRefresh;
|
||||
|
||||
std::unique_ptr<CButton> m_modeUpdate;
|
||||
std::unique_ptr<CButton> m_modeDelete;
|
||||
|
||||
std::unique_ptr<CGroupBox> m_autosizeGroup;
|
||||
std::unique_ptr<CStaticWidget> m_defRefreshLabel;
|
||||
std::unique_ptr<CEditWidget> m_defRefresh;
|
||||
std::unique_ptr<CStaticWidget> m_defRefreshHz;
|
||||
|
||||
std::function<void()> m_onDestroy;
|
||||
double m_scale;
|
||||
@@ -38,6 +44,8 @@ class CConfigWindow : public CWindow
|
||||
std::optional<std::vector<DisplayMode>> m_modes;
|
||||
|
||||
void updateFont();
|
||||
void updateModeList();
|
||||
void onModeListSelectChange();
|
||||
|
||||
virtual LRESULT handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
|
||||
virtual LRESULT onCreate() override;
|
||||
|
||||
@@ -15,7 +15,7 @@ std::wstring CEditWidget::getValue()
|
||||
{
|
||||
std::wstring result;
|
||||
result.resize(Edit_GetTextLength(m_hwnd));
|
||||
Edit_GetText(m_hwnd, result.data(), result.size() + 1);
|
||||
Edit_GetText(m_hwnd, result.data(), (int) (result.size() + 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ int CListBox::getSel()
|
||||
|
||||
int CListBox::getData(int index)
|
||||
{
|
||||
return ListBox_GetItemData(m_hwnd, index);
|
||||
return (int) ListBox_GetItemData(m_hwnd, index);
|
||||
}
|
||||
|
||||
void CListBox::setSel(int index)
|
||||
@@ -50,3 +50,8 @@ void CListBox::setSel(int index)
|
||||
if (!ListBox_SetCurSel(m_hwnd, index))
|
||||
DEBUG_ERROR("listbox: failed to set selection to %d", index);
|
||||
}
|
||||
|
||||
void CListBox::clear()
|
||||
{
|
||||
ListBox_ResetContent(m_hwnd);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ public:
|
||||
int getSel();
|
||||
int getData(int index);
|
||||
void setSel(int index);
|
||||
void clear();
|
||||
};
|
||||
|
||||
@@ -51,6 +51,7 @@ LRESULT CNotifyWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
case WM_NOTIFY_ICON:
|
||||
return onNotifyIcon(LOWORD(lParam), HIWORD(lParam), GET_X_LPARAM(wParam), GET_Y_LPARAM(wParam));
|
||||
|
||||
case WM_CLEAN_UP_CONFIG:
|
||||
if (m_config && !m_config->hwnd())
|
||||
{
|
||||
@@ -58,6 +59,7 @@ LRESULT CNotifyWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
m_config.reset();
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
if (s_taskbarCreated && uMsg == s_taskbarCreated)
|
||||
{
|
||||
@@ -70,6 +72,9 @@ LRESULT CNotifyWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
LRESULT CNotifyWindow::onCreate()
|
||||
{
|
||||
// Allow explorer to send us this message to register the notification icon.
|
||||
ChangeWindowMessageFilterEx(m_hwnd, s_taskbarCreated, MSGFLT_ALLOW, NULL);
|
||||
|
||||
registerIcon();
|
||||
return 0;
|
||||
}
|
||||
@@ -129,12 +134,20 @@ void CNotifyWindow::registerIcon()
|
||||
StringCbCopy(m_iconData.szTip, sizeof m_iconData.szTip, L"Looking Glass (IDD)");
|
||||
|
||||
if (!Shell_NotifyIcon(NIM_ADD, &m_iconData))
|
||||
{
|
||||
DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_ADD)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Shell_NotifyIcon(NIM_SETVERSION, &m_iconData))
|
||||
DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_SETVERSION)");
|
||||
}
|
||||
|
||||
HWND CNotifyWindow::hwndDialog()
|
||||
{
|
||||
return m_config ? m_config->hwnd() : nullptr;
|
||||
}
|
||||
|
||||
void CNotifyWindow::close()
|
||||
{
|
||||
closeRequested = true;
|
||||
|
||||
@@ -28,5 +28,6 @@ public:
|
||||
~CNotifyWindow() override;
|
||||
static bool registerClass();
|
||||
|
||||
HWND hwndDialog();
|
||||
void close();
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <regex>
|
||||
#include <CDebug.h>
|
||||
|
||||
#include "DefaultDisplayModes.h"
|
||||
|
||||
#define LGIDD_REGKEY L"SOFTWARE\\LookingGlass\\IDD"
|
||||
|
||||
CRegistrySettings::CRegistrySettings() : hKey(nullptr) {}
|
||||
@@ -60,8 +62,25 @@ std::optional<std::vector<DisplayMode>> CRegistrySettings::getModes()
|
||||
|
||||
DWORD type = 0, cb = 0;
|
||||
status = RegGetValue(hKey, nullptr, L"Modes", RRF_RT_REG_MULTI_SZ, &type, nullptr, &cb);
|
||||
if (status != ERROR_SUCCESS)
|
||||
switch (status)
|
||||
{
|
||||
case ERROR_SUCCESS:
|
||||
break;
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
{
|
||||
std::vector<DisplayMode> result;
|
||||
for (int i = 0; i < ARRAYSIZE(DefaultDisplayModes); ++i)
|
||||
{
|
||||
DisplayMode mode;
|
||||
mode.width = DefaultDisplayModes[i][0];
|
||||
mode.height = DefaultDisplayModes[i][1];
|
||||
mode.refresh = DefaultDisplayModes[i][2];
|
||||
mode.preferred = i == DefaultPreferredDisplayMode;
|
||||
result.emplace_back(mode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
DEBUG_ERROR_HR(status, "RegGetValue(Modes) length computation");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -105,8 +105,12 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0) > 0)
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
HWND hDlg = window.hwndDialog();
|
||||
if (!hDlg || !IsDialogMessage(hDlg, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
(void) UnregisterWait(hWait);
|
||||
|
||||
Reference in New Issue
Block a user