From 8922b5b8aae7397c11c7c679f384a6826a422424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 16 Jun 2021 14:35:29 +0000 Subject: [PATCH] Bug 1716462 - Add a bit more logging. r=stransky And reuse an already-computed name rather than calling GetGtkTheme again. Depends on D117722 Differential Revision: https://phabricator.services.mozilla.com/D117723 --- widget/gtk/nsLookAndFeel.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index 72c827a70950..8f43c9b46344 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -1032,19 +1032,23 @@ static bool IsGtkThemeCompatibleWithHTMLColors() { return HasGoodContrastVisibility(backgroundColor, black); } -static nsCString GetGtkTheme() { +static nsCString GetGtkSettingsStringKey(const char* aKey) { MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread()); nsCString ret; GtkSettings* settings = gtk_settings_get_default(); - char* themeName = nullptr; - g_object_get(settings, "gtk-theme-name", &themeName, nullptr); - if (themeName) { - ret.Assign(themeName); - g_free(themeName); + char* value = nullptr; + g_object_get(settings, aKey, &value, nullptr); + if (value) { + ret.Assign(value); + g_free(value); } return ret; } +static nsCString GetGtkTheme() { + return GetGtkSettingsStringKey("gtk-theme-name"); +} + static bool GetPreferDarkTheme() { GtkSettings* settings = gtk_settings_get_default(); gboolean preferDarkTheme = FALSE; @@ -1074,6 +1078,9 @@ void nsLookAndFeel::ConfigureTheme(const LookAndFeelTheme& aTheme) { } void nsLookAndFeel::RestoreSystemTheme() { + LOGLNF(("RestoreSystemTheme(%s, %d)\n", mSystemTheme.mName.get(), + mSystemTheme.mPreferDarkTheme)); + // Available on Gtk 3.20+. static auto sGtkSettingsResetProperty = (void (*)(GtkSettings*, const gchar*))dlsym( @@ -1316,6 +1323,10 @@ bool nsLookAndFeel::MatchFirefoxThemeIfNeeded() { }(); const bool usingSystem = GetThemeIsDark() == mSystemTheme.mIsDark; + + LOGLNF(("MatchFirefoxThemeIfNeeded(matchesSystem=%d, usingSystem=%d)\n", + matchesSystem, usingSystem)); + if (usingSystem == matchesSystem) { return false; } @@ -1323,6 +1334,9 @@ bool nsLookAndFeel::MatchFirefoxThemeIfNeeded() { if (matchesSystem) { RestoreSystemTheme(); } else { + LOGLNF(("Setting theme %s, %d\n", mAltTheme.mName.get(), + mAltTheme.mPreferDarkTheme)); + GtkSettings* settings = gtk_settings_get_default(); if (mSystemTheme.mName == mAltTheme.mName) { // Prefer setting only gtk-application-prefer-dark-theme, so we can still @@ -1403,7 +1417,7 @@ void nsLookAndFeel::PerThemeData::Init() { GtkStyleContext* style; mHighContrast = StaticPrefs::widget_content_gtk_high_contrast_enabled() && - GetGtkTheme().Find("HighContrast"_ns) >= 0; + mName.Find("HighContrast"_ns) >= 0; mPreferDarkTheme = GetPreferDarkTheme();