From 06d2cca4121cc8a4bd885b127ecbc9ee3d165a9f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 17:03:14 +0900 Subject: [PATCH] Use registry-based dark mode detection on <= Windows 10 Signed-off-by: Claudio Cambra f dete Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index caf137667171..e2202a3cae85 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -1022,17 +1022,28 @@ QVariantMap Theme::systemPalette() bool Theme::darkMode() { connectToPaletteSignal(); - switch (qGuiApp->styleHints()->colorScheme()) - { - case Qt::ColorScheme::Dark: - return true; - case Qt::ColorScheme::Light: + const auto isDarkFromStyle = [] { + switch (qGuiApp->styleHints()->colorScheme()) + { + case Qt::ColorScheme::Dark: + return true; + case Qt::ColorScheme::Light: + return false; + case Qt::ColorScheme::Unknown: + return Theme::isDarkColor(QGuiApplication::palette().window().color()); + } + return false; - case Qt::ColorScheme::Unknown: - return Theme::isDarkColor(QGuiApplication::palette().window().color()); - } + }; - return false; +#ifdef Q_OS_WIN + if (!IsWindows11OrGreater() && + Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) && + !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) { + return true; + } +#endif + return isDarkFromStyle(); } void Theme::setOverrideServerUrl(const QString &overrideServerUrl)