diff options
author | Dave Davenport <qball@gmpclient.org> | 2020-04-24 00:47:50 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2020-04-24 00:47:50 +0200 |
commit | 674d9f03ff00498d1350e95f115dd5e7bf3d392e (patch) | |
tree | 44e3ed5203d9ddc76a4ce57c8666c5895058a87a | |
parent | 15b0f39acd046ddfdbfce8b2f9c8cfb60cabf093 (diff) |
[Theme] Add * and / to calc().
-rw-r--r-- | include/rofi-types.h | 2 | ||||
-rw-r--r-- | lexer/theme-lexer.l | 4 | ||||
-rw-r--r-- | lexer/theme-parser.y | 28 | ||||
-rw-r--r-- | source/theme.c | 21 |
4 files changed, 54 insertions, 1 deletions
diff --git a/include/rofi-types.h b/include/rofi-types.h index c546f6e6..554bc14a 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -94,6 +94,8 @@ typedef enum ROFI_DISTANCE_MODIFIER_NONE, ROFI_DISTANCE_MODIFIER_ADD, ROFI_DISTANCE_MODIFIER_SUBTRACT, + ROFI_DISTANCE_MODIFIER_DIVIDE, + ROFI_DISTANCE_MODIFIER_MULTIPLY, } RofiDistanceModifier; typedef struct RofiDistanceUnit diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 800878a9..ec1ccc0b 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -185,6 +185,8 @@ ENV $\{[[:alnum:]]*\} MODIFIER_ADD \+ MODIFIER_SUBTRACT - +MODIFIER_DIVIDE \/ +MODIFIER_MULTIPLY \* /* Position */ CENTER (?i:center) @@ -456,6 +458,8 @@ if ( queue == NULL ){ <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{INHERIT} { return T_INHERIT; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_ADD} { return T_MODIFIER_ADD; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_SUBTRACT} { return T_MODIFIER_SUBTRACT; } +<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; } +<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_DIVIDE} { return T_MODIFIER_DIVIDE; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CALC} { return T_CALC; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ENV} { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 5f5ad174..0631574a 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -213,6 +213,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_MODIFIER_ADD "Add ('+')" %token T_MODIFIER_SUBTRACT "Subtract ('-')" +%token T_MODIFIER_DIVIDE "Divide ('/')" +%token T_MODIFIER_MULTIPLY "Multiply ('*')" %token T_CALC "calc" @@ -610,6 +612,7 @@ t_property_distance_zero $$.base.distance = (double) $1; $$.base.type = ROFI_PU_PX; $$.base.modifier = NULL; + $$.base.modtype = ROFI_DISTANCE_MODIFIER_NONE; $$.style = $2; } | t_property_distance { $$ = $1;} @@ -617,7 +620,9 @@ t_property_distance_zero t_property_distance_modifier_type : T_MODIFIER_ADD { $$ = ROFI_DISTANCE_MODIFIER_ADD; } -| T_MODIFIER_SUBTRACT { $$ = ROFI_DISTANCE_MODIFIER_SUBTRACT; }; +| T_MODIFIER_SUBTRACT { $$ = ROFI_DISTANCE_MODIFIER_SUBTRACT; } +| T_MODIFIER_DIVIDE { $$ = ROFI_DISTANCE_MODIFIER_DIVIDE; } +| T_MODIFIER_MULTIPLY { $$ = ROFI_DISTANCE_MODIFIER_MULTIPLY; }; /** Distance. */ @@ -629,6 +634,13 @@ t_property_distance_unit $$->modifier = NULL; $$->modtype = $1; } +| t_property_distance_modifier_type T_INT { + $$ = g_slice_new0(RofiDistanceUnit); + $$->distance = (double)$2; + $$->type = T_UNIT_PX; + $$->modifier = NULL; + $$->modtype = $1; +} | t_property_distance_modifier_type T_DOUBLE t_property_unit { $$ = g_slice_new0(RofiDistanceUnit); $$->distance = (double)$2; @@ -643,6 +655,13 @@ t_property_distance_unit $$->modifier = $4; $$->modtype = $1; } +| t_property_distance_modifier_type T_INT t_property_distance_unit { + $$ = g_slice_new0(RofiDistanceUnit); + $$->distance = (double)$2; + $$->type = T_UNIT_PX; + $$->modifier = $3; + $$->modtype = $1; +} | t_property_distance_modifier_type T_DOUBLE t_property_unit t_property_distance_unit { $$ = g_slice_new0(RofiDistanceUnit); $$->distance = (double)$2; @@ -689,6 +708,13 @@ t_property_distance $$.base.modtype = ROFI_DISTANCE_MODIFIER_NONE; $$.style = $7; } +| T_CALC T_PARENT_LEFT T_INT t_property_distance_unit T_PARENT_RIGHT t_property_line_style { + $$.base.distance = (double)$3; + $$.base.type = T_UNIT_PX; + $$.base.modifier = $4; + $$.base.modtype = ROFI_DISTANCE_MODIFIER_NONE; + $$.style = $6; +} | T_CALC T_PARENT_LEFT T_DOUBLE t_property_unit t_property_distance_unit T_PARENT_RIGHT t_property_line_style { $$.base.distance = (double)$3; $$.base.type = $4; diff --git a/source/theme.c b/source/theme.c index 4603ce66..51b1117c 100644 --- a/source/theme.c +++ b/source/theme.c @@ -266,6 +266,10 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( " + ", stdout ); } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { fputs ( " - ", stdout ); + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { + fputs ( " / ", stdout ); + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { + fputs ( " * ", stdout ); } if ( unit->type == ROFI_PU_PX ) { @@ -289,7 +293,13 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) } static void rofi_theme_print_distance ( RofiDistance d ) { + if ( d.base.modifier ){ + fputs( "calc( ", stdout ); + } rofi_theme_print_distance_unit ( &(d.base) ); + if ( d.base.modifier ){ + fputs( ")", stdout ); + } if ( d.style == ROFI_HL_DASH ) { printf ( "dash " ); } @@ -915,6 +925,17 @@ static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori case ROFI_DISTANCE_MODIFIER_SUBTRACT: val -= distance_unit_get_pixel ( unit->modifier, ori); break; + case ROFI_DISTANCE_MODIFIER_MULTIPLY: + val *= distance_unit_get_pixel ( unit->modifier, ori); + break; + case ROFI_DISTANCE_MODIFIER_DIVIDE: + { + int v = distance_unit_get_pixel ( unit->modifier, ori); + if ( v != 0 ) { + val /= v; + } + break; + } default: break; } |