1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Add support for rgb() rgba() color codes

This commit is contained in:
Dave Davenport 2016-12-11 17:50:03 +01:00
parent a0096f52c4
commit 7f40ed1065
2 changed files with 18 additions and 8 deletions

View file

@ -23,6 +23,7 @@ int yylex(void);
(true|false) { yylval.bval= g_strcmp0(yytext, "true") == 0; return T_BOOLEAN;}
[_\-a-zA-Z0-9]+ { yylval.sval = g_strdup(yytext); return N_STRING;}
\"[_\-a-zA-Z0-9 \t]+\" { yytext[yyleng-1] = '\0'; yylval.sval = g_strdup(&yytext[1]); return T_STRING;}
#[0-9A-Fa-f]{8} {
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
@ -34,12 +35,28 @@ int yylex(void);
}
#[0-9A-Fa-f]{6} {
union { unsigned int val; struct { unsigned char b,g,r,a;};} val;
val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16);
val.val = (unsigned int)g_ascii_strtoull ( &yytext[1], NULL, 16);
yylval.colorval.alpha = 1.0;
yylval.colorval.red = val.r/255.0;
yylval.colorval.green = val.g/255.0;
yylval.colorval.blue = val.b/255.0;
return T_COLOR;
}
rgba\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[01](\.[0-9]+)?\) {
char *endptr = &yytext[5];
yylval.colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
yylval.colorval.green= g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval.colorval.blue= g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval.colorval.alpha= g_ascii_strtod ( endptr+1, NULL);
return T_COLOR;
}
rgb\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\) {
char *endptr = &yytext[4];
yylval.colorval.red = g_ascii_strtoull ( endptr, &endptr, 10);
yylval.colorval.green = g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval.colorval.blue = g_ascii_strtoull ( endptr+1, &endptr, 10);
yylval.colorval.alpha = 1.0;
return T_COLOR;
}
[\r\n]+ ;

View file

@ -51,7 +51,6 @@ Widget *rofi_theme = NULL;
%type <name_path> name_path
%type <property> property
%type <property_list> property_list
%type <property_list> properties
%type <property_list> optional_properties
%start start
@ -99,12 +98,6 @@ optional_properties
: %empty { $$ = NULL; }
| property_list { $$ = $1; }
;
/*
properties: BOPEN property_list BCLOSE { $$ = $2;}
| BOPEN BCLOSE { $$ = NULL; }
| %empty { $$ = NULL; }
;
*/
property_list:
property {