Skip to content

Commit 782a520

Browse files
committed
Update WinRegistry
1 parent be0d95b commit 782a520

File tree

3 files changed

+44
-49
lines changed

3 files changed

+44
-49
lines changed

src/core/qwindowkit_windows.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,5 @@ namespace QWK {
8787
reinterpret_cast<unsigned char *>(&value), &size) == ERROR_SUCCESS;
8888
return qMakePair(value, ok);
8989
}
90-
#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
91-
WindowsRegistryKey::WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions, REGSAM access)
92-
: QWinRegistryKey(parentHandle, subKey, permissions, access)
93-
{
94-
}
9590
#endif
9691
}

src/core/qwindowkit_windows.h

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ namespace QWK {
6262
inline bool IsWindows1122H2OrGreater_Real() {
6363
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
6464
return (rovi.dwMajorVersion > 10) ||
65-
(rovi.dwMajorVersion == 10 && (rovi.dwMinorVersion > 0 ||
66-
rovi.dwBuildNumber >= 22621));
65+
(rovi.dwMajorVersion == 10 &&
66+
(rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 22621));
6767
}
6868

6969
inline bool IsWindows11OrGreater_Real() {
7070
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
7171
return (rovi.dwMajorVersion > 10) ||
72-
(rovi.dwMajorVersion == 10 && (rovi.dwMinorVersion > 0 ||
73-
rovi.dwBuildNumber >= 22000));
72+
(rovi.dwMajorVersion == 10 &&
73+
(rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 22000));
7474
}
7575

7676
inline bool IsWindows1020H1OrGreater_Real() {
7777
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
7878
return (rovi.dwMajorVersion > 10) ||
79-
(rovi.dwMajorVersion == 10 && (rovi.dwMinorVersion > 0 ||
80-
rovi.dwBuildNumber >= 19041));
79+
(rovi.dwMajorVersion == 10 &&
80+
(rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 19041));
8181
}
8282

8383
inline bool IsWindows102004OrGreater_Real() {
@@ -87,8 +87,8 @@ namespace QWK {
8787
inline bool IsWindows101903OrGreater_Real() {
8888
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
8989
return (rovi.dwMajorVersion > 10) ||
90-
(rovi.dwMajorVersion == 10 && (rovi.dwMinorVersion > 0 ||
91-
rovi.dwBuildNumber >= 18362));
90+
(rovi.dwMajorVersion == 10 &&
91+
(rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 18362));
9292
}
9393

9494
inline bool IsWindows1019H1OrGreater_Real() {
@@ -98,8 +98,8 @@ namespace QWK {
9898
inline bool IsWindows101809OrGreater_Real() {
9999
RTL_OSVERSIONINFOW rovi = GetRealOSVersion();
100100
return (rovi.dwMajorVersion > 10) ||
101-
(rovi.dwMajorVersion == 10 && (rovi.dwMinorVersion > 0 ||
102-
rovi.dwBuildNumber >= 17763));
101+
(rovi.dwMajorVersion == 10 &&
102+
(rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 17763));
103103
}
104104

105105
inline bool IsWindows10RS5OrGreater_Real() {
@@ -147,9 +147,6 @@ namespace QWK {
147147
QString stringValue(QStringView subKey) const;
148148
QPair<DWORD, bool> dwordValue(QStringView subKey) const;
149149

150-
template<typename T>
151-
std::optional<T> value(QStringView subKey) const;
152-
153150
private:
154151
HKEY m_key;
155152

@@ -159,34 +156,26 @@ namespace QWK {
159156
inline bool WindowsRegistryKey::isValid() const {
160157
return m_key != nullptr;
161158
}
162-
163-
template<>
164-
inline std::optional<DWORD> WindowsRegistryKey::value(QStringView subKey) const {
165-
const auto dv = dwordValue(subKey);
166-
if (!dv.second) {
167-
return {};
168-
}
169-
return dv.first;
170-
}
171159
#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
160+
using WindowsRegistryKey = QWinRegistryKey;
161+
#else
172162
class WindowsRegistryKey : public QWinRegistryKey {
173163
public:
174-
WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions = KEY_READ, REGSAM access = 0);
164+
WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions = KEY_READ,
165+
REGSAM access = 0)
166+
: QWinRegistryKey(parentHandle, subKey, permissions, access) {
167+
}
175168

176-
template<typename T>
177-
std::optional<T> value(QStringView subKey) const;
169+
inline QPair<DWORD, bool> dwordValue(QStringView subKey) const;
178170
};
179171

180-
template<>
181-
inline std::optional<DWORD> WindowsRegistryKey::value(QStringView subKey) const {
182-
const auto dv = dwordValue(subKey);
183-
if (!dv.second) {
184-
return {};
172+
inline QPair<DWORD, bool> WindowsRegistryKey::dwordValue(QStringView subKey) const {
173+
const auto val = value<DWORD>(subKey);
174+
if (!val) {
175+
return {0, false};
185176
}
186-
return dv.first;
177+
return {val.value(), true};
187178
}
188-
#else
189-
using WindowsRegistryKey = QWinRegistryKey;
190179
#endif
191180

192181
//

src/core/shared/qwkwindowsextra_p.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
#include <timeapi.h>
2020

2121
#include <QWKCore/qwindowkit_windows.h>
22-
#include <QtCore/private/qsystemlibrary_p.h>
2322

23+
#include <QtCore/QtMath>
24+
#include <QtCore/QPair>
2425
#include <QtGui/QGuiApplication>
2526
#include <QtGui/QStyleHints>
2627
#include <QtGui/QPalette>
2728

29+
#include <QtCore/private/qsystemlibrary_p.h>
30+
2831
// Don't include this header in any header files.
2932

3033
namespace QWK {
@@ -345,8 +348,11 @@ namespace QWK {
345348
if (!registry.isValid()) {
346349
return false;
347350
}
348-
auto value = registry.value<DWORD>(L"ColorPrevalence");
349-
return value.value_or(false);
351+
auto value = registry.dwordValue(L"ColorPrevalence");
352+
if (!value.second) {
353+
return false;
354+
}
355+
return value.first;
350356
}
351357

352358
inline bool isHighContrastModeEnabled() {
@@ -368,8 +374,11 @@ namespace QWK {
368374
if (!registry.isValid()) {
369375
return false;
370376
}
371-
auto value = registry.value<DWORD>(L"AppsUseLightTheme");
372-
return value.value_or(false);
377+
auto value = registry.dwordValue(L"AppsUseLightTheme");
378+
if (!value.second) {
379+
return false;
380+
}
381+
return !value.first;
373382
#endif
374383
}
375384

@@ -379,8 +388,10 @@ namespace QWK {
379388
}
380389
BOOL enabled = FALSE;
381390
const DynamicApis &apis = DynamicApis::instance();
382-
const auto attr = isWin1020H1OrGreater() ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
383-
return SUCCEEDED(apis.pDwmGetWindowAttribute(hwnd, attr, &enabled, sizeof(enabled))) && enabled;
391+
const auto attr = isWin1020H1OrGreater() ? _DWMWA_USE_IMMERSIVE_DARK_MODE
392+
: _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
393+
return SUCCEEDED(apis.pDwmGetWindowAttribute(hwnd, attr, &enabled, sizeof(enabled))) &&
394+
enabled;
384395
}
385396

386397
inline QColor getAccentColor() {
@@ -391,13 +402,13 @@ namespace QWK {
391402
if (!registry.isValid()) {
392403
return {};
393404
}
394-
auto value = registry.value<DWORD>(L"AccentColor");
395-
if (!value) {
405+
auto value = registry.dwordValue(L"AccentColor");
406+
if (!value.second) {
396407
return {};
397408
}
398409
// The retrieved value is in the #AABBGGRR format, we need to
399410
// convert it to the #AARRGGBB format which Qt expects.
400-
QColor color = QColor::fromRgba(*value);
411+
QColor color = QColor::fromRgba(value.first);
401412
if (!color.isValid()) {
402413
return {};
403414
}
@@ -407,7 +418,7 @@ namespace QWK {
407418

408419
inline quint32 getDpiForWindow(HWND hwnd) {
409420
const DynamicApis &apis = DynamicApis::instance();
410-
if (apis.pGetDpiForWindow) { // Win10
421+
if (apis.pGetDpiForWindow) { // Win10
411422
return apis.pGetDpiForWindow(hwnd);
412423
} else if (apis.pGetDpiForMonitor) { // Win8.1
413424
HMONITOR monitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

0 commit comments

Comments
 (0)