summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2020-04-23 20:17:34 +0200
committerDave Davenport <qball@gmpclient.org>2020-04-23 20:17:34 +0200
commit7fdf1af7e482c43416534216f72df66ad795ff41 (patch)
tree0b4e57c771fb2dabb070c303e10b1e1479d0aeeb
parent1cf9fd4b5e63d05bdbcda7b2ff7db1934dcfa8c2 (diff)
[THEME] Fix printing theme with math in distance.
-rw-r--r--lexer/theme-parser.y14
-rw-r--r--source/theme.c39
2 files changed, 35 insertions, 18 deletions
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index 50819098..0eb1bd73 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -383,7 +383,7 @@ t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optio
gchar *name = g_strdup_printf("@media ( %s: %d )",$3, $5);
ThemeWidget *widget = rofi_theme_find_or_create_name ( rofi_theme, name );
widget->set = TRUE;
- widget->media = g_malloc0(sizeof(ThemeMedia));
+ widget->media = g_slice_new0(ThemeMedia);
widget->media->type = rofi_theme_parse_media_type ( $3 );
widget->media->value = (double)$5;
for ( unsigned int i = 0; i < $8->num_widgets;i++) {
@@ -396,7 +396,7 @@ t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optio
gchar *name = g_strdup_printf("@media ( %s: %f )",$3, $5);
ThemeWidget *widget = rofi_theme_find_or_create_name ( rofi_theme, name );
widget->set = TRUE;
- widget->media = g_malloc0(sizeof(ThemeMedia));
+ widget->media = g_slice_new0(ThemeMedia);
widget->media->type = rofi_theme_parse_media_type ( $3 );
widget->media->value = $5;
for ( unsigned int i = 0; i < $8->num_widgets;i++) {
@@ -409,7 +409,7 @@ t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optio
gchar *name = g_strdup_printf("@media ( %s: %d px )",$3, $5);
ThemeWidget *widget = rofi_theme_find_or_create_name ( rofi_theme, name );
widget->set = TRUE;
- widget->media = g_malloc0(sizeof(ThemeMedia));
+ widget->media = g_slice_new0(ThemeMedia);
widget->media->type = rofi_theme_parse_media_type ( $3 );
widget->media->value = (double)$5;
for ( unsigned int i = 0; i < $9->num_widgets;i++) {
@@ -621,28 +621,28 @@ t_property_distance_modifier_type
/** Distance. */
t_property_distance_unit
: t_property_distance_modifier_type T_INT t_property_unit {
- $$ = g_malloc0(sizeof(RofiDistanceUnit));
+ $$ = g_slice_new0(RofiDistanceUnit);
$$->distance = (double)$2;
$$->type = $3;
$$->modifier = NULL;
$$->modtype = $1;
}
| t_property_distance_modifier_type T_DOUBLE t_property_unit {
- $$ = g_malloc0(sizeof(RofiDistanceUnit));
+ $$ = g_slice_new0(RofiDistanceUnit);
$$->distance = (double)$2;
$$->type = $3;
$$->modifier = NULL;
$$->modtype = $1;
}
| t_property_distance_modifier_type T_INT t_property_unit t_property_distance_unit {
- $$ = g_malloc0(sizeof(RofiDistanceUnit));
+ $$ = g_slice_new0(RofiDistanceUnit);
$$->distance = (double)$2;
$$->type = $3;
$$->modifier = $4;
$$->modtype = $1;
}
| t_property_distance_modifier_type T_DOUBLE t_property_unit t_property_distance_unit {
- $$ = g_malloc0(sizeof(RofiDistanceUnit));
+ $$ = g_slice_new0(RofiDistanceUnit);
$$->distance = (double)$2;
$$->type = $3;
$$->modifier = $4;
diff --git a/source/theme.c b/source/theme.c
index c7489292..4603ce66 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -84,7 +84,7 @@ Property *rofi_theme_property_create ( PropertyType type )
static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit )
{
- RofiDistanceUnit *retv = g_malloc0( sizeof(RofiDistanceUnit) );
+ RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit );
*retv = *unit;
if ( unit->modifier ) {
retv->modifier = rofi_theme_property_copy_distance_unit ( unit->modifier );
@@ -142,7 +142,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit )
rofi_theme_distance_unit_property_free ( unit->modifier );
unit->modifier = NULL;
}
- g_free (unit);
+ g_slice_free ( RofiDistanceUnit, unit);
}
static void rofi_theme_distance_property_free ( RofiDistance *distance )
{
@@ -239,6 +239,9 @@ void rofi_theme_free ( ThemeWidget *widget )
g_hash_table_destroy ( widget->properties );
widget->properties = NULL;
}
+ if ( widget->media ) {
+ g_slice_free ( ThemeMedia, widget->media );
+ }
for ( unsigned int i = 0; i < widget->num_widgets; i++ ) {
rofi_theme_free ( widget->widgets[i] );
}
@@ -256,23 +259,37 @@ inline static void printf_double ( double d )
g_ascii_formatd ( buf, G_ASCII_DTOSTR_BUF_SIZE, "%.4lf", d );
fputs ( buf, stdout );
}
-static void rofi_theme_print_distance ( RofiDistance d )
+
+static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit )
{
- if ( d.base.type == ROFI_PU_PX ) {
- printf ( "%upx ", (unsigned int) d.base.distance );
+ if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) {
+ fputs ( " + ", stdout );
+ } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) {
+ fputs ( " - ", stdout );
}
- else if ( d.base.type == ROFI_PU_PERCENT ) {
- printf_double ( d.base.distance );
- fputs ( "%% ", stdout );
+
+ if ( unit->type == ROFI_PU_PX ) {
+ printf ( "%upx ", (unsigned int) unit->distance );
+ }
+ else if ( unit->type == ROFI_PU_PERCENT ) {
+ printf_double ( unit->distance );
+ fputs ( "% ", stdout );
}
- else if ( d.base.type == ROFI_PU_CH ) {
- printf_double ( d.base.distance );
+ else if ( unit->type == ROFI_PU_CH ) {
+ printf_double ( unit->distance );
fputs ( "ch ", stdout );
}
else {
- printf_double ( d.base.distance );
+ printf_double ( unit->distance );
fputs ( "em ", stdout );
}
+ if ( unit->modifier ) {
+ rofi_theme_print_distance_unit ( unit->modifier );
+ }
+}
+static void rofi_theme_print_distance ( RofiDistance d )
+{
+ rofi_theme_print_distance_unit ( &(d.base) );
if ( d.style == ROFI_HL_DASH ) {
printf ( "dash " );
}