Use QOperatingSystemVersion in Windows 11 check

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-11-10 19:12:57 +08:00 committed by Matthieu Gallien
parent 5f6712f442
commit e69b6cb4c6

View file

@ -67,20 +67,8 @@ bool shouldPreferSvg()
} }
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
bool IsWindows11OrGreater() { bool isWindows11OrGreater() {
OSVERSIONINFOEX osvi = {}; return QOperatingSystemVersion::current().majorVersion() >= QOperatingSystemVersion::Windows11.majorVersion();
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;
} }
#endif #endif
@ -971,7 +959,7 @@ void Theme::connectToPaletteSignal()
if (const auto ptr = qobject_cast<QGuiApplication *>(QGuiApplication::instance())) { if (const auto ptr = qobject_cast<QGuiApplication *>(QGuiApplication::instance())) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Windows 10 does not have proper dark mode support via Qt 6 so hack detection // 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); connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged);
} else } else
#endif #endif
@ -988,7 +976,7 @@ QVariantMap Theme::systemPalette()
connectToPaletteSignal(); connectToPaletteSignal();
auto systemPalette = QGuiApplication::palette(); auto systemPalette = QGuiApplication::palette();
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
if (darkMode() && !IsWindows11OrGreater()) { if (darkMode() && !isWindows11OrGreater()) {
systemPalette = reserveDarkPalette; systemPalette = reserveDarkPalette;
} }
#else #else
@ -1038,7 +1026,7 @@ bool Theme::darkMode()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (!IsWindows11OrGreater() && if (!isWindows11OrGreater() &&
Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) && Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
!Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) { !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
return true; return true;