diff --git a/include/rofi-types.h b/include/rofi-types.h index 49ea42c6..48de8f78 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -103,6 +103,9 @@ typedef enum { ROFI_DISTANCE_MODIFIER_GROUP, ROFI_DISTANCE_MODIFIER_MIN, ROFI_DISTANCE_MODIFIER_MAX, + ROFI_DISTANCE_MODIFIER_ROUND, + ROFI_DISTANCE_MODIFIER_FLOOR, + ROFI_DISTANCE_MODIFIER_CEIL, } RofiDistanceModifier; typedef struct RofiDistanceUnit { diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index bf32ecb9..97e860f1 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -202,6 +202,9 @@ MODIFIER_SUBTRACT - MODIFIER_MULTIPLY \* MODIFIER_MIN (min) MODIFIER_MAX (max) +MODIFIER_ROUND (round) +MODIFIER_FLOOR (floor) +MODIFIER_CEIL (ceil) /* Position */ CENTER (?i:center) @@ -530,6 +533,9 @@ if ( queue == NULL ) { {MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; } {MODIFIER_MIN} { return T_MODIFIER_MIN; } {MODIFIER_MAX} { return T_MODIFIER_MAX; } +{MODIFIER_ROUND} { return T_MODIFIER_ROUND; } +{MODIFIER_FLOOR} { return T_MODIFIER_FLOOR; } +{MODIFIER_CEIL} { return T_MODIFIER_CEIL; } {CALC} { return T_CALC; } {ENV} { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index d149f05b..6deb38d0 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -240,6 +240,9 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b ) %token T_MODIFIER_MAX "Max ('max')" %token T_MODIFIER_MIN "Min ('min')" +%token T_MODIFIER_ROUND "Min ('round')" +%token T_MODIFIER_FLOOR "Min ('floor')" +%token T_MODIFIER_CEIL "Min ('ceil')" %token T_CALC "calc" @@ -801,6 +804,24 @@ t_property_distance_unit_math3 $$->right = $3; $$->modtype = ROFI_DISTANCE_MODIFIER_MAX; } +| t_property_distance_unit_math3 T_MODIFIER_ROUND t_property_distance_unit_math2 { + $$ = g_slice_new0(RofiDistanceUnit); + $$->left = $1; + $$->right = $3; + $$->modtype = ROFI_DISTANCE_MODIFIER_ROUND; +} +| t_property_distance_unit_math3 T_MODIFIER_FLOOR t_property_distance_unit_math2 { + $$ = g_slice_new0(RofiDistanceUnit); + $$->left = $1; + $$->right = $3; + $$->modtype = ROFI_DISTANCE_MODIFIER_FLOOR; +} +| t_property_distance_unit_math3 T_MODIFIER_CEIL t_property_distance_unit_math2 { + $$ = g_slice_new0(RofiDistanceUnit); + $$->left = $1; + $$->right = $3; + $$->modtype = ROFI_DISTANCE_MODIFIER_CEIL; +} | t_property_distance_unit_math2 { $$ = $1; }; diff --git a/source/theme.c b/source/theme.c index ab367aab..31dd0f8f 100644 --- a/source/theme.c +++ b/source/theme.c @@ -57,10 +57,8 @@ void rofi_theme_print_parsed_files(gboolean is_term) { printf("\nParsed files:\n"); for (GList *iter = g_list_first(parsed_config_files); iter != NULL; iter = g_list_next(iter)) { - printf("\t\u2022 %s%s%s\n", - is_term ? color_bold : "", (const char *)(iter->data), - is_term ? color_reset : ""); - + printf("\t\u2022 %s%s%s\n", is_term ? color_bold : "", + (const char *)(iter->data), is_term ? color_reset : ""); } printf("\n"); } @@ -285,6 +283,12 @@ static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit) { fputs(" min ", stdout); } else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MAX) { fputs(" max ", stdout); + } else if (unit->modtype == ROFI_DISTANCE_MODIFIER_ROUND) { + fputs(" round ", stdout); + } else if (unit->modtype == ROFI_DISTANCE_MODIFIER_FLOOR) { + fputs(" floor ", stdout); + } else if (unit->modtype == ROFI_DISTANCE_MODIFIER_CEIL) { + fputs(" ceil ", stdout); } if (unit->right) { rofi_theme_print_distance_unit(unit->right); @@ -1350,6 +1354,21 @@ static int distance_unit_get_pixel(RofiDistanceUnit *unit, int b = distance_unit_get_pixel(unit->right, ori); return MAX(a, b); } + case ROFI_DISTANCE_MODIFIER_ROUND: { + double a = (double)distance_unit_get_pixel(unit->left, ori); + double b = (double)distance_unit_get_pixel(unit->right, ori); + return (int)round(a / b) * b; + } + case ROFI_DISTANCE_MODIFIER_CEIL: { + double a = (double)distance_unit_get_pixel(unit->left, ori); + double b = (double)distance_unit_get_pixel(unit->right, ori); + return (int)ceil(a / b) * b; + } + case ROFI_DISTANCE_MODIFIER_FLOOR: { + double a = (double)distance_unit_get_pixel(unit->left, ori); + double b = (double)distance_unit_get_pixel(unit->right, ori); + return (int)floor(a / b) * b; + } default: break; }