rc: the rc sets a widget path, class path or type name matches are kept for the next widgets with the same path until the sets change, instead of matching every pattern of the theme for each widget
This commit is contained in:
parent
cc15589b82
commit
32a3932ecb
1 changed files with 67 additions and 3 deletions
70
gtk/gtkrc.c
70
gtk/gtkrc.c
|
|
@ -128,6 +128,10 @@ struct _GtkRcContext
|
|||
|
||||
GHashTable *color_hash;
|
||||
|
||||
/* the sets matched by a widget path, class path or type name (the key
|
||||
* starts with 'w', 'c' or 't'), for widgets with the same path */
|
||||
GHashTable *matches;
|
||||
|
||||
guint reloading : 1;
|
||||
};
|
||||
|
||||
|
|
@ -700,6 +704,7 @@ gtk_rc_context_get (GtkSettings *settings)
|
|||
context->rc_sets_class = NULL;
|
||||
context->rc_files = NULL;
|
||||
context->default_style = NULL;
|
||||
context->matches = NULL;
|
||||
context->reloading = FALSE;
|
||||
|
||||
g_object_get (settings,
|
||||
|
|
@ -786,6 +791,9 @@ _gtk_rc_context_destroy (GtkSettings *settings)
|
|||
if (context->color_hash)
|
||||
g_hash_table_unref (context->color_hash);
|
||||
|
||||
if (context->matches)
|
||||
g_hash_table_destroy (context->matches);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (settings,
|
||||
gtk_rc_settings_changed, context);
|
||||
g_signal_handlers_disconnect_by_func (settings,
|
||||
|
|
@ -1613,11 +1621,21 @@ gtk_rc_free_rc_sets (GSList *slist)
|
|||
}
|
||||
}
|
||||
|
||||
/* The sets of @context are new: what paths matched is to be found again */
|
||||
static void
|
||||
gtk_rc_context_sets_changed (GtkRcContext *context)
|
||||
{
|
||||
if (context->matches)
|
||||
g_hash_table_remove_all (context->matches);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_rc_clear_styles (GtkRcContext *context)
|
||||
{
|
||||
/* Clear out all old rc_styles */
|
||||
|
||||
gtk_rc_context_sets_changed (context);
|
||||
|
||||
if (context->rc_style_ht)
|
||||
{
|
||||
g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
|
||||
|
|
@ -1913,6 +1931,44 @@ gtk_rc_styles_match (GSList *rc_styles,
|
|||
return rc_styles;
|
||||
}
|
||||
|
||||
/* gtk_rc_styles_match() of the sets of @context of @kind, by way of the
|
||||
* matches of earlier widgets with the same path: many widgets have the
|
||||
* same class path, and all of a type the same type names */
|
||||
#define MAX_MATCHES 2048
|
||||
|
||||
static GSList *
|
||||
gtk_rc_context_match (GtkRcContext *context,
|
||||
GSList *rc_styles,
|
||||
gchar kind,
|
||||
GSList *sets,
|
||||
guint path_length,
|
||||
gchar *path,
|
||||
gchar *path_reversed)
|
||||
{
|
||||
gchar *key;
|
||||
gpointer matches;
|
||||
|
||||
key = g_malloc (path_length + 2);
|
||||
key[0] = kind;
|
||||
memcpy (key + 1, path, path_length + 1);
|
||||
|
||||
if (!context->matches)
|
||||
context->matches = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, (GDestroyNotify) g_slist_free);
|
||||
|
||||
if (!g_hash_table_lookup_extended (context->matches, key, NULL, &matches))
|
||||
{
|
||||
matches = gtk_rc_styles_match (NULL, sets, path_length, path, path_reversed);
|
||||
if (g_hash_table_size (context->matches) >= MAX_MATCHES)
|
||||
g_hash_table_remove_all (context->matches);
|
||||
g_hash_table_insert (context->matches, key, matches);
|
||||
}
|
||||
else
|
||||
g_free (key);
|
||||
|
||||
return g_slist_concat (rc_styles, g_slist_copy (matches));
|
||||
}
|
||||
|
||||
static gint
|
||||
rc_set_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
|
|
@ -1995,7 +2051,8 @@ gtk_rc_get_style (GtkWidget *widget)
|
|||
guint path_length;
|
||||
|
||||
gtk_widget_path (widget, &path_length, &path, &path_reversed);
|
||||
rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget, path_length, path, path_reversed);
|
||||
rc_styles = gtk_rc_context_match (context, rc_styles, 'w', context->rc_sets_widget,
|
||||
path_length, path, path_reversed);
|
||||
g_free (path);
|
||||
g_free (path_reversed);
|
||||
}
|
||||
|
|
@ -2006,7 +2063,8 @@ gtk_rc_get_style (GtkWidget *widget)
|
|||
guint path_length;
|
||||
|
||||
gtk_widget_class_path (widget, &path_length, &path, &path_reversed);
|
||||
rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_widget_class, path_length, path, path_reversed);
|
||||
rc_styles = gtk_rc_context_match (context, rc_styles, 'c', context->rc_sets_widget_class,
|
||||
path_length, path, path_reversed);
|
||||
g_free (path);
|
||||
g_free (path_reversed);
|
||||
}
|
||||
|
|
@ -2027,7 +2085,8 @@ gtk_rc_get_style (GtkWidget *widget)
|
|||
path_reversed = g_strdup (path);
|
||||
g_strreverse (path_reversed);
|
||||
|
||||
rc_styles = gtk_rc_styles_match (rc_styles, context->rc_sets_class, path_length, path, path_reversed);
|
||||
rc_styles = gtk_rc_context_match (context, rc_styles, 't', context->rc_sets_class,
|
||||
path_length, path, path_reversed);
|
||||
g_free (path);
|
||||
g_free (path_reversed);
|
||||
|
||||
|
|
@ -2220,6 +2279,7 @@ gtk_rc_add_widget_name_style (GtkRcStyle *rc_style,
|
|||
|
||||
context = gtk_rc_context_get (gtk_settings_get_default ());
|
||||
|
||||
gtk_rc_context_sets_changed (context);
|
||||
context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern, GTK_PATH_WIDGET);
|
||||
}
|
||||
|
||||
|
|
@ -2234,6 +2294,7 @@ gtk_rc_add_widget_class_style (GtkRcStyle *rc_style,
|
|||
|
||||
context = gtk_rc_context_get (gtk_settings_get_default ());
|
||||
|
||||
gtk_rc_context_sets_changed (context);
|
||||
context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern, GTK_PATH_WIDGET_CLASS);
|
||||
}
|
||||
|
||||
|
|
@ -2248,6 +2309,7 @@ gtk_rc_add_class_style (GtkRcStyle *rc_style,
|
|||
|
||||
context = gtk_rc_context_get (gtk_settings_get_default ());
|
||||
|
||||
gtk_rc_context_sets_changed (context);
|
||||
context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern, GTK_PATH_CLASS);
|
||||
}
|
||||
|
||||
|
|
@ -4292,6 +4354,8 @@ gtk_rc_parse_path_pattern (GtkRcContext *context,
|
|||
rc_set->rc_style = rc_style;
|
||||
rc_set->priority = priority;
|
||||
|
||||
gtk_rc_context_sets_changed (context);
|
||||
|
||||
if (path_type == GTK_PATH_WIDGET)
|
||||
context->rc_sets_widget = g_slist_prepend (context->rc_sets_widget, rc_set);
|
||||
else if (path_type == GTK_PATH_WIDGET_CLASS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue