[gtk+] settings: Fix xsettings handling



commit 1da048d19ac8921a9da843fc4376f927e620b8fb
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed May 4 11:19:03 2016 -0400

    settings: Fix xsettings handling
    
    I was somehow under the misconception that we'd get GdkEventSettings
    events for all the xsettings at startup. That is not in general true,
    so we need to make sure that we check for the xsettings value before
    we use them, or derived fields. Update all the private getters to
    do so; and fix settings_update_font_values() to cope with font
    descriptions that might miss the family or size.

 gtk/gtksettings.c |   58 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index a720d35..672ba61 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -1971,29 +1971,35 @@ settings_update_font_values (GtkSettings *settings)
   PangoFontDescription *desc;
   const gchar *font_name;
 
-  g_free (priv->font_family);
-
   font_name = g_value_get_string (&priv->property_values[PROP_FONT_NAME - 1].value);
   desc = pango_font_description_from_string (font_name);
 
-  if (desc == NULL)
+  if (desc != NULL &&
+      (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_SIZE) != 0)
+    {
+      priv->font_size = pango_font_description_get_size (desc);
+      priv->font_size_absolute = pango_font_description_get_size_is_absolute (desc);
+    }
+  else
     {
       priv->font_size = 10 * PANGO_SCALE;
       priv->font_size_absolute = FALSE;
-      priv->font_family = g_strdup ("Sans");
-      return;
     }
 
-  if (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_SIZE)
+  g_free (priv->font_family);
+
+  if (desc != NULL &&
+      (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_FAMILY) != 0)
     {
-      priv->font_size = pango_font_description_get_size (desc);
-      priv->font_size_absolute = pango_font_description_get_size_is_absolute (desc);
+      priv->font_family = g_strdup (pango_font_description_get_family (desc));
+    }
+  else
+    {
+      priv->font_family = g_strdup ("Sans");
     }
 
-  if (pango_font_description_get_set_fields (desc) & PANGO_FONT_MASK_FAMILY)
-    priv->font_family = g_strdup (pango_font_description_get_family (desc));
-
-  pango_font_description_free (desc);
+  if (desc)
+    pango_font_description_free (desc);
 }
 
 static void
@@ -3530,7 +3536,8 @@ gtk_settings_get_enable_animations (GtkSettings *settings)
       GParamSpec *pspec;
 
       pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), "gtk-enable-animations");
-      settings_update_xsetting (settings, pspec, FALSE);
+      if (settings_update_xsetting (settings, pspec, FALSE))
+        g_object_notify_by_pspec (G_OBJECT (settings), pspec);
     }
 
   return g_value_get_boolean (&svalue->value);
@@ -3547,26 +3554,49 @@ gtk_settings_get_dnd_drag_threshold (GtkSettings *settings)
       GParamSpec *pspec;
 
       pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), "gtk-dnd-drag-threshold");
-      settings_update_xsetting (settings, pspec, FALSE);
+      if (settings_update_xsetting (settings, pspec, FALSE))
+        g_object_notify_by_pspec (G_OBJECT (settings), pspec);
     }
 
   return g_value_get_int (&svalue->value);
 }
 
+static void
+update_font_name (GtkSettings *settings)
+{
+  GtkSettingsPrivate *priv = settings->priv;
+  GtkSettingsPropertyValue *svalue = &priv->property_values[PROP_FONT_NAME - 1];
+
+  if (svalue->source < GTK_SETTINGS_SOURCE_XSETTING)
+    {
+      GParamSpec *pspec;
+
+      pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), "gtk-font-name");
+      if (settings_update_xsetting (settings, pspec, FALSE))
+        g_object_notify_by_pspec (G_OBJECT (settings), pspec);
+    }
+}
+
 const gchar *
 gtk_settings_get_font_family (GtkSettings *settings)
 {
+  update_font_name (settings);
+
   return settings->priv->font_family;
 }
 
 gint
 gtk_settings_get_font_size (GtkSettings *settings)
 {
+  update_font_name (settings);
+
   return settings->priv->font_size;
 }
 
 gboolean
 gtk_settings_get_font_size_is_absolute (GtkSettings *settings)
 {
+  update_font_name (settings);
+
   return settings->priv->font_size_absolute;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]