diff options
author | nick87720z <nick87720z@gmail.com> | 2020-06-10 01:19:43 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-09 22:19:43 +0200 |
commit | fb2ba8ada36ba5cdc009d527d2e2f177dd6b978c (patch) | |
tree | d6e77d3386d7819f155b5cf807aa0394fdd39335 | |
parent | 2da2a1f4dc9513fde9355b10569bccb1a1742db3 (diff) |
Millimeter support for distance (#1144)
-rw-r--r-- | include/rofi-types.h | 2 | ||||
-rw-r--r-- | lexer/theme-lexer.l | 2 | ||||
-rw-r--r-- | lexer/theme-parser.y | 4 | ||||
-rw-r--r-- | source/theme.c | 7 |
4 files changed, 14 insertions, 1 deletions
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 ){ <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{EM} { return T_UNIT_EM; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CH} { return T_UNIT_CH; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{PX} { return T_UNIT_PX; } +<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT,MEDIA_CONTENT>{MM} { return T_UNIT_MM; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{PERCENT} { return T_PERCENT; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{LS_SOLID} { return T_SOLID; } <PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{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; } |