summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-03-27 09:04:55 +0200
committerDave Davenport <qball@gmpclient.org>2017-03-27 09:04:55 +0200
commitb91a9fb0c0d08950aa4556c4a7e9ad0870a1cdab (patch)
treec42295027485464ce44244b7bddca59363de67d0
parent5186dab1b848d97aa12ae64b4f424371f91cec9c (diff)
Add 'Configuration' section to rasi format that parses config option.
-rw-r--r--include/xrmoptions.h9
-rw-r--r--lexer/theme-lexer.l8
-rw-r--r--lexer/theme-parser.y27
-rw-r--r--source/xrmoptions.c22
4 files changed, 65 insertions, 1 deletions
diff --git a/include/xrmoptions.h b/include/xrmoptions.h
index b4abc76b..87b9f15c 100644
--- a/include/xrmoptions.h
+++ b/include/xrmoptions.h
@@ -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
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index 78b1c26f..3d16c127 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -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);
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index e304ff29..f571d231 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -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;
+
+ }
+ }
+}
;
/**
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 9c017377..8b4e17e5 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -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 );