Skip to content

Commit

Permalink
Use QOperatingSystemVersion in Windows 11 check
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored and mgallien committed Nov 19, 2024
1 parent b26eb27 commit 3097ce3
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -971,7 +959,7 @@ void Theme::connectToPaletteSignal()
if (const auto ptr = qobject_cast<QGuiApplication *>(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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3097ce3

Please sign in to comment.