diff options
author | Matthias Clasen <mclasen@redhat.com> | 2009-10-25 23:47:59 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2009-10-25 23:53:50 -0400 |
commit | 90f7a1ccfd35d563c16da9491cd785acbf6a774d (patch) | |
tree | 29fa7daefb547ab1a114f0f9b1cc14ff9917d8ac | |
parent | d56f5a843d1e9213e7a4bf11f08caaa20af46ded (diff) | |
download | gdk-pixbuf-90f7a1ccfd35d563c16da9491cd785acbf6a774d.tar.gz |
Fix issues with symbolic colors in rc file parsing
Don't recreate the settings color hash every time, repopulate it
instead. This avoids invalidating the references held by RcContexts.
-rw-r--r-- | gtk/gtkrc.c | 16 | ||||
-rw-r--r-- | gtk/gtksettings.c | 49 |
2 files changed, 44 insertions, 21 deletions
diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c index a2ac58b93..70540a313 100644 --- a/gtk/gtkrc.c +++ b/gtk/gtkrc.c @@ -659,11 +659,15 @@ gtk_rc_color_hash_changed (GtkSettings *settings, GParamSpec *pspec, GtkRcContext *context) { - if (context->color_hash) - g_hash_table_unref (context->color_hash); - + GHashTable *old_hash; + + old_hash = context->color_hash; + g_object_get (settings, "color-hash", &context->color_hash, NULL); + if (old_hash) + g_hash_table_unref (old_hash); + gtk_rc_reparse_all_for_settings (settings, TRUE); } @@ -3148,8 +3152,10 @@ gtk_rc_parse_style (GtkRcContext *context, break; case GTK_RC_TOKEN_COLOR: if (our_hash == NULL) - gtk_rc_style_prepend_empty_color_hash (rc_style); - our_hash = rc_priv->color_hashes->data; + { + gtk_rc_style_prepend_empty_color_hash (rc_style); + our_hash = rc_priv->color_hashes->data; + } token = gtk_rc_parse_logical_color (scanner, rc_style, our_hash); break; case G_TOKEN_IDENTIFIER: diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index 49172636e..2b6b24ee1 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -2190,8 +2190,8 @@ settings_update_color_scheme (GtkSettings *settings) } static gboolean -add_color_to_hash (gchar *name, - GdkColor *color, +add_color_to_hash (gchar *name, + GdkColor *color, GHashTable *target) { GdkColor *old; @@ -2200,7 +2200,7 @@ add_color_to_hash (gchar *name, if (!old || !gdk_color_equal (old, color)) { g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color)); - + return TRUE; } @@ -2208,7 +2208,7 @@ add_color_to_hash (gchar *name, } static gboolean -add_colors_to_hash_from_string (GHashTable *hash, +add_colors_to_hash_from_string (GHashTable *hash, const gchar *colors) { gchar *s, *p, *name; @@ -2256,24 +2256,27 @@ add_colors_to_hash_from_string (GHashTable *hash, static gboolean update_color_hash (ColorSchemeData *data, - const gchar *str, + const gchar *str, GtkSettingsSource source) { gboolean changed = FALSE; gint i; GHashTable *old_hash; + GHashTableIter iter; + gchar *name; + GdkColor *color; - if ((str == NULL || *str == '\0') && + if ((str == NULL || *str == '\0') && (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0')) return FALSE; if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0) return FALSE; - /* For the RC_FILE source we merge the values rather than over-writing + /* For the RC_FILE source we merge the values rather than over-writing * them, since multiple rc files might define independent sets of colors */ - if ((source != GTK_SETTINGS_SOURCE_RC_FILE) && + if ((source != GTK_SETTINGS_SOURCE_RC_FILE) && data->tables[source] && g_hash_table_size (data->tables[source]) > 0) { g_hash_table_unref (data->tables[source]); @@ -2282,22 +2285,36 @@ update_color_hash (ColorSchemeData *data, } if (data->tables[source] == NULL) - data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal, + data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gdk_color_free); g_free (data->lastentry[source]); data->lastentry[source] = g_strdup (str); - + changed |= add_colors_to_hash_from_string (data->tables[source], str); if (!changed) return FALSE; - + /* Rebuild the merged hash table. */ - old_hash = data->color_hash; - data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - (GDestroyNotify) gdk_color_free); + if (data->color_hash) + { + old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + (GDestroyNotify) gdk_color_free); + + g_hash_table_iter_init (&iter, data->color_hash); + while (g_hash_table_iter_next (&iter, &name, &color)) + { + g_hash_table_insert (old_hash, name, color); + g_hash_table_iter_steal (&iter); + } + } + else + { + old_hash = NULL; + } + for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++) { if (data->tables[i]) @@ -2324,13 +2341,13 @@ update_color_hash (ColorSchemeData *data, { changed = TRUE; break; - } + } } } g_hash_table_unref (old_hash); } - else + else changed = TRUE; return changed; |