1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Merge the configuration loading into something more simple (3)

This commit is contained in:
Dave Davenport 2017-03-28 17:33:43 +02:00
parent 14b43523be
commit 5259eb11bc
8 changed files with 54 additions and 30 deletions

View file

@ -4,6 +4,7 @@
#include <cairo.h>
#include <widgets/widget.h>
#include <settings.h>
#include "theme.h"
/** Style of text highlight */
typedef enum

View file

@ -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

View file

@ -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 );
}
}
;

View file

@ -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;
}
}

View file

@ -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 )

View file

@ -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 )

View file

@ -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 )
{
}

View file

@ -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 )