From fb2ba8ada36ba5cdc009d527d2e2f177dd6b978c Mon Sep 17 00:00:00 2001 From: nick87720z Date: Wed, 10 Jun 2020 01:19:43 +0500 Subject: Millimeter support for distance (#1144) --- include/rofi-types.h | 2 ++ lexer/theme-lexer.l | 2 ++ lexer/theme-parser.y | 4 +++- source/theme.c | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/rofi-types.h b/include/rofi-types.h index 29fdca93..e6c65696 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -80,6 +80,8 @@ typedef enum { /** PixelWidth in pixels. */ ROFI_PU_PX, + /** PixelWidth in millimeters. */ + ROFI_PU_MM, /** PixelWidth in EM. */ ROFI_PU_EM, /** PixelWidget in percentage */ diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index e8ca45ba..6542df86 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -174,6 +174,7 @@ HEX [[:xdigit:]] NUMBER [[:digit:]] PNNUMBER [-+]?[[:digit:]]+ PX (px) +MM (mm) EM (em) CH (ch) PERCENT (\%) @@ -452,6 +453,7 @@ if ( queue == NULL ){ {EM} { return T_UNIT_EM; } {CH} { return T_UNIT_CH; } {PX} { return T_UNIT_PX; } +{MM} { return T_UNIT_MM; } {PERCENT} { return T_PERCENT; } {LS_SOLID} { return T_SOLID; } {LS_DASH} { return T_DASH; } diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index ed3fdb1c..9f1b2779 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -187,6 +187,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_SOLID "Solid" %token T_UNIT_PX "pixels" +%token T_UNIT_MM "mm" %token T_UNIT_EM "em" %token T_UNIT_CH "ch" %token T_UNIT_PERCENT "%" @@ -738,9 +739,10 @@ t_property_distance /** distance unit. px, em, % */ t_property_unit : T_UNIT_PX { $$ = ROFI_PU_PX; } +| T_UNIT_MM { $$ = ROFI_PU_MM; } | T_UNIT_EM { $$ = ROFI_PU_EM; } | T_UNIT_CH { $$ = ROFI_PU_CH; } -| T_PERCENT { $$ = ROFI_PU_PERCENT; } +| T_PERCENT { $$ = ROFI_PU_PERCENT; } ; /****** * Line style diff --git a/source/theme.c b/source/theme.c index 85bf7c86..d12eadfb 100644 --- a/source/theme.c +++ b/source/theme.c @@ -301,6 +301,10 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) if ( unit->type == ROFI_PU_PX ) { printf ( "%upx ", (unsigned int) unit->distance ); } + else if ( unit->type == ROFI_PU_MM ) { + printf_double ( unit->distance ); + fputs ( "mm ", stdout ); + } else if ( unit->type == ROFI_PU_PERCENT ) { printf_double ( unit->distance ); fputs ( "% ", stdout ); @@ -942,6 +946,9 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) val = ( unit->distance * width ) / ( 100.0 ); } } + else if ( unit->type == ROFI_PU_MM ) { + val = unit->distance * config.dpi / 25.4; + } return val; } -- cgit v1.2.3