mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
[#1569] Add initial round,floor,ceil function
a round b rounds a to the closest multiple off b a ceil b ceil a to the multiple off b a floor b floor a to the multiple off b Completely untested.
This commit is contained in:
parent
f5eafcc04c
commit
b6ce41825c
4 changed files with 53 additions and 4 deletions
|
@ -103,6 +103,9 @@ typedef enum {
|
||||||
ROFI_DISTANCE_MODIFIER_GROUP,
|
ROFI_DISTANCE_MODIFIER_GROUP,
|
||||||
ROFI_DISTANCE_MODIFIER_MIN,
|
ROFI_DISTANCE_MODIFIER_MIN,
|
||||||
ROFI_DISTANCE_MODIFIER_MAX,
|
ROFI_DISTANCE_MODIFIER_MAX,
|
||||||
|
ROFI_DISTANCE_MODIFIER_ROUND,
|
||||||
|
ROFI_DISTANCE_MODIFIER_FLOOR,
|
||||||
|
ROFI_DISTANCE_MODIFIER_CEIL,
|
||||||
} RofiDistanceModifier;
|
} RofiDistanceModifier;
|
||||||
|
|
||||||
typedef struct RofiDistanceUnit {
|
typedef struct RofiDistanceUnit {
|
||||||
|
|
|
@ -202,6 +202,9 @@ MODIFIER_SUBTRACT -
|
||||||
MODIFIER_MULTIPLY \*
|
MODIFIER_MULTIPLY \*
|
||||||
MODIFIER_MIN (min)
|
MODIFIER_MIN (min)
|
||||||
MODIFIER_MAX (max)
|
MODIFIER_MAX (max)
|
||||||
|
MODIFIER_ROUND (round)
|
||||||
|
MODIFIER_FLOOR (floor)
|
||||||
|
MODIFIER_CEIL (ceil)
|
||||||
|
|
||||||
/* Position */
|
/* Position */
|
||||||
CENTER (?i:center)
|
CENTER (?i:center)
|
||||||
|
@ -530,6 +533,9 @@ if ( queue == NULL ) {
|
||||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; }
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MULTIPLY} { return T_MODIFIER_MULTIPLY; }
|
||||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MIN} { return T_MODIFIER_MIN; }
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MIN} { return T_MODIFIER_MIN; }
|
||||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MAX} { return T_MODIFIER_MAX; }
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_MAX} { return T_MODIFIER_MAX; }
|
||||||
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_ROUND} { return T_MODIFIER_ROUND; }
|
||||||
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_FLOOR} { return T_MODIFIER_FLOOR; }
|
||||||
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{MODIFIER_CEIL} { return T_MODIFIER_CEIL; }
|
||||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CALC} { return T_CALC; }
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CALC} { return T_CALC; }
|
||||||
|
|
||||||
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ENV} {
|
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ENV} {
|
||||||
|
|
|
@ -240,6 +240,9 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b )
|
||||||
|
|
||||||
%token T_MODIFIER_MAX "Max ('max')"
|
%token T_MODIFIER_MAX "Max ('max')"
|
||||||
%token T_MODIFIER_MIN "Min ('min')"
|
%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"
|
%token T_CALC "calc"
|
||||||
|
|
||||||
|
@ -801,6 +804,24 @@ t_property_distance_unit_math3
|
||||||
$$->right = $3;
|
$$->right = $3;
|
||||||
$$->modtype = ROFI_DISTANCE_MODIFIER_MAX;
|
$$->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 {
|
| t_property_distance_unit_math2 {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,10 +57,8 @@ void rofi_theme_print_parsed_files(gboolean is_term) {
|
||||||
printf("\nParsed files:\n");
|
printf("\nParsed files:\n");
|
||||||
for (GList *iter = g_list_first(parsed_config_files); iter != NULL;
|
for (GList *iter = g_list_first(parsed_config_files); iter != NULL;
|
||||||
iter = g_list_next(iter)) {
|
iter = g_list_next(iter)) {
|
||||||
printf("\t\u2022 %s%s%s\n",
|
printf("\t\u2022 %s%s%s\n", is_term ? color_bold : "",
|
||||||
is_term ? color_bold : "", (const char *)(iter->data),
|
(const char *)(iter->data), is_term ? color_reset : "");
|
||||||
is_term ? color_reset : "");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
@ -285,6 +283,12 @@ static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit) {
|
||||||
fputs(" min ", stdout);
|
fputs(" min ", stdout);
|
||||||
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MAX) {
|
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MAX) {
|
||||||
fputs(" max ", stdout);
|
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) {
|
if (unit->right) {
|
||||||
rofi_theme_print_distance_unit(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);
|
int b = distance_unit_get_pixel(unit->right, ori);
|
||||||
return MAX(a, b);
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue