vcl/inc/qt5/QtFrame.hxx | 1 + vcl/qt5/QtFrame.cxx | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
New commits: commit 19b8bac2aa59d02968c33ac6f83c66907d5ab94c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Sep 2 10:37:47 2023 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Sep 2 15:42:44 2023 +0200 tdf#149611 qt: Make auto-selection of dark app colors work Rename the newly introduced method `QtFrame::isUsingDarkColorScheme` to detect whether a dark color scheme is in use from Change-Id I8f347c6e7f775cc55377c5c84481de3051c3cf24 tdf#156894 qt: Prefer dark icon theme in dark mode and let it override `SalFrame::GetUseDarkMode`. This gets used (via `MiscSettings::GetUseDarkMode`) in `ColorConfig::GetDefaultColor` to determine what application colors to use. With this, setting "Tools" -> "Options" -> "LibreOfficeDev" -> "Application Colors" -> "Automatic" to "System Theme" will now automatically switch to dark application colors (like a dark doc background instead of white) for kf5/qt6 when a dark global theme is active (e.g. because "Breeze Dark" has been selected in Plasma system settings). Change-Id: I151e7eb35a94a9c525452a7d90b24283f6226904 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156467 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx index ecedc3ae2e29..b5ae7508a506 100644 --- a/vcl/inc/qt5/QtFrame.hxx +++ b/vcl/inc/qt5/QtFrame.hxx @@ -128,7 +128,6 @@ class VCLPLUG_QT_PUBLIC QtFrame : public QObject, public SalFrame bool isWindow() const; QWindow* windowHandle() const; QScreen* screen() const; - static bool isUsingDarkColorScheme(); bool isMinimized() const; bool isMaximized() const; void SetWindowStateImpl(Qt::WindowStates eState); @@ -215,6 +214,7 @@ public: virtual void SetScreenNumber(unsigned int) override; virtual void SetApplicationID(const OUString&) override; virtual void ResolveWindowHandle(SystemEnvData& rData) const override; + virtual bool GetUseDarkMode() const override; virtual bool GetUseReducedAnimation() const override; inline bool CallCallback(SalEvent nEvent, const void* pEvent) const; diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index ff7edb9fd7b2..49d542a64909 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -354,7 +354,7 @@ QScreen* QtFrame::screen() const #endif } -bool QtFrame::isUsingDarkColorScheme() +bool QtFrame::GetUseDarkMode() const { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) const QStyleHints* pStyleHints = QApplication::styleHints(); @@ -1234,7 +1234,7 @@ void QtFrame::UpdateSettings(AllSettings& rSettings) style.SetMenuFont(aFont); // Icon theme - const bool bPreferDarkTheme = isUsingDarkColorScheme(); + const bool bPreferDarkTheme = GetUseDarkMode(); style.SetPreferredIconTheme(toOUString(QIcon::themeName()), bPreferDarkTheme); // Scroll bar size commit 73d0d205c43a9848acd313ff1845ebafe63e807c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Sep 2 10:12:54 2023 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Sep 2 15:42:37 2023 +0200 tdf#156894 qt: Prefer dark icon theme in dark mode When in dark mode, pass the param to prefer a dark icon theme to `StyleSettings::SetPreferredIconTheme`. For Qt >= 6.5 use `QStyleHints::colorScheme` introduced in Qt 6.5 to get the color scheme. For older Qt versions, use the same algorithm based on the gray value of the window background as xdg-desktop-portal-kde does for evaluating whether a light or dark color scheme is preferred [1]. On my Debian testing, the Breeze dark icon theme is now used as expected with kf5 or qt6 when setting the Global KDE Plasma theme to "Breeze Dark" and manually setting the Icon theme to "GNOME" afterwards. Previously, this would not use a dark icon theme and icons would be hard to see. Without manually setting the icon theme to "GNOME", the Breeze Dark icon theme would already be used before, because selecting "Breeze Dark" as the global KDE Plasma theme also selects the "Breeze Dark" icon theme by default, and therefore "breeze-dark" was already passed as the first param to `StyleSettings::SetPreferredIconTheme` and since that icon theme is present, the `bPreferDarkTheme` wouldn't be evaluated at all; it's only used when determining the fallback icon theme when the specified icon theme is not present. (Likewise, by enabling the "Breeze Dark" global theme and then manually setting the icon theme to "Breeze" in Plasma System settings, the Breeze light icon theme will be used in LibreOffice as well, resulting in hard to see icons, but I tend to think that that behavior is correct and works as designed - it's a misconfiguration.) The color scheme is also specified in xdg-desktop-portal (s. commit [2]) and can be retrived via dbus. Example with "Breeze Light" active: $ dbus-send --session --print-reply=literal --reply-timeout=1000 --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:'org.freedesktop.appearance' string:'color-scheme' variant variant uint32 2 With "Breeze Dark": $ dbus-send --session --print-reply=literal --reply-timeout=1000 --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:'org.freedesktop.appearance' string:'color-scheme' variant variant uint32 1 [1] https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/0a4237549debf9518f8cfbaf531456850c0729bd/src/settings.cpp#L213-227 [2] https://github.com/flatpak/xdg-desktop-portal/commit/d7a304a00697d7d608821253cd013f3b97ac0fb6 Change-Id: I8f347c6e7f775cc55377c5c84481de3051c3cf24 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156465 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx index 02146343e10d..ecedc3ae2e29 100644 --- a/vcl/inc/qt5/QtFrame.hxx +++ b/vcl/inc/qt5/QtFrame.hxx @@ -128,6 +128,7 @@ class VCLPLUG_QT_PUBLIC QtFrame : public QObject, public SalFrame bool isWindow() const; QWindow* windowHandle() const; QScreen* screen() const; + static bool isUsingDarkColorScheme(); bool isMinimized() const; bool isMaximized() const; void SetWindowStateImpl(Qt::WindowStates eState); diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 7cecebf2edf0..ff7edb9fd7b2 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -44,6 +44,9 @@ #include <QtGui/QIcon> #include <QtGui/QWindow> #include <QtGui/QScreen> +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) +#include <QtGui/QStyleHints> +#endif #include <QtWidgets/QStyle> #include <QtWidgets/QToolTip> #include <QtWidgets/QApplication> @@ -351,6 +354,20 @@ QScreen* QtFrame::screen() const #endif } +bool QtFrame::isUsingDarkColorScheme() +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + const QStyleHints* pStyleHints = QApplication::styleHints(); + return pStyleHints->colorScheme() == Qt::ColorScheme::Dark; +#else + // use same mechanism for determining dark mode preference as xdg-desktop-portal-kde, s. + // https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/0a4237549debf9518f8cfbaf531456850c0729bd/src/settings.cpp#L213-227 + const QPalette aPalette = QApplication::palette(); + const int nWindowBackGroundGray = qGray(aPalette.window().color().rgb()); + return nWindowBackGroundGray < 192; +#endif +} + bool QtFrame::isMinimized() const { return asChild()->isMinimized(); } bool QtFrame::isMaximized() const { return asChild()->isMaximized(); } @@ -1217,7 +1234,8 @@ void QtFrame::UpdateSettings(AllSettings& rSettings) style.SetMenuFont(aFont); // Icon theme - style.SetPreferredIconTheme(toOUString(QIcon::themeName())); + const bool bPreferDarkTheme = isUsingDarkColorScheme(); + style.SetPreferredIconTheme(toOUString(QIcon::themeName()), bPreferDarkTheme); // Scroll bar size style.SetScrollBarSize(QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent));