vcl/qt5/QtFrame.cxx |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

New commits:
commit 6b0b28d66ae79c1cbb7545b4b40dd3682f20ff72
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Aug 27 13:43:24 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Aug 27 20:11:59 2024 +0200

    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 <[email protected]>
    Tested-by: Jenkins

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(); }

Reply via email to