From 81b00705e848d6968f8462d64f2e8035b7593804 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 24 Apr 2020 18:17:01 +0200 Subject: [Theme] Add modulo to calc. --- doc/rofi-theme.5 | 2 ++ doc/rofi-theme.5.markdown | 1 + include/rofi-types.h | 1 + lexer/theme-parser.y | 14 ++++++++++---- source/theme.c | 11 +++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index f67280a6..cc0bc564 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -534,6 +534,8 @@ It supports the following operations: \fB\fC/\fR: Divide .IP \(bu 2 \fB\fC*\fR: Multiply +.IP \(bu 2 +\fB\fC%\fR: Multiply .PP It uses the C precedence ordering. diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 6a0d07ba..143551db 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -366,6 +366,7 @@ It supports the following operations: * `-`: Subtract * `/`: Divide * `*`: Multiply +* `%`: Multiply It uses the C precedence ordering. diff --git a/include/rofi-types.h b/include/rofi-types.h index e6d834ce..ced7e321 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -96,6 +96,7 @@ typedef enum ROFI_DISTANCE_MODIFIER_SUBTRACT, ROFI_DISTANCE_MODIFIER_DIVIDE, ROFI_DISTANCE_MODIFIER_MULTIPLY, + ROFI_DISTANCE_MODIFIER_MODULO, ROFI_DISTANCE_MODIFIER_GROUP, } RofiDistanceModifier; diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 1da0bda0..c93e8c7f 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -211,10 +211,10 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_LIST_OPEN "List open ('[')" %token T_LIST_CLOSE "List close (']')" -%token T_MODIFIER_ADD "Add ('+')" -%token T_MODIFIER_SUBTRACT "Subtract ('-')" -%token T_MODIFIER_DIVIDE "Divide ('/')" -%token T_MODIFIER_MULTIPLY "Multiply ('*')" +%token T_MODIFIER_ADD "Add ('+')" +%token T_MODIFIER_SUBTRACT "Subtract ('-')" +%token T_MODIFIER_DIVIDE "Divide ('/')" +%token T_MODIFIER_MULTIPLY "Multiply ('*')" %token T_CALC "calc" @@ -672,6 +672,12 @@ t_property_distance_unit_math $$->right = $3; $$->modtype = ROFI_DISTANCE_MODIFIER_DIVIDE; } +| t_property_distance_unit_math T_PERCENT t_property_distance_unit { + $$ = g_slice_new0(RofiDistanceUnit); + $$->left = $1; + $$->right = $3; + $$->modtype = ROFI_DISTANCE_MODIFIER_MODULO; +} | t_property_distance_unit { $$ = $1; }; diff --git a/source/theme.c b/source/theme.c index 1a7fe863..85bf7c86 100644 --- a/source/theme.c +++ b/source/theme.c @@ -290,6 +290,8 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( " / ", stdout ); } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { fputs ( " * ", stdout ); + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) { + fputs ( " % ", stdout ); } if ( unit->right ) rofi_theme_print_distance_unit ( unit->right ); @@ -966,6 +968,15 @@ static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori } return a; } + case ROFI_DISTANCE_MODIFIER_MODULO: + { + int a = distance_unit_get_pixel ( unit->left, ori); + int b = distance_unit_get_pixel ( unit->right, ori); + if ( b != 0 ) { + return a%b; + } + return 0; + } default: break; } -- cgit v1.2.3