diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-08-27 13:43:24 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-08-27 20:11:59 +0200 |
commit | 6b0b28d66ae79c1cbb7545b4b40dd3682f20ff72 (patch) | |
tree | 2efbb2cbf5b3a52aa09c28a1cc58eb3bf3bfd3a6 | |
parent | 84662e0454eddd928dfdf3cd8f7fe675db6a1fcf (diff) |
tdf#162003 qt: Add fall back for dark mode detection
For Qt >= 6.5, only rely on the color scheme reported
via `QApplication::styleHints()->colorScheme()` if it
is explicitly `Qt::ColorScheme::Light` or
`Qt::ColorScheme::Dark`.
For the `Qt::ColorScheme::Unknown` case, fall back
to the same mechanism used for Qt < 6.5, where
that API was not available yet.
This e.g. works around an issue with plasma-integration
currently always reporting `Qt::ColorScheme::Unknown`.
Suggested upstream fix:
https://invent.kde.org/plasma/plasma-integration/-/merge_requests/149
Change-Id: Iae022f7bcff3e7758d655006ec78602e08b50b56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172467
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
-rw-r--r-- | vcl/qt5/QtFrame.cxx | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index e3bc65e185d1..032956168768 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -321,15 +321,18 @@ QScreen* QtFrame::screen() const { return asChild()->screen(); } bool QtFrame::GetUseDarkMode() const { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - const QStyleHints* pStyleHints = QApplication::styleHints(); - return pStyleHints->colorScheme() == Qt::ColorScheme::Dark; -#else + const Qt::ColorScheme eColorScheme = QApplication::styleHints()->colorScheme(); + if (eColorScheme == Qt::ColorScheme::Dark) + return true; + if (eColorScheme == Qt::ColorScheme::Light) + return false; +#endif + // 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(); } |