From 91274c58b1772dfe38d3fcab291693141e822684 Mon Sep 17 00:00:00 2001 From: Daniel <49284193+dnlkrs@users.noreply.github.com> Date: 周五, 06 12月 2024 21:55:30 +0800 Subject: [PATCH] Fix WindowsRegistryKey for Qt 6.8.1 (#154) --- src/core/shared/qwkwindowsextra_p.h | 52 +++++++++++++++++++++++++--------------------------- 1 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/core/shared/qwkwindowsextra_p.h b/src/core/shared/qwkwindowsextra_p.h index 29f69d0..52d8943 100644 --- a/src/core/shared/qwkwindowsextra_p.h +++ b/src/core/shared/qwkwindowsextra_p.h @@ -1,3 +1,7 @@ +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) +// SPDX-License-Identifier: Apache-2.0 + #ifndef QWKWINDOWSEXTRA_P_H #define QWKWINDOWSEXTRA_P_H @@ -15,9 +19,7 @@ #include <timeapi.h> #include <QWKCore/qwindowkit_windows.h> - #include <QtCore/private/qsystemlibrary_p.h> -#include <QtCore/private/qwinregistry_p.h> #include <QtGui/QGuiApplication> #include <QtGui/QStyleHints> @@ -132,12 +134,14 @@ }; using PWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA *; - enum PREFERRED_APP_MODE - { - PAM_DEFAULT = 0, // Default behavior on systems before Win10 1809. It indicates the application doesn't support dark mode at all. - PAM_AUTO = 1, // Available since Win10 1809, let system decide whether to enable dark mode or not. - PAM_DARK = 2, // Available since Win10 1903, force dark mode regardless of the system theme. - PAM_LIGHT = 3, // Available since Win10 1903, force light mode regardless of the system theme. + enum PREFERRED_APP_MODE { + PAM_DEFAULT = 0, // Default behavior on systems before Win10 1809. It indicates the + // application doesn't support dark mode at all. + PAM_AUTO = + 1, // Available since Win10 1809, let system decide whether to enable dark mode or not. + PAM_DARK = 2, // Available since Win10 1903, force dark mode regardless of the system theme. + PAM_LIGHT = + 3, // Available since Win10 1903, force light mode regardless of the system theme. PAM_MAX = 4 }; @@ -155,7 +159,7 @@ struct DynamicApis { static const DynamicApis &instance() { - static const DynamicApis inst{}; + static const DynamicApis inst; return inst; } @@ -230,7 +234,7 @@ ~DynamicApis() = default; - Q_DISABLE_COPY_MOVE(DynamicApis) + Q_DISABLE_COPY(DynamicApis) }; } @@ -337,15 +341,12 @@ } static inline bool isWindowFrameBorderColorized() { - QWinRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); + WindowsRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); if (!registry.isValid()) { return false; } - auto value = registry.dwordValue(L"ColorPrevalence"); - if (!value.second) { - return false; - } - return value.first; + auto value = registry.value<DWORD>(L"ColorPrevalence"); + return value.value_or(false); } static inline bool isHighContrastModeEnabled() { @@ -359,16 +360,13 @@ #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark; #else - QWinRegistryKey registry( + WindowsRegistryKey registry( HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"); if (!registry.isValid()) { return false; } - auto value = registry.dwordValue(L"AppsUseLightTheme"); - if (!value.second) { - return false; - } - return !value.first; + auto value = registry.value<DWORD>(L"AppsUseLightTheme"); + return value.value_or(false); #endif } @@ -390,17 +388,17 @@ #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) return QGuiApplication::palette().color(QPalette::Accent); #else - QWinRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); + WindowsRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); if (!registry.isValid()) { return {}; } - auto value = registry.dwordValue(L"AccentColor"); - if (!value.second) { + auto value = registry.value<DWORD>(L"AccentColor"); + if (!value) { return {}; } // The retrieved value is in the #AABBGGRR format, we need to // convert it to the #AARRGGBB format which Qt expects. - QColor color = QColor::fromRgba(value.first); + QColor color = QColor::fromRgba(*value); if (!color.isValid()) { return {}; } @@ -430,7 +428,7 @@ static inline quint32 getSystemMetricsForDpi(int index, quint32 dpi) { const DynamicApis &apis = DynamicApis::instance(); if (apis.pGetSystemMetricsForDpi) { - return ::GetSystemMetricsForDpi(index, dpi); + return apis.pGetSystemMetricsForDpi(index, dpi); } return ::GetSystemMetrics(index); } -- Gitblit v1.9.1