From 3097ce3bb3ed0c575d38545d0e5c498927a5e2d2 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sun, 10 Nov 2024 19:12:57 +0800 Subject: [PATCH] Use QOperatingSystemVersion in Windows 11 check Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index e6894791508db..ea4bd466cb125 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -67,20 +67,8 @@ bool shouldPreferSvg() } #ifdef Q_OS_WIN -bool IsWindows11OrGreater() { - OSVERSIONINFOEX osvi = {}; - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - osvi.dwMajorVersion = 10; - osvi.dwMinorVersion = 0; - osvi.dwBuildNumber = 22000; - - DWORDLONG const conditionMask = VerSetConditionMask( - VerSetConditionMask( - VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), - VER_MINORVERSION, VER_GREATER_EQUAL), - VER_BUILDNUMBER, VER_GREATER_EQUAL); - - return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, conditionMask) != 0; +bool isWindows11OrGreater() { + return QOperatingSystemVersion::current().majorVersion() >= QOperatingSystemVersion::Windows11.majorVersion(); } #endif @@ -971,7 +959,7 @@ void Theme::connectToPaletteSignal() if (const auto ptr = qobject_cast(QGuiApplication::instance())) { #ifdef Q_OS_WIN // Windows 10 does not have proper dark mode support via Qt 6 so hack detection - if (!IsWindows11OrGreater()) { + if (!isWindows11OrGreater()) { connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged); } else #endif @@ -988,7 +976,7 @@ QVariantMap Theme::systemPalette() connectToPaletteSignal(); auto systemPalette = QGuiApplication::palette(); #if defined(Q_OS_WIN) - if (darkMode() && !IsWindows11OrGreater()) { + if (darkMode() && !isWindows11OrGreater()) { systemPalette = reserveDarkPalette; } #else @@ -1038,7 +1026,7 @@ bool Theme::darkMode() #ifdef Q_OS_WIN static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); - if (!IsWindows11OrGreater() && + if (!isWindows11OrGreater() && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) && !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) { return true;