diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index ba96ead3..c2c726f9 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -470,6 +470,23 @@ window { } ``` +* Format: `var(PROPERTY NAME, DEFAULT)` + +A reference can point to another reference. Currently, the maximum number of redirects is 20. +A property always refers to another property. It cannot be used for a subpart of the property. + +Example: + +```css +window { + width: var( width, 30%); +} +``` + +If the property `width` is set globally (`*{}`) that value is used, if the property +`width` is not set, the default value is used. + + ## Orientation * Format: `(horizontal|vertical)` @@ -502,6 +519,20 @@ The environment variable should be an alphanumeric string without white-space. } ``` +* Format: `env(ENVIRONMENT, default)` + +This will parse the environment variable as the property value. (that then can be any of the above types). +The environment variable should be an alphanumeric string without white-space. +If the environment value is not found, the default value is used. + +```css +window { + width: env(WIDTH, 40%); +} +``` + +If environment WIDTH is set, then that value is parsed, otherwise the default value (`40%`). + ## Inherit * Format: `inherit` diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index acc57c23..23abab2b 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -273,6 +273,7 @@ LIST_OPEN \[ LIST_CLOSE \] VAR_START "var" +ENV_START "env" CPP_COMMENT "//" C_COMMENT_OPEN "/*" @@ -290,6 +291,7 @@ CONFIGURATION (?i:configuration) %x PROPERTIES %x PROPERTIES_ENV %x PROPERTIES_VAR +%x PROPERTIES_ENV_VAR %x PROPERTIES_VAR_DEFAULT %x PROPERTIES_LIST %x NAMESTR @@ -491,7 +493,7 @@ if ( queue == NULL ) { /* After Namestr/Classstr we want to go to state str, then to { */ {WHITESPACE}+ ; // ignore all whitespace -{WHITESPACE}+ ; // ignore all whitespace +{WHITESPACE}+ ; // ignore all whitespace
":" { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES); return T_PSEP; } ";" { BEGIN(GPOINTER_TO_INT ( g_queue_pop_head ( queue ))); return T_PCLOSE;} @@ -550,6 +552,26 @@ if ( queue == NULL ) { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_ENV); } } +{WORD} { + const char *val = g_getenv(yytext); + if ( val ) { + ParseObject *top = g_queue_peek_head ( file_queue ); + top->location = *yylloc; + ParseObject *po = g_malloc0(sizeof(ParseObject)); + po->type = PT_ENV; + po->input_str = val; + po->str_len = strlen(val); + current = po; + g_queue_push_head ( file_queue, po ); + + yypush_buffer_state (yy_create_buffer ( 0, YY_BUF_SIZE )); + yylloc->first_line = yylloc->last_line = 1; + yylloc->first_column = yylloc->last_column = 1; + yylloc->filename = current->filename; + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_ENV); + } +} + /** * Color parsing. It is easier to do this at lexer level. @@ -610,17 +632,26 @@ if ( queue == NULL ) { {HSL} { return T_COL_HSL; } {HWB} { return T_COL_HWB; } {CMYK} { return T_COL_CMYK; } - /* Fluff */ -{VAR_START}{S_T_PARENT_LEFT} { - g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); - BEGIN(PROPERTIES_VAR); + +{S_T_PARENT_LEFT} { return T_PARENT_LEFT; } -{S_T_PARENT_RIGHT} { + /* Fluff */ +{VAR_START} { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(PROPERTIES_VAR); + return T_VAR_START; +} +{ENV_START} { + g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); + BEGIN(PROPERTIES_ENV_VAR); + return T_ENV_START; +} +{S_T_PARENT_RIGHT} { BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue ))); return T_PARENT_RIGHT; } -{COMMA} { +{COMMA} { g_queue_push_head ( queue, GINT_TO_POINTER (YY_START) ); BEGIN(PROPERTIES_VAR_DEFAULT); return T_COMMA; @@ -794,7 +825,7 @@ if ( queue == NULL ) { return T_ELEMENT; } -. { +. { yytext[yyleng-1] = '\0'; return T_ERROR_PROPERTY; } diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 047bfb0e..cdef6421 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -265,6 +265,10 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b ) %token T_MEDIA_MAX "Max" %token T_MEDIA_SEP "-" + +%token T_VAR_START "var" +%token T_ENV_START "env" + %type t_entry_list %type t_entry_list_included %type t_entry_name_path @@ -481,17 +485,25 @@ t_property $$ = $3; $$->name = $1; } -| t_property_name T_PSEP T_PARENT_LEFT T_ELEMENT T_PARENT_RIGHT T_PCLOSE{ +| t_property_name T_PSEP T_VAR_START T_PARENT_LEFT T_ELEMENT T_PARENT_RIGHT T_PCLOSE{ $$ = rofi_theme_property_create ( P_LINK ); $$->name = $1; - $$->value.link.name = $4; + $$->value.link.name = $5; } -| t_property_name T_PSEP T_PARENT_LEFT T_ELEMENT T_COMMA t_property_element T_PARENT_RIGHT T_PCLOSE{ +| t_property_name T_PSEP T_VAR_START T_PARENT_LEFT T_ELEMENT T_COMMA t_property_element T_PARENT_RIGHT T_PCLOSE{ $$ = rofi_theme_property_create ( P_LINK ); $$->name = $1; - $$->value.link.name = $4; - $$->value.link.def_value = $6; + $$->value.link.name = $5; + $$->value.link.def_value = $7; } +| t_property_name T_PSEP T_ENV_START T_PARENT_LEFT T_COMMA t_property_element T_PARENT_RIGHT T_PCLOSE { + $$ = $6; + $$->name = $1; +} +| t_property_name T_PSEP T_ENV_START T_PARENT_LEFT t_property_element T_COMMA t_property_element T_PARENT_RIGHT T_PCLOSE { + $$ = $5; + $$->name = $1; +} t_property_element : T_INHERIT { diff --git a/meson.build b/meson.build index ff6b9236..8406e5f8 100644 --- a/meson.build +++ b/meson.build @@ -134,7 +134,7 @@ flex = generator(find_program('flex'), ) bison = generator(find_program('bison'), output: [ '@BASENAME@.c', '@BASENAME@.h' ], - arguments: [ '-d', '@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@' ] + arguments: [ '--verbose', '-d', '@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@' ] ) rofi_sources = files(