[idd] helper: use registry boolean helper instead of duplication
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled

This commit is contained in:
Quantum
2026-08-16 15:48:41 -04:00
committed by Geoffrey McRae
parent 2005ea5d69
commit cec1a16cfc
2 changed files with 25 additions and 55 deletions

View File

@@ -220,98 +220,65 @@ LSTATUS CRegistrySettings::setDefaultRefresh(DWORD refresh100uHz)
(DWORD)((value.size() + 1) * sizeof(wchar_t))); (DWORD)((value.size() + 1) * sizeof(wchar_t)));
} }
std::optional<bool> CRegistrySettings::getNoGPU() std::optional<bool> CRegistrySettings::readBooleanSetting(LPCWSTR szName, bool fallback)
{ {
DWORD result, cbData = sizeof result; DWORD result, cbData = sizeof result;
LSTATUS status = RegGetValue(hKey, nullptr, L"NoGPU", RRF_RT_REG_DWORD, nullptr, &result, &cbData); LSTATUS status = RegGetValue(hKey, nullptr, szName, RRF_RT_REG_DWORD, nullptr, &result, &cbData);
switch (status) switch (status)
{ {
case ERROR_SUCCESS: case ERROR_SUCCESS:
return !!result; return !!result;
case ERROR_FILE_NOT_FOUND: case ERROR_FILE_NOT_FOUND:
return false; return fallback;
default: default:
DEBUG_ERROR_HR(status, "RegGetValue(NoGPU)"); DEBUG_ERROR_HR(status, "RegGetValue(%S)", szName);
return {}; return {};
} }
} }
LSTATUS CRegistrySettings::writeBooleanSetting(LPCWSTR szName, bool value)
{
DWORD dwValue = value;
return RegSetValueEx(hKey, szName, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
}
std::optional<bool> CRegistrySettings::getNoGPU()
{
return readBooleanSetting(L"NoGPU");
}
LSTATUS CRegistrySettings::setNoGPU(bool noGPU) LSTATUS CRegistrySettings::setNoGPU(bool noGPU)
{ {
DWORD dwValue = noGPU; return writeBooleanSetting(L"NoGPU", noGPU);
return RegSetValueEx(hKey, L"NoGPU", 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
} }
std::optional<bool> CRegistrySettings::getExclusiveMonitor() std::optional<bool> CRegistrySettings::getExclusiveMonitor()
{ {
DWORD result, cbData = sizeof result; return readBooleanSetting(L"ExclusiveMonitor", true);
LSTATUS status = RegGetValue(hKey, nullptr, L"ExclusiveMonitor", RRF_RT_REG_DWORD, nullptr, &result, &cbData);
switch (status)
{
case ERROR_SUCCESS:
return !!result;
case ERROR_FILE_NOT_FOUND:
return true;
default:
DEBUG_ERROR_HR(status, "RegGetValue(ExclusiveMonitor)");
return {};
}
} }
LSTATUS CRegistrySettings::setExclusiveMonitor(bool exclusive) LSTATUS CRegistrySettings::setExclusiveMonitor(bool exclusive)
{ {
DWORD dwValue = exclusive; return writeBooleanSetting(L"ExclusiveMonitor", exclusive);
return RegSetValueEx(hKey, L"ExclusiveMonitor", 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
} }
std::optional<bool> CRegistrySettings::getForceFullDirectCopy() std::optional<bool> CRegistrySettings::getForceFullDirectCopy()
{ {
DWORD result, cbData = sizeof result; return readBooleanSetting(L"ForceFullDirectCopy");
LSTATUS status = RegGetValue(hKey, nullptr, L"ForceFullDirectCopy",
RRF_RT_REG_DWORD, nullptr, &result, &cbData);
switch (status)
{
case ERROR_SUCCESS:
return !!result;
case ERROR_FILE_NOT_FOUND:
return false;
default:
DEBUG_ERROR_HR(status, "RegGetValue(ForceFullDirectCopy)");
return {};
}
} }
LSTATUS CRegistrySettings::setForceFullDirectCopy(bool forceFullCopy) LSTATUS CRegistrySettings::setForceFullDirectCopy(bool forceFullCopy)
{ {
DWORD dwValue = forceFullCopy; return writeBooleanSetting(L"ForceFullDirectCopy", forceFullCopy);
return RegSetValueEx(hKey, L"ForceFullDirectCopy", 0, REG_DWORD,
(LPBYTE)&dwValue, sizeof(DWORD));
} }
std::optional<bool> CRegistrySettings::getForceIndirectCopy() std::optional<bool> CRegistrySettings::getForceIndirectCopy()
{ {
DWORD result, cbData = sizeof result; return readBooleanSetting(L"ForceIndirectCopy");
LSTATUS status = RegGetValue(hKey, nullptr, L"ForceIndirectCopy",
RRF_RT_REG_DWORD, nullptr, &result, &cbData);
switch (status)
{
case ERROR_SUCCESS:
return !!result;
case ERROR_FILE_NOT_FOUND:
return false;
default:
DEBUG_ERROR_HR(status, "RegGetValue(ForceIndirectCopy)");
return {};
}
} }
LSTATUS CRegistrySettings::setForceIndirectCopy(bool forceIndirectCopy) LSTATUS CRegistrySettings::setForceIndirectCopy(bool forceIndirectCopy)
{ {
DWORD dwValue = forceIndirectCopy; return writeBooleanSetting(L"ForceIndirectCopy", forceIndirectCopy);
return RegSetValueEx(hKey, L"ForceIndirectCopy", 0, REG_DWORD,
(LPBYTE)&dwValue, sizeof(DWORD));
} }

View File

@@ -37,6 +37,9 @@ struct DisplayMode {
class CRegistrySettings { class CRegistrySettings {
HKEY hKey; HKEY hKey;
std::optional<bool> readBooleanSetting(LPCWSTR szName, bool fallback = false);
LSTATUS writeBooleanSetting(LPCWSTR szName, bool value);
public: public:
CRegistrySettings(); CRegistrySettings();
~CRegistrySettings(); ~CRegistrySettings();