diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2023-09-02 10:12:54 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-09-02 15:42:37 +0200 |
commit | 73d0d205c43a9848acd313ff1845ebafe63e807c (patch) | |
tree | 7ad450c12c0c7240e37db63b0019b75e46531ebd /vcl/qt5 | |
parent | bdf2d664784b3ebe3e7078b9ec82a02d09d9ded8 (diff) |
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.weghorn@posteo.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r-- | vcl/qt5/QtFrame.cxx | 20 |
1 files changed, 19 insertions, 1 deletions
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)); |