From 1f4f7c7d0f3c1edf0c5dc2abc1b1fe6f494054b8 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 16:56:00 +0900 Subject: [PATCH 01/11] Revert "remove broken system paellete detection within our custom style" This reverts commit 2d08cdb503c69392ac5cb3eddf514f0550953ed8. Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/libsync/theme.h | 3 +++ theme/Style/Style.qml | 9 +++------ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index d10d50be4f650..e699cf4d136a3 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -947,12 +947,49 @@ void Theme::connectToPaletteSignal() { if (!_paletteSignalsConnected) { if (const auto ptr = qobject_cast(QGuiApplication::instance())) { + connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::systemPaletteChanged); connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged); _paletteSignalsConnected = true; } } } +QVariantMap Theme::systemPalette() +{ + connectToPaletteSignal(); +#if defined(Q_OS_WIN) + auto systemPalette = QGuiApplication::palette(); + if(darkMode()) { + systemPalette = reserveDarkPalette; + } +#else + const auto systemPalette = QGuiApplication::palette(); +#endif + + return QVariantMap { + { QStringLiteral("base"), systemPalette.base().color() }, + { QStringLiteral("alternateBase"), systemPalette.alternateBase().color() }, + { QStringLiteral("text"), systemPalette.text().color() }, + { QStringLiteral("toolTipBase"), systemPalette.toolTipBase().color() }, + { QStringLiteral("toolTipText"), systemPalette.toolTipText().color() }, + { QStringLiteral("brightText"), systemPalette.brightText().color() }, + { QStringLiteral("buttonText"), systemPalette.buttonText().color() }, + { QStringLiteral("button"), systemPalette.button().color() }, + { QStringLiteral("highlightedText"), systemPalette.highlightedText().color() }, + { QStringLiteral("placeholderText"), systemPalette.placeholderText().color() }, + { QStringLiteral("windowText"), systemPalette.windowText().color() }, + { QStringLiteral("window"), systemPalette.window().color() }, + { QStringLiteral("dark"), systemPalette.dark().color() }, + { QStringLiteral("highlight"), systemPalette.highlight().color() }, + { QStringLiteral("light"), systemPalette.light().color() }, + { QStringLiteral("link"), systemPalette.link().color() }, + { QStringLiteral("midlight"), systemPalette.midlight().color() }, + { QStringLiteral("mid"), systemPalette.mid().color() }, + { QStringLiteral("linkVisited"), systemPalette.linkVisited().color() }, + { QStringLiteral("shadow"), systemPalette.shadow().color() }, + }; +} + bool Theme::darkMode() { connectToPaletteSignal(); diff --git a/src/libsync/theme.h b/src/libsync/theme.h index b414c9fa3fbe8..707cb07d555fc 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -67,6 +67,7 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject Q_PROPERTY(QColor defaultColor READ defaultColor CONSTANT) + Q_PROPERTY(QVariantMap systemPalette READ systemPalette NOTIFY systemPaletteChanged) Q_PROPERTY(bool darkMode READ darkMode NOTIFY darkModeChanged) public: enum CustomMediaType { @@ -600,6 +601,7 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject static constexpr const char *themePrefix = ":/client/theme/"; + QVariantMap systemPalette(); bool darkMode(); public slots: @@ -624,6 +626,7 @@ public slots: signals: void systrayUseMonoIconsChanged(bool); + void systemPaletteChanged(const QPalette &palette); void darkModeChanged(); void overrideServerUrlChanged(); void forceOverrideServerUrlChanged(); diff --git a/theme/Style/Style.qml b/theme/Style/Style.qml index 912aa10b8167b..2bb1905d3bd9c 100644 --- a/theme/Style/Style.qml +++ b/theme/Style/Style.qml @@ -8,20 +8,17 @@ QtObject { readonly property int pixelSize: fontMetrics.font.pixelSize readonly property bool darkMode: Theme.darkMode - property SystemPalette nativePalette: SystemPalette { - } - // Colors readonly property color ncBlue: Theme.wizardHeaderBackgroundColor readonly property color ncHeaderTextColor: Theme.wizardHeaderTitleColor - readonly property color ncTextColor: nativePalette.text + readonly property color ncTextColor: Theme.systemPalette.windowText readonly property color ncTextBrightColor: "white" readonly property color ncSecondaryTextColor: "#808080" readonly property color lightHover: Theme.darkMode ? Qt.lighter(backgroundColor, 2) : Qt.darker(backgroundColor, 1.05) readonly property color darkerHover: Theme.darkMode ? Qt.lighter(backgroundColor, 2.35) : Qt.darker(backgroundColor, 1.25) readonly property color menuBorder: Theme.darkMode ? Qt.lighter(backgroundColor, 2.5) : Qt.darker(backgroundColor, 1.5) - readonly property color backgroundColor: nativePalette.window - readonly property color buttonBackgroundColor: nativePalette.button + readonly property color backgroundColor: Theme.systemPalette.window + readonly property color buttonBackgroundColor: Theme.systemPalette.button readonly property color positiveColor: Qt.rgba(0.38, 0.74, 0.38, 1) readonly property color currentUserHeaderColor: UserModel.currentUser ? UserModel.currentUser.headerColor : ncBlue From 7c2102547d2264087cc2badc4ebfe3a474d4cafd Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 17:02:14 +0900 Subject: [PATCH 02/11] Add convenience method to check Windows 11 availability Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index e699cf4d136a3..2f9944b929fe8 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -33,6 +33,10 @@ #include #include +#ifdef Q_OS_WIN +#include +#endif + #include "nextcloudtheme.h" #ifdef THEME_INCLUDE @@ -62,6 +66,24 @@ bool shouldPreferSvg() return QByteArray(APPLICATION_ICON_SET).toUpper() == QByteArrayLiteral("SVG"); } +#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; +} +#endif + } namespace OCC { From d2d91bb10581e04d121daa9aab47071fa1e8215a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 17:02:32 +0900 Subject: [PATCH 03/11] Use old palette change detection method on Windows 10 and under Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 2f9944b929fe8..e69c34922e14b 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -969,8 +969,15 @@ void Theme::connectToPaletteSignal() { if (!_paletteSignalsConnected) { if (const auto ptr = qobject_cast(QGuiApplication::instance())) { - connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::systemPaletteChanged); - connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged); +#ifdef Q_OS_WIN + // Windows 10 does not have proper dark mode support via Qt 6 so hack detection + if (!IsWindows11OrGreater()) { + connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged); + } else +#endif + { + connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged); + } _paletteSignalsConnected = true; } } From 800b84d16518bfc730b9a027732b75a47e2b66a8 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 17:02:54 +0900 Subject: [PATCH 04/11] If <= Windows 10, use the reserve dark palette for dark mode Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index e69c34922e14b..44c2789b09beb 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -986,13 +986,13 @@ void Theme::connectToPaletteSignal() QVariantMap Theme::systemPalette() { connectToPaletteSignal(); -#if defined(Q_OS_WIN) auto systemPalette = QGuiApplication::palette(); - if(darkMode()) { +#if defined(Q_OS_WIN) + if (darkMode() && !IsWindows11OrGreater()) { systemPalette = reserveDarkPalette; } #else - const auto systemPalette = QGuiApplication::palette(); + #endif return QVariantMap { From 5f6712f442d355a89594284d22d553951c5ab7a6 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Nov 2024 17:03:14 +0900 Subject: [PATCH 05/11] Use registry-based dark mode detection on <= Windows 10 Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 44c2789b09beb..fef629491a86b 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -1022,17 +1022,29 @@ 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 + static const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"); + 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) From e69b6cb4c65a75e69593428266f57fe5f02c6876 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sun, 10 Nov 2024 19:12:57 +0800 Subject: [PATCH 06/11] 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 fef629491a86b..7eadcac3543bf 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; From 194f9187887dd0dad0920eda97d850921bcdd748 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 12 Nov 2024 14:11:24 +0100 Subject: [PATCH 07/11] use QWidget Fusion style on Windows 10: enable dark mode Signed-off-by: Matthieu Gallien --- src/gui/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/main.cpp b/src/gui/main.cpp index e91fb3be9a1f4..da946bc3b32c0 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -35,8 +35,11 @@ #include #include #include +#include +#include #include #include +#include using namespace OCC; @@ -82,6 +85,12 @@ int main(int argc, char **argv) QQuickStyle::setStyle(style); QQuickStyle::setFallbackStyle(QStringLiteral("Fusion")); +#if defined Q_OS_WIN + if (QOperatingSystemVersion::current().version() < QOperatingSystemVersion::Windows11.version()) { + QApplication::setStyle(QStyleFactory::create("Fusion")); + } +#endif + OCC::Application app(argc, argv); #ifndef Q_OS_WIN From bce61115ef6851543744e32cf921932689871b25 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 12 Nov 2024 14:12:07 +0100 Subject: [PATCH 08/11] create a log category for OCC::Theme class Signed-off-by: Matthieu Gallien --- src/libsync/theme.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 7eadcac3543bf..9a322f33808a9 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef Q_OS_WIN #include @@ -76,6 +77,8 @@ bool isWindows11OrGreater() { namespace OCC { +Q_LOGGING_CATEGORY(lcTheme, "nextcloud.gui.theme", QtInfoMsg) + Theme *Theme::_instance = nullptr; Theme *Theme::instance() From 1399a32edcadbb1f3a503e740aeaf4f3396a395e Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 12 Nov 2024 14:16:05 +0100 Subject: [PATCH 09/11] implement a drak mode palette and use it when needed for now unable to dynamically switch between light and dark mode Signed-off-by: Matthieu Gallien --- src/libsync/theme.cpp | 43 ++++++++++++++++++++++++++----------------- src/libsync/theme.h | 4 ++-- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 9a322f33808a9..05a8a1ba6b641 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -69,7 +69,7 @@ bool shouldPreferSvg() #ifdef Q_OS_WIN bool isWindows11OrGreater() { - return QOperatingSystemVersion::current().majorVersion() >= QOperatingSystemVersion::Windows11.majorVersion(); + return QOperatingSystemVersion::current().version() >= QOperatingSystemVersion::Windows11.version(); } #endif @@ -367,30 +367,40 @@ Theme::Theme() #if defined(Q_OS_WIN) // Windows does not provide a dark theme for Win32 apps so let's come up with a palette // Credit to https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle + reserveDarkPalette = qApp->palette(); - reserveDarkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); reserveDarkPalette.setColor(QPalette::WindowText, Qt::white); - reserveDarkPalette.setColor(QPalette::Disabled, QPalette::WindowText, - QColor(127, 127, 127)); + reserveDarkPalette.setColor(QPalette::Button, QColor(127, 127, 127)); + reserveDarkPalette.setColor(QPalette::Light, QColor(53, 53, 53)); + reserveDarkPalette.setColor(QPalette::Midlight, QColor(78, 78, 78)); + reserveDarkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); + reserveDarkPalette.setColor(QPalette::Mid, QColor(44, 44, 44)); + reserveDarkPalette.setColor(QPalette::Text, Qt::white); + reserveDarkPalette.setColor(QPalette::BrightText, Qt::red); + reserveDarkPalette.setColor(QPalette::ButtonText, Qt::white); reserveDarkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); + reserveDarkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); + reserveDarkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); + reserveDarkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); + reserveDarkPalette.setColor(QPalette::HighlightedText, Qt::white); + reserveDarkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); + reserveDarkPalette.setColor(QPalette::LinkVisited, QColor(42, 130, 218)); reserveDarkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); + reserveDarkPalette.setColor(QPalette::NoRole, QColor(127, 127, 127)); reserveDarkPalette.setColor(QPalette::ToolTipBase, Qt::white); reserveDarkPalette.setColor(QPalette::ToolTipText, QColor(53, 53, 53)); - reserveDarkPalette.setColor(QPalette::Text, Qt::white); + reserveDarkPalette.setColor(QPalette::PlaceholderText, QColor(44, 44, 44)); + reserveDarkPalette.setColor(QPalette::Accent, QColor(127, 127, 200)); + reserveDarkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); - reserveDarkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); - reserveDarkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); - reserveDarkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); - reserveDarkPalette.setColor(QPalette::ButtonText, Qt::white); reserveDarkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127)); - reserveDarkPalette.setColor(QPalette::BrightText, Qt::red); - reserveDarkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); - reserveDarkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); reserveDarkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); - reserveDarkPalette.setColor(QPalette::HighlightedText, Qt::white); reserveDarkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127)); + reserveDarkPalette.setColor(QPalette::Disabled, QPalette::WindowText, + QColor(127, 127, 127)); + connectToPaletteSignal(); #endif #ifdef APPLICATION_SERVER_URL_ENFORCE @@ -974,13 +984,13 @@ void Theme::connectToPaletteSignal() } } -QVariantMap Theme::systemPalette() +QVariantMap Theme::systemPalette() const { - connectToPaletteSignal(); auto systemPalette = QGuiApplication::palette(); #if defined(Q_OS_WIN) if (darkMode() && !isWindows11OrGreater()) { systemPalette = reserveDarkPalette; + qApp->setPalette(reserveDarkPalette); } #else @@ -1010,9 +1020,8 @@ QVariantMap Theme::systemPalette() }; } -bool Theme::darkMode() +bool Theme::darkMode() const { - connectToPaletteSignal(); const auto isDarkFromStyle = [] { switch (qGuiApp->styleHints()->colorScheme()) { diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 707cb07d555fc..37fea143ac8d9 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -601,8 +601,8 @@ class OWNCLOUDSYNC_EXPORT Theme : public QObject static constexpr const char *themePrefix = ":/client/theme/"; - QVariantMap systemPalette(); - bool darkMode(); + [[nodiscard]] QVariantMap systemPalette() const; + [[nodiscard]] bool darkMode() const; public slots: void setOverrideServerUrl(const QString &overrideServerUrl); From 1a9ba18661df37163e85e695c3b46c23daac83a1 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 12 Nov 2024 14:52:04 +0100 Subject: [PATCH 10/11] on Windows 10 follow color scheme changes and apply them Signed-off-by: Matthieu Gallien --- src/gui/application.cpp | 23 +++++------------------ src/gui/application.h | 1 + src/libsync/theme.cpp | 22 ++++++++++++---------- src/libsync/theme.h | 1 + 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index f05f222a351bf..fb34647618350 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -126,21 +126,6 @@ namespace { // ---------------------------------------------------------------------------------- -#ifdef Q_OS_WIN -class WindowsNativeEventFilter : public QAbstractNativeEventFilter { -public: - bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override { - const auto msg = static_cast(message); - if(msg->message == WM_SYSCOLORCHANGE || msg->message == WM_SETTINGCHANGE) { - if (const auto ptr = qobject_cast(QGuiApplication::instance())) { - emit ptr->paletteChanged(ptr->palette()); - } - } - return false; - } -}; -#endif - bool Application::configVersionMigration() { QStringList deleteKeys, ignoreKeys; @@ -237,9 +222,6 @@ Application::Application(int &argc, char **argv) // Ensure OpenSSL config file is only loaded from app directory QString opensslConf = QCoreApplication::applicationDirPath() + QString("/openssl.cnf"); qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit()); - - // Set up event listener for Windows theme changing - installNativeEventFilter(new WindowsNativeEventFilter()); #endif // TODO: Can't set this without breaking current config paths @@ -384,6 +366,8 @@ Application::Application(int &argc, char **argv) _theme->setSystrayUseMonoIcons(ConfigFile().monoIcons()); connect(_theme, &Theme::systrayUseMonoIconsChanged, this, &Application::slotUseMonoIconsChanged); + connect(this, &Application::systemPaletteChanged, + _theme, &Theme::systemPaletteHasChanged); #if defined(Q_OS_WIN) _shellExtensionsServer.reset(new ShellExtensionsServer); @@ -1127,6 +1111,9 @@ bool Application::event(QEvent *event) qCInfo(lcApplication) << errorParsingLocalFileEditingUrl; showHint(errorParsingLocalFileEditingUrl.toStdString()); } + } else if (event->type() == QEvent::ApplicationPaletteChange) { + qCInfo(lcApplication) << "application palette changed"; + emit systemPaletteChanged(); } return SharedTools::QtSingleApplication::event(event); } diff --git a/src/gui/application.h b/src/gui/application.h index 9ec6e121bda39..f2c41fe453768 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -96,6 +96,7 @@ public slots: void folderRemoved(); void folderStateChanged(OCC::Folder *); void isShowingSettingsDialog(); + void systemPaletteChanged(); protected slots: void slotParseMessage(const QString &, QObject *); diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 05a8a1ba6b641..98e2857c391c5 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -969,16 +969,8 @@ QColor Theme::defaultColor() void Theme::connectToPaletteSignal() { if (!_paletteSignalsConnected) { - 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()) { - connect(ptr, &QGuiApplication::paletteChanged, this, &Theme::darkModeChanged); - } else -#endif - { - connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged); - } + if (const auto ptr = qobject_cast(qApp)) { + connect(ptr->styleHints(), &QStyleHints::colorSchemeChanged, this, &Theme::darkModeChanged); _paletteSignalsConnected = true; } } @@ -1088,4 +1080,14 @@ void Theme::setStartLoginFlowAutomatically(bool startLoginFlowAuto) } } +void Theme::systemPaletteHasChanged() +{ + qCInfo(lcTheme()) << "system palette changed"; +#ifdef Q_OS_WIN + if (darkMode() && !isWindows11OrGreater()) { + qApp->setPalette(reserveDarkPalette); + } +#endif +} + } // end namespace client diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 37fea143ac8d9..a7e817de15ca9 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -609,6 +609,7 @@ public slots: void setForceOverrideServerUrl(bool forceOverride); void setVfsEnabled(bool enabled); void setStartLoginFlowAutomatically(bool startLoginFlowAuto); + void systemPaletteHasChanged(); protected: #ifndef TOKEN_AUTH_ONLY From 011fcd04f7b441fc8020ee92c1b2ae7bc88b442b Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Tue, 12 Nov 2024 18:28:15 +0100 Subject: [PATCH 11/11] some improvements for account network settings Signed-off-by: Matthieu Gallien --- src/gui/networksettings.ui | 5 ++++- src/libsync/theme.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gui/networksettings.ui b/src/gui/networksettings.ui index db6db42be4802..e8ee66ad60572 100644 --- a/src/gui/networksettings.ui +++ b/src/gui/networksettings.ui @@ -13,11 +13,14 @@ Form + + true + - Qt::Vertical + Qt::Orientation::Vertical diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 98e2857c391c5..3c65e31bbcf8d 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -371,10 +371,10 @@ Theme::Theme() reserveDarkPalette.setColor(QPalette::WindowText, Qt::white); reserveDarkPalette.setColor(QPalette::Button, QColor(127, 127, 127)); - reserveDarkPalette.setColor(QPalette::Light, QColor(53, 53, 53)); + reserveDarkPalette.setColor(QPalette::Light, QColor(20, 20, 20)); reserveDarkPalette.setColor(QPalette::Midlight, QColor(78, 78, 78)); - reserveDarkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); - reserveDarkPalette.setColor(QPalette::Mid, QColor(44, 44, 44)); + reserveDarkPalette.setColor(QPalette::Dark, QColor(191, 191, 191)); + reserveDarkPalette.setColor(QPalette::Mid, QColor(95, 95, 95)); reserveDarkPalette.setColor(QPalette::Text, Qt::white); reserveDarkPalette.setColor(QPalette::BrightText, Qt::red); reserveDarkPalette.setColor(QPalette::ButtonText, Qt::white);