Bug 1869525 - Watch KDE's colors.css and trigger theme recomputation when it mutates. r=stransky

Consider the following situation:

 * We're using the Breeze (light) theme.
 * We switch to dark mode.

When the KDE system theme changes, we get a color scheme change
notification. However by the time we get it, the gtk colorreload module
that KDE uses to communicate its colors to GTK[1] hasn't processed the
change yet.

So we end up thinking that Breeze is still light, (and even
special-casing that wouldn't work, because we still get the light
colors). So we fall back to Adwaita-dark, and by the time the file
actually changes we don't get any other notification. I don't think
there's another thing to watch here, unfortunately, but if there is we
should do it. I guess we could patch the color-reload module to send
some sort of signal to the screen / settings objects?

[1]: https://invent.kde.org/plasma/kde-gtk-config/-/blob/master/color-reload-module

Differential Revision: https://phabricator.services.mozilla.com/D196164
This commit is contained in:
Emilio Cobos Álvarez 2023-12-13 17:13:41 +00:00
Родитель edf29b31d0
Коммит d4dfa221f7
3 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -27,6 +27,7 @@ struct GObjectRefPtrTraits {
GOBJECT_TRAITS(GtkWidget)
GOBJECT_TRAITS(GFile)
GOBJECT_TRAITS(GFileMonitor)
GOBJECT_TRAITS(GMenu)
GOBJECT_TRAITS(GMenuItem)
GOBJECT_TRAITS(GSimpleAction)

Просмотреть файл

@ -215,6 +215,17 @@ nsLookAndFeel::nsLookAndFeel() {
},
this, nullptr);
}
if (IsKdeDesktopEnvironment()) {
GUniquePtr<gchar> path(
g_strconcat(g_get_user_config_dir(), "/gtk-3.0/colors.css", NULL));
mKdeColors = dont_AddRef(g_file_new_for_path(path.get()));
mKdeColorsMonitor = dont_AddRef(
g_file_monitor_file(mKdeColors.get(), G_FILE_MONITOR_NONE, NULL, NULL));
if (mKdeColorsMonitor) {
g_signal_connect(mKdeColorsMonitor.get(), "changed",
G_CALLBACK(settings_changed_cb), NULL);
}
}
}
nsLookAndFeel::~nsLookAndFeel() {

Просмотреть файл

@ -17,6 +17,8 @@ enum WidgetNodeType : int;
struct _GtkStyle;
typedef struct _GDBusProxy GDBusProxy;
typedef struct _GtkCssProvider GtkCssProvider;
typedef struct _GFile GFile;
typedef struct _GFileMonitor GFileMonitor;
namespace mozilla {
enum class StyleGtkThemeFamily : uint8_t;
@ -162,6 +164,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
uint32_t mDBusID = 0;
RefPtr<GDBusProxy> mDBusSettingsProxy;
RefPtr<GFile> mKdeColors;
RefPtr<GFileMonitor> mKdeColorsMonitor;
mozilla::Maybe<ColorScheme> mColorSchemePreference;
int32_t mCaretBlinkTime = 0;
int32_t mCaretBlinkCount = -1;