From 7c1ecb470773843d72a49adb462becb05af299df Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 6 Sep 2017 23:11:03 +0200 Subject: Add support for multiple selectors. #dummy0, dummy1 {} --- source/theme.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'source/theme.c') diff --git a/source/theme.c b/source/theme.c index 05156600..a335db10 100644 --- a/source/theme.c +++ b/source/theme.c @@ -74,6 +74,28 @@ Property *rofi_theme_property_create ( PropertyType type ) retv->type = type; return retv; } +Property* rofi_theme_property_copy ( Property *p) +{ + Property *retv = rofi_theme_property_create ( p->type ); + retv->name = g_strdup ( p->name ); + + switch ( p->type ) { + case P_STRING: + retv->value.s = g_strdup ( p->value.s ); + break; + case P_LIST: + retv->value.list = g_list_copy_deep ( p->value.list, (GCopyFunc)g_strdup, NULL ); + break; + case P_LINK: + retv->value.link.name = g_strdup ( p->value.link.name ); + retv->value.link.ref = NULL; + break; + default: + retv->value = p->value; + } + return retv; +} + void rofi_theme_property_free ( Property *p ) { if ( p == NULL ) { @@ -332,11 +354,11 @@ void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) rofi_add_error_message ( str ); } -static gboolean rofi_theme_steal_property_int ( gpointer key, gpointer value, gpointer user_data ) +static void rofi_theme_copy_property_int ( gpointer key, gpointer value, gpointer user_data ) { GHashTable *table = (GHashTable *) user_data; - g_hash_table_replace ( table, key, value ); - return TRUE; + Property *p = rofi_theme_property_copy( (Property*) value); + g_hash_table_replace ( table, p->name, p ); } void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table ) { @@ -344,11 +366,9 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table ) return; } if ( widget->properties == NULL ) { - widget->properties = table; - return; + widget->properties = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free ); } - g_hash_table_foreach_steal ( table, rofi_theme_steal_property_int, widget->properties ); - g_hash_table_destroy ( table ); + g_hash_table_foreach ( table, rofi_theme_copy_property_int, widget->properties ); } /** -- cgit v1.2.3