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
This commit is contained in:
Emilio Cobos Álvarez 2021-06-16 14:35:29 +00:00
parent cbe629b48c
commit 8922b5b8aa

View File

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