summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-08-27 13:43:24 +0200
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2024-09-05 09:59:09 +0200
commit59a46daf21986b1cb15bc4fccae0bf2489664045 (patch)
tree060729aa7c1ff596591d5b9c8cedfd94cc306faf
parent2d497a8754dbd33ebe7793e543c89018333891f1 (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 (cherry picked from commit 6b0b28d66ae79c1cbb7545b4b40dd3682f20ff72) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172486 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
-rw-r--r--vcl/qt5/QtFrame.cxx11
1 files changed, 7 insertions, 4 deletions
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 2f314b3735ef..b0529e58fce2 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(); }