From 5f424fa598662e35f647b99c9e7755ffecb451ad Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 31 Dec 2016 21:37:19 +0100 Subject: [PATCH] Padding should be specified in px now and 4 borders can be specified on one pixel line. --- include/theme.h | 5 ++++- lexer/theme-lexer.l | 12 ++++++++++-- lexer/theme-parser.y | 12 ++++++++++++ source/theme.c | 30 ++---------------------------- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/include/theme.h b/include/theme.h index 75acbc43..3cf34387 100644 --- a/include/theme.h +++ b/include/theme.h @@ -7,7 +7,9 @@ typedef enum { P_DOUBLE, P_STRING, P_BOOLEAN, - P_COLOR + P_COLOR, + // Used in padding. + P_PADDING, } PropertyType; typedef struct @@ -40,6 +42,7 @@ typedef struct { char *s; int b; ThemeColor color; + Padding padding; } value; } Property; diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 01732733..0cf11f66 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -23,7 +23,9 @@ WHITESPACE [[:space:]] WORD [[:alnum:]-]+ STRING [[:print:]]+ HEX [[:xdigit:]] -NUMBER [[:digit:]-] +NUMBER [[:digit:]] +PX (px) +NEWLINES (\r|\n)+ %x PROPERTIES %x NAMESTR @@ -102,6 +104,11 @@ if ( queue == NULL ){ {NUMBER}+ { yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); return T_INT;} {NUMBER}+\.{NUMBER}+ { yylval->fval = g_ascii_strtod(yytext, NULL); return T_DOUBLE;} \"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;} + +{NUMBER}+{PX} { + yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10); + return T_PIXEL; +} #{HEX}{8} { union { unsigned int val; struct { unsigned char b,g,r,a;};} val; val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16); @@ -146,7 +153,8 @@ if ( queue == NULL ){ return T_COLOR; } -<*>(\r\n|\n) { +<*>(\r\n) { + printf("newlines\n"); yylloc->last_column = 1; yylloc->last_line ++; }; diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 3c64ee2d..1384f7fe 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -11,6 +11,7 @@ %{ #include #include +#include #include "theme.h" @@ -39,6 +40,7 @@ int yylex (YYSTYPE *, YYLTYPE *); %token NAME_ELEMENT %token T_BOOLEAN %token T_COLOR +%token T_PIXEL %token CLASS_NAME %token FIRST_NAME @@ -165,6 +167,16 @@ property $$->name = $1; $$->value.b = $3; } +| pvalue PSEP T_PIXEL PCLOSE { + $$ = rofi_theme_property_create ( P_PADDING ); + $$->name = $1; + $$->value.padding = (Padding){ $3, $3, $3, $3, FALSE }; +} +| pvalue PSEP T_PIXEL T_PIXEL T_PIXEL T_PIXEL PCLOSE { + $$ = rofi_theme_property_create ( P_PADDING ); + $$->name = $1; + $$->value.padding = (Padding){ $3, $4, $5, $6, FALSE }; +} ; pvalue: N_STRING { $$ = $1; } diff --git a/source/theme.c b/source/theme.c index bc322461..93ff78ee 100644 --- a/source/theme.c +++ b/source/theme.c @@ -285,35 +285,9 @@ void rofi_theme_get_color ( const char *wclass, const char *name, const char *s Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad ) { Widget *widget = rofi_theme_find_widget ( wclass, name, state ); - Property *p = rofi_theme_find_property ( widget, P_INTEGER, property ); + Property *p = rofi_theme_find_property ( widget, P_PADDING, property ); if ( p ){ - pad.left = pad.top = pad.bottom = pad.right = p->value.i; + pad = p->value.padding; } - - char *s = g_strdup_printf("%s-top", property); - p = rofi_theme_find_property ( widget, P_INTEGER, s ); - if ( p ){ - pad.top = p->value.i; - } - g_free(s); - s = g_strdup_printf("%s-left", property); - p = rofi_theme_find_property ( widget, P_INTEGER, s ); - if ( p ){ - pad.left = p->value.i; - } - g_free(s); - s = g_strdup_printf("%s-bottom", property); - p = rofi_theme_find_property ( widget, P_INTEGER, s ); - if ( p ){ - pad.bottom = p->value.i; - } - g_free(s); - s = g_strdup_printf("%s-right", property); - p = rofi_theme_find_property ( widget, P_INTEGER, s ); - if ( p ){ - pad.right = p->value.i; - } - g_free(s); - return pad; }