90 lines
3.3 KiB
Diff
90 lines
3.3 KiB
Diff
From 1d693df019b1ebf54980a015000b01ae947f82ee Mon Sep 17 00:00:00 2001
|
|
From: Jan Grulich <jgrulich@redhat.com>
|
|
Date: Wed, 26 Jul 2023 12:26:39 +0200
|
|
Subject: [PATCH 04/22] QGtk3Theme: implement appearance function to detect
|
|
dark themes
|
|
|
|
This allows Qt Quick Controls to detect if a dark theme is in use,
|
|
and if so, use a dark theme of the current style (if available).
|
|
---
|
|
.../platformthemes/gtk3/qgtk3theme.cpp | 42 +++++++++++++++++++
|
|
src/plugins/platformthemes/gtk3/qgtk3theme.h | 2 +
|
|
2 files changed, 44 insertions(+)
|
|
|
|
diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
|
|
index 93520344f8..a47720384c 100644
|
|
--- a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
|
|
+++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
|
|
@@ -41,6 +41,7 @@
|
|
#include "qgtk3dialoghelpers.h"
|
|
#include "qgtk3menu.h"
|
|
#include <QVariant>
|
|
+#include <QtCore/qregularexpression.h>
|
|
|
|
#undef signals
|
|
#include <gtk/gtk.h>
|
|
@@ -147,6 +148,47 @@ QString QGtk3Theme::gtkFontName() const
|
|
return QGnomeTheme::gtkFontName();
|
|
}
|
|
|
|
+QPlatformTheme::Appearance QGtk3Theme::appearance() const
|
|
+{
|
|
+ /*
|
|
+ https://docs.gtk.org/gtk3/running.html
|
|
+
|
|
+ It's possible to set a theme variant after the theme name when using GTK_THEME:
|
|
+
|
|
+ GTK_THEME=Adwaita:dark
|
|
+
|
|
+ Some themes also have "-dark" as part of their name.
|
|
+
|
|
+ We test this environment variable first because the documentation says
|
|
+ it's mainly used for easy debugging, so it should be possible to use it
|
|
+ to override any other settings.
|
|
+ */
|
|
+ QString themeName = qEnvironmentVariable("GTK_THEME");
|
|
+ const QRegularExpression darkRegex(QStringLiteral("[:-]dark"), QRegularExpression::CaseInsensitiveOption);
|
|
+ if (!themeName.isEmpty())
|
|
+ return darkRegex.match(themeName).hasMatch() ? Appearance::Dark : Appearance::Light;
|
|
+
|
|
+ /*
|
|
+ https://docs.gtk.org/gtk3/property.Settings.gtk-application-prefer-dark-theme.html
|
|
+
|
|
+ This setting controls which theme is used when the theme specified by
|
|
+ gtk-theme-name provides both light and dark variants. We can save a
|
|
+ regex check by testing this property first.
|
|
+ */
|
|
+ const auto preferDark = gtkSetting<bool>("gtk-application-prefer-dark-theme");
|
|
+ if (preferDark)
|
|
+ return Appearance::Dark;
|
|
+
|
|
+ /*
|
|
+ https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html
|
|
+ */
|
|
+ themeName = gtkSetting("gtk-theme-name");
|
|
+ if (!themeName.isEmpty())
|
|
+ return darkRegex.match(themeName).hasMatch() ? Appearance::Dark : Appearance::Light;
|
|
+
|
|
+ return Appearance::Unknown;
|
|
+}
|
|
+
|
|
bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const
|
|
{
|
|
switch (type) {
|
|
diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.h b/src/plugins/platformthemes/gtk3/qgtk3theme.h
|
|
index 54296d2ff1..5f439067af 100644
|
|
--- a/src/plugins/platformthemes/gtk3/qgtk3theme.h
|
|
+++ b/src/plugins/platformthemes/gtk3/qgtk3theme.h
|
|
@@ -52,6 +52,8 @@ public:
|
|
virtual QVariant themeHint(ThemeHint hint) const override;
|
|
virtual QString gtkFontName() const override;
|
|
|
|
+ Appearance appearance() const override;
|
|
+
|
|
bool usePlatformNativeDialog(DialogType type) const override;
|
|
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override;
|
|
|
|
--
|
|
2.41.0
|
|
|