Add 'Configuration' section to rasi format that parses config option.

This commit is contained in:
Dave Davenport 2017-03-27 09:04:55 +02:00
parent 5186dab1b8
commit b91a9fb0c0
4 changed files with 65 additions and 1 deletions

View file

@ -158,5 +158,14 @@ void print_help_msg ( const char *option, const char *type, const char*text, con
*/
char ** config_parser_return_display_help ( unsigned int *length );
/**
* @brief Set config option.
*
* Sets both the static as dynamic config option.
*
* @param option Option to set.
* @param value Value to set it too
*/
void config_parser_set_option ( char *option, char *value);
/* @}*/
#endif

View file

@ -141,6 +141,8 @@ LS_SOLID "solid"
INCLUDE "@import"
CONFIGURATION "Configuration"
%x INCLUDE
%x PROPERTIES
%x NAMESTR
@ -257,6 +259,12 @@ if ( queue == NULL ){
/**
* Handle defaults: * { ... }
*/
<INITIAL>{CONFIGURATION} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(DEFAULTS);
return CONFIGURATION;
}
<INITIAL>{ASTERIX} {
g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) );
BEGIN(DEFAULTS);

View file

@ -89,6 +89,7 @@ int yylex (YYSTYPE *, YYLTYPE *);
%token NAME_PREFIX "Element section ('# {name} { ... }')"
%token WHITESPACE "White space"
%token PDEFAULTS "Default settings section ( '* { ... }')"
%token CONFIGURATION "Configuration block"
%type <ival> highlight_styles
%type <sval> entry
@ -131,6 +132,32 @@ NAME_PREFIX name_path BOPEN optional_properties BCLOSE
PDEFAULTS BOPEN optional_properties BCLOSE {
rofi_theme_widget_add_properties ( rofi_theme, $3);
}
| CONFIGURATION BOPEN optional_properties BCLOSE {
GHashTableIter iter;
g_hash_table_iter_init ( &iter, $3 );
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;
}
}
}
;
/**

View file

@ -49,6 +49,7 @@ const char * const ConfigSourceStr[] = {
"Default",
"XResources",
"File",
"Rasi File",
"Commandline",
};
/** Enumerator of different sources of configuration. */
@ -57,7 +58,8 @@ enum ConfigSource
CONFIG_DEFAULT = 0,
CONFIG_XRESOURCES = 1,
CONFIG_FILE = 2,
CONFIG_CMDLINE = 3
CONFIG_FILE_THEME = 3,
CONFIG_CMDLINE = 4
};
typedef struct
@ -386,6 +388,24 @@ static void __config_parse_xresource_options_dynamic ( xcb_xrm_database_t *xDB,
}
}
void config_parser_set_option ( char *option, char *value)
{
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);
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);
return;
}
}
}
void config_parse_xresource_options_dynamic ( xcb_stuff *xcb )
{
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );