diff --git a/include/theme.h b/include/theme.h index 6030b0e0..aece11ae 100644 --- a/include/theme.h +++ b/include/theme.h @@ -4,6 +4,7 @@ #include #include #include +#include "theme.h" /** Style of text highlight */ typedef enum diff --git a/include/xrmoptions.h b/include/xrmoptions.h index e1c47893..4d54f1e4 100644 --- a/include/xrmoptions.h +++ b/include/xrmoptions.h @@ -1,6 +1,7 @@ #ifndef ROFI_XRMOPTIONS_H #define ROFI_XRMOPTIONS_H #include "xcb.h" +#include "theme.h" // Big thanks to Sean Pringle for this code. /** @@ -139,9 +140,8 @@ char ** config_parser_return_display_help ( unsigned int *length ); * * Sets both the static as dynamic config option. * - * @param option Option to set. - * @param value Value to set it too + * @param p Property to set */ -void config_parser_set_option ( char *option, char *value); +void config_parse_set_property ( const Property *p); /* @}*/ #endif diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 30cc987f..4a5368b8 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -139,24 +139,7 @@ NAME_PREFIX name_path BOPEN optional_properties BCLOSE gpointer key,value; while ( g_hash_table_iter_next ( &iter, &key, &value ) ) { Property *p = (Property *) value; - switch ( p ->type ) - { - case P_STRING: - config_parser_set_option ( p->name, p->value.s); - break; - case P_BOOLEAN: - config_parser_set_option ( p->name, p->value.b?"true":"false"); - break; - case P_INTEGER: - { - char *str = g_strdup_printf("%d", p->value.i); - config_parser_set_option ( p->name, str ); - g_free(str); - } - default: - break; - - } + config_parse_set_property ( p ); } } ; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 5a910b19..189c0ee2 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -385,21 +385,61 @@ void config_parse_cmd_options ( void ) } } +static void __config_parser_set_property ( XrmOption *option, const Property *p ) +{ + if ( option->type == xrm_String ) + { + if ( p->type != P_STRING ) { + fprintf(stderr, "Option: %s needs to be set with a string.\n", option->name); + return; + } + if ( ( option )->mem != NULL ) { + g_free ( option->mem ); + option->mem = NULL; + } + *( option->value.str ) = g_strdup ( p->value.s ); + + // Memory + ( option )->mem = *( option->value.str ); + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_Number ) { + if ( p->type != P_INTEGER ){ + fprintf(stderr, "Option: %s needs to be set with a number.\n", option->name); + return; + } + *(option->value.snum) = p->value.i; + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_SNumber ) { + if ( p->type != P_INTEGER ){ + fprintf(stderr, "Option: %s needs to be set with a number.\n", option->name); + return; + } + *(option->value.num) = (unsigned int )(p->value.i); + option->source = CONFIG_FILE_THEME; + } else if ( option->type == xrm_Boolean ) { + if ( p->type != P_BOOLEAN ){ + fprintf(stderr, "Option: %s needs to be set with a boolean.\n", option->name); + return; + } + *(option->value.num) = (p->value.b); + option->source = CONFIG_FILE_THEME; + } +} -void config_parser_set_option ( char *option, char *value) +void config_parse_set_property ( const Property *p ) { for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( XrmOption ); ++i ) { XrmOption *op = &( xrmOptions[i] ); - if ( g_strcmp0 ( op->name, option) == 0 ) { - config_parser_set ( op, value, CONFIG_FILE_THEME); + if ( g_strcmp0 ( op->name, p->name) == 0 ) { + __config_parser_set_property ( op, p ); return; } } for ( unsigned int i = 0; i < num_extra_options; ++i ) { XrmOption *op = &( extra_options[i] ); - if ( g_strcmp0 ( op->name, option) == 0 ) { - config_parser_set ( op, value, CONFIG_FILE_THEME); + if ( g_strcmp0 ( op->name, p->name) == 0 ) { + __config_parser_set_property ( op, p ); return; } } diff --git a/test/box-test.c b/test/box-test.c index 228fe52b..74794820 100644 --- a/test/box-test.c +++ b/test/box-test.c @@ -23,7 +23,7 @@ unsigned int test =0; } \ } -void config_parser_set_option ( const char *k, const char *v) +void config_parse_set_property ( const void *p ) { } char * rofi_expand_path ( const char *path ) diff --git a/test/scrollbar-test.c b/test/scrollbar-test.c index 5402719c..9de2f744 100644 --- a/test/scrollbar-test.c +++ b/test/scrollbar-test.c @@ -22,7 +22,7 @@ unsigned int test =0; abort ( ); \ } \ } -void config_parser_set_option ( const char *k, const char *v) +void config_parse_set_property ( const void *p ) { } void rofi_add_error_message ( GString *msg ) diff --git a/test/textbox-test.c b/test/textbox-test.c index 8034b69b..664b4b61 100644 --- a/test/textbox-test.c +++ b/test/textbox-test.c @@ -22,7 +22,7 @@ unsigned int normal_window_mode = 0; #include "view.h" -void config_parser_set_option ( const char *k, const char *v) +void config_parse_set_property ( void *p ) { } diff --git a/test/widget-test.c b/test/widget-test.c index 5118ffbd..d9eab98a 100644 --- a/test/widget-test.c +++ b/test/widget-test.c @@ -12,7 +12,7 @@ unsigned int test =0; assert ( a ); \ printf ( "Test %3i passed (%s)\n", ++test, # a ); \ } -void config_parser_set_option ( const char *k, const char *v) +void config_parse_set_property ( const void *p ) { } void rofi_add_error_message ( GString *msg )