diff options
author | Dave Davenport <DaveDavenport@users.noreply.github.com> | 2017-05-15 22:46:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-15 22:46:33 +0200 |
commit | 494550d38d572801ba3924611b09c7ca2b20610a (patch) | |
tree | df744a40f2bcaee4ba155faf4113b42089494500 | |
parent | e397c346da38f71c8b8f6e5e4cf57f7ee01b2404 (diff) |
[ThemeParser] Add CSS color names support
* [ThemeParser] Add css color names
* Add CSS color support (WIP)
* Parse color names in the lexer.
* Add test for css color names
* Indent and fix ordering
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | include/css-colors.h | 12 | ||||
-rw-r--r-- | include/helper.h | 2 | ||||
-rw-r--r-- | include/settings.h | 8 | ||||
-rw-r--r-- | lexer/theme-lexer.l | 24 | ||||
-rw-r--r-- | lexer/theme-parser.y | 43 | ||||
-rw-r--r-- | source/css-colors.c | 154 | ||||
-rw-r--r-- | source/theme.c | 10 | ||||
-rw-r--r-- | source/view.c | 26 | ||||
-rw-r--r-- | source/widgets/textbox.c | 10 | ||||
-rw-r--r-- | source/x11-helper.c | 11 | ||||
-rw-r--r-- | test/theme-parser-test.c | 45 |
12 files changed, 291 insertions, 64 deletions
diff --git a/Makefile.am b/Makefile.am index 9411806d..e76fc934 100644 --- a/Makefile.am +++ b/Makefile.am @@ -60,6 +60,7 @@ SOURCES=\ source/widgets/scrollbar.c\ source/xrmoptions.c\ source/x11-helper.c\ + source/css-colors.c\ source/dialogs/run.c\ source/dialogs/ssh.c\ source/dialogs/drun.c\ @@ -82,6 +83,7 @@ SOURCES=\ include/timings.h\ include/history.h\ include/theme.h\ + include/css-colors.h\ include/default-theme.h\ include/widgets/box.h\ include/widgets/container.h\ @@ -319,6 +321,7 @@ widget_test_SOURCES=\ source/widgets/widget.c\ source/widgets/textbox.c\ source/theme.c\ + source/css-colors.c\ source/helper.c\ source/x11-helper.c\ config/config.c\ @@ -334,7 +337,9 @@ box_test_SOURCES=\ lexer/theme-parser.y\ lexer/theme-lexer.l\ source/theme.c\ + source/css-colors.c\ include/theme.h\ + include/css-colors.h\ test/box-test.c scrollbar_test_LDADD=$(textbox_test_LDADD) @@ -345,7 +350,9 @@ scrollbar_test_SOURCES=\ lexer/theme-parser.y\ lexer/theme-lexer.l\ source/theme.c\ + source/css-colors.c\ include/theme.h\ + include/css-colors.h\ test/scrollbar-test.c textbox_test_SOURCES=\ @@ -354,6 +361,7 @@ textbox_test_SOURCES=\ lexer/theme-parser.y\ lexer/theme-lexer.l\ source/theme.c\ + source/css-colors.c\ source/helper.c\ source/x11-helper.c\ config/config.c\ @@ -382,6 +390,7 @@ theme_parser_test_SOURCES=\ include/helper.h\ include/helper-theme.h\ include/theme.h\ + include/css-colors.h\ include/xrmoptions.h\ source/xrmoptions.c\ source/x11-helper.c\ @@ -389,6 +398,7 @@ theme_parser_test_SOURCES=\ lexer/theme-parser.c\ lexer/theme-parser.h\ source/theme.c\ + source/css-colors.c\ test/theme-parser-test.c endif diff --git a/include/css-colors.h b/include/css-colors.h new file mode 100644 index 00000000..0c47b393 --- /dev/null +++ b/include/css-colors.h @@ -0,0 +1,12 @@ +#ifndef ROFI_INCLUDE_CSS_COLORS_H +#define ROFI_INCLUDE_CSS_COLORS_H + +typedef struct CSSColor +{ + char *name; + uint8_t b, g, r, a; +}CSSColor; + +extern const CSSColor CSSColors[]; +extern const unsigned int num_CSSColors; +#endif // ROFI_INCLUDE_CSS_COLORS_H diff --git a/include/helper.h b/include/helper.h index e3648b6b..03d4515f 100644 --- a/include/helper.h +++ b/include/helper.h @@ -244,7 +244,7 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st * are found, respectively, to be less than, to match, or be greater than the first `n` * characters (not bytes) of `b`. */ -int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__((nonnull(1,2))); +int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__( ( nonnull ( 1, 2 ) ) ); /** * @param wd The work directory (optional) diff --git a/include/settings.h b/include/settings.h index b0506f64..f18be7a9 100644 --- a/include/settings.h +++ b/include/settings.h @@ -65,13 +65,13 @@ typedef enum /** Middle left */ WL_WEST = 8, /** Left top corner. */ - WL_NORTH_WEST = WL_NORTH|WL_WEST, + WL_NORTH_WEST = WL_NORTH | WL_WEST, /** Top right */ - WL_NORTH_EAST = WL_NORTH|WL_EAST, + WL_NORTH_EAST = WL_NORTH | WL_EAST, /** Bottom right */ - WL_SOUTH_EAST = WL_SOUTH|WL_EAST, + WL_SOUTH_EAST = WL_SOUTH | WL_EAST, /** Bottom left */ - WL_SOUTH_WEST = WL_SOUTH|WL_WEST, + WL_SOUTH_WEST = WL_SOUTH | WL_WEST, } WindowLocation; /** diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index a35a5044..72d569c7 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -41,6 +41,7 @@ #include "theme.h" #include "theme-parser.h" +#include "css-colors.h" #define LOG_DOMAIN "Parser" int last_state = 0; @@ -147,6 +148,7 @@ UANYN {ASCN}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} WHITESPACE [[:blank:]] WSO [[:blank:]]* WORD [[:alnum:]-]+ +COLOR_NAME [[:alpha:]]+ STRING {UANYN}+ HEX [[:xdigit:]] NUMBER [[:digit:]] @@ -179,12 +181,13 @@ ANGLE_RAD "rad" ANGLE_TURN "turn" /* Color schema */ -RGBA "rgba" -RGB "rgb" +RGBA rgb[a]? HWB "hwb" CMYK "cmyk" HSL hsl[a]? +COLOR_TRANSPARENT "transparent" + S_T_PARENT_LEFT \( S_T_PARENT_RIGHT \) COMMA , @@ -422,7 +425,6 @@ if ( queue == NULL ){ } /* Color schemes */ <PROPERTIES>{RGBA} { return T_COL_RGBA; } -<PROPERTIES>{RGB} { return T_COL_RGB; } <PROPERTIES>{HSL} { return T_COL_HSL; } <PROPERTIES>{HWB} { return T_COL_HWB; } <PROPERTIES>{CMYK} { return T_COL_CMYK; } @@ -448,6 +450,22 @@ if ( queue == NULL ){ <PROPERTIES>{ANGLE_GRAD} { return T_ANGLE_GRAD; } <PROPERTIES>{ANGLE_TURN} { return T_ANGLE_TURN; } +<PROPERTIES>{COLOR_TRANSPARENT} { + return T_COLOR_TRANSPARENT; +} +<PROPERTIES>{COLOR_NAME} { + for ( unsigned int iter = 0; iter < num_CSSColors; iter++){ + if ( strcasecmp(yytext, CSSColors[iter].name )== 0 ) { + yylval->colorval.alpha = 1.0; + yylval->colorval.red = CSSColors[iter].r/255.0; + yylval->colorval.green = CSSColors[iter].g/255.0; + yylval->colorval.blue = CSSColors[iter].b/255.0; + return T_COLOR_NAME; + } + } + REJECT; +} + <INITIAL><<EOF>> { ParseObject *po = g_queue_pop_head ( file_queue ); if ( po ) { diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 7ba81ae6..7e9c1da2 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -35,6 +35,7 @@ %code requires { #include "theme.h" #include "xrmoptions.h" +#include "css-colors.h" typedef struct YYLTYPE { int first_line; @@ -157,6 +158,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token <fval> T_DOUBLE "Floating-point number" %token <sval> T_STRING "UTF-8 encoded string" %token <sval> T_PROP_NAME "property name" +%token <colorval> T_COLOR_NAME "Color value by name" %token <sval> T_NAME_ELEMENT "Element name" %token <bval> T_BOOLEAN "Boolean value (true or false)" %token <colorval> T_COLOR "Hexidecimal color value" @@ -183,8 +185,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_ANGLE_RAD "Radians" %token T_ANGLE_TURN "Turns" -%token T_COL_RGBA "rgba colorscheme" -%token T_COL_RGB "rgb colorscheme" +%token T_COL_RGBA "rgb[a] colorscheme" %token T_COL_HSL "hsl colorscheme" %token T_COL_HWB "hwb colorscheme" %token T_COL_CMYK "cmyk colorscheme" @@ -206,6 +207,8 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b) %token T_PDEFAULTS "Default settings section ( '* { ... }')" %token T_CONFIGURATION "Configuration block" +%token T_COLOR_TRANSPARENT "Transparent" + %type <sval> t_entry %type <theme> t_entry_list %type <name_path> t_entry_name_path @@ -433,41 +436,21 @@ t_property_line_style */ t_property_color /** rgba ( 0-255 , 0-255, 0-255, 0-1.0 ) */ -: T_COL_RGBA T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT T_COMMA t_property_color_value_unit T_PARENT_RIGHT { +: T_COL_RGBA T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT t_property_color_opt_alpha_c T_PARENT_RIGHT { if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; } if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; } if ( ! check_in_range($7,0,255, &(@$)) ) { YYABORT; } - $$.alpha = $9; + $$.alpha = $8; $$.red = $3/255.0; $$.green = $5/255.0; $$.blue = $7/255.0; } /** rgba ( 0-255 0-255 0-255 / 0-1.0 ) */ -| T_COL_RGBA T_PARENT_LEFT T_INT T_INT T_INT T_FORWARD_SLASH t_property_color_value_unit T_PARENT_RIGHT { - if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; } - if ( ! check_in_range($4,0,255, &(@$)) ) { YYABORT; } - if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; } - $$.alpha = $7; - $$.red = $3/255.0; - $$.green = $4/255.0; - $$.blue = $5/255.0; -} - /** rgb ( 0-255 , 0-255, 0-255 ) */ -| T_COL_RGB T_PARENT_LEFT T_INT T_COMMA T_INT T_COMMA T_INT T_PARENT_RIGHT { - if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; } - if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; } - if ( ! check_in_range($7,0,255, &(@$)) ) { YYABORT; } - $$.alpha = 1.0; - $$.red = $3/255.0; - $$.green = $5/255.0; - $$.blue = $7/255.0; -} - /** rgb ( 0-255 0-255 0-255 ) */ -| T_COL_RGB T_PARENT_LEFT T_INT T_INT T_INT T_PARENT_RIGHT { +| T_COL_RGBA T_PARENT_LEFT T_INT T_INT T_INT t_property_color_opt_alpha_ws T_PARENT_RIGHT { if ( ! check_in_range($3,0,255, &(@$)) ) { YYABORT; } if ( ! check_in_range($4,0,255, &(@$)) ) { YYABORT; } if ( ! check_in_range($5,0,255, &(@$)) ) { YYABORT; } - $$.alpha = 1.0; + $$.alpha = $6; $$.red = $3/255.0; $$.green = $4/255.0; $$.blue = $5/255.0; @@ -516,6 +499,14 @@ t_property_color | T_COLOR { $$ = $1; } +| T_COLOR_TRANSPARENT { + $$.alpha = 0.0; + $$.red = $$.green = $$.blue = 0.0; +} +| T_COLOR_NAME t_property_color_opt_alpha_ws { + $$ = $1; + $$.alpha = $2; +} ; t_property_color_opt_alpha_c : %empty { $$ = 1.0; } diff --git a/source/css-colors.c b/source/css-colors.c new file mode 100644 index 00000000..cc2a6b35 --- /dev/null +++ b/source/css-colors.c @@ -0,0 +1,154 @@ +#include <stdint.h> +#include "css-colors.h" +const CSSColor CSSColors[] = { + { .name = "AliceBlue", .r = 0xF0, .g = 0xF8, .b = 0xFF }, + { .name = "AntiqueWhite", .r = 0xFA, .g = 0xEB, .b = 0xD7 }, + { .name = "Aqua", .r = 0x00, .g = 0xFF, .b = 0xFF }, + { .name = "Aquamarine", .r = 0x7F, .g = 0xFF, .b = 0xD4 }, + { .name = "Azure", .r = 0xF0, .g = 0xFF, .b = 0xFF }, + { .name = "Beige", .r = 0xF5, .g = 0xF5, .b = 0xDC }, + { .name = "Bisque", .r = 0xFF, .g = 0xE4, .b = 0xC4 }, + { .name = "Black", .r = 0x00, .g = 0x00, .b = 0x00 }, + { .name = "BlanchedAlmond", .r = 0xFF, .g = 0xEB, .b = 0xCD }, + { .name = "Blue", .r = 0x00, .g = 0x00, .b = 0xFF }, + { .name = "BlueViolet", .r = 0x8A, .g = 0x2B, .b = 0xE2 }, + { .name = "Brown", .r = 0xA5, .g = 0x2A, .b = 0x2A }, + { .name = "BurlyWood", .r = 0xDE, .g = 0xB8, .b = 0x87 }, + { .name = "CadetBlue", .r = 0x5F, .g = 0x9E, .b = 0xA0 }, + { .name = "Chartreuse", .r = 0x7F, .g = 0xFF, .b = 0x00 }, + { .name = "Chocolate", .r = 0xD2, .g = 0x69, .b = 0x1E }, + { .name = "Coral", .r = 0xFF, .g = 0x7F, .b = 0x50 }, + { .name = "CornflowerBlue", .r = 0x64, .g = 0x95, .b = 0xED }, + { .name = "Cornsilk", .r = 0xFF, .g = 0xF8, .b = 0xDC }, + { .name = "Crimson", .r = 0xDC, .g = 0x14, .b = 0x3C }, + { .name = "Cyan", .r = 0x00, .g = 0xFF, .b = 0xFF }, + { .name = "DarkBlue", .r = 0x00, .g = 0x00, .b = 0x8B }, + { .name = "DarkCyan", .r = 0x00, .g = 0x8B, .b = 0x8B }, + { .name = "DarkGoldenRod", .r = 0xB8, .g = 0x86, .b = 0x0B }, + { .name = "DarkGray", .r = 0xA9, .g = 0xA9, .b = 0xA9 }, + { .name = "DarkGrey", .r = 0xA9, .g = 0xA9, .b = 0xA9 }, + { .name = "DarkGreen", .r = 0x00, .g = 0x64, .b = 0x00 }, + { .name = "DarkKhaki", .r = 0xBD, .g = 0xB7, .b = 0x6B }, + { .name = "DarkMagenta", .r = 0x8B, .g = 0x00, .b = 0x8B }, + { .name = "DarkOliveGreen", .r = 0x55, .g = 0x6B, .b = 0x2F }, + { .name = "DarkOrange", .r = 0xFF, .g = 0x8C, .b = 0x00 }, + { .name = "DarkOrchid", .r = 0x99, .g = 0x32, .b = 0xCC }, + { .name = "DarkRed", .r = 0x8B, .g = 0x00, .b = 0x00 }, + { .name = "DarkSalmon", .r = 0xE9, .g = 0x96, .b = 0x7A }, + { .name = "DarkSeaGreen", .r = 0x8F, .g = 0xBC, .b = 0x8F }, + { .name = "DarkSlateBlue", .r = 0x48, .g = 0x3D, .b = 0x8B }, + { .name = "DarkSlateGray", .r = 0x2F, .g = 0x4F, .b = 0x4F }, + { .name = "DarkSlateGrey", .r = 0x2F, .g = 0x4F, .b = 0x4F }, + { .name = "DarkTurquoise", .r = 0x00, .g = 0xCE, .b = 0xD1 }, + { .name = "DarkViolet", .r = 0x94, .g = 0x00, .b = 0xD3 }, + { .name = "DeepPink", .r = 0xFF, .g = 0x14, .b = 0x93 }, + { .name = "DeepSkyBlue", .r = 0x00, .g = 0xBF, .b = 0xFF }, + { .name = "DimGray", .r = 0x69, .g = 0x69, .b = 0x69 }, + { .name = "DimGrey", .r = 0x69, .g = 0x69, .b = 0x69 }, + { .name = "DodgerBlue", .r = 0x1E, .g = 0x90, .b = 0xFF }, + { .name = "FireBrick", .r = 0xB2, .g = 0x22, .b = 0x22 }, + { .name = "FloralWhite", .r = 0xFF, .g = 0xFA, .b = 0xF0 }, + { .name = "ForestGreen", .r = 0x22, .g = 0x8B, .b = 0x22 }, + { .name = "Fuchsia", .r = 0xFF, .g = 0x00, .b = 0xFF }, + { .name = "Gainsboro", .r = 0xDC, .g = 0xDC, .b = 0xDC }, + { .name = "GhostWhite", .r = 0xF8, .g = 0xF8, .b = 0xFF }, + { .name = "Gold", .r = 0xFF, .g = 0xD7, .b = 0x00 }, + { .name = "GoldenRod", .r = 0xDA, .g = 0xA5, .b = 0x20 }, + { .name = "Gray", .r = 0x80, .g = 0x80, .b = 0x80 }, + { .name = "Grey", .r = 0x80, .g = 0x80, .b = 0x80 }, + { .name = "Green", .r = 0x00, .g = 0x80, .b = 0x00 }, + { .name = "GreenYellow", .r = 0xAD, .g = 0xFF, .b = 0x2F }, + { .name = "HoneyDew", .r = 0xF0, .g = 0xFF, .b = 0xF0 }, + { .name = "HotPink", .r = 0xFF, .g = 0x69, .b = 0xB4 }, + { .name = "IndianRed", .r = 0xCD, .g = 0x5C, .b = 0x5C }, + { .name = "Indigo", .r = 0x4B, .g = 0x00, .b = 0x82 }, + { .name = "Ivory", .r = 0xFF, .g = 0xFF, .b = 0xF0 }, + { .name = "Khaki", .r = 0xF0, .g = 0xE6, .b = 0x8C }, + { .name = "Lavender", .r = 0xE6, .g = 0xE6, .b = 0xFA }, + { .name = "LavenderBlush", .r = 0xFF, .g = 0xF0, .b = 0xF5 }, + { .name = "LawnGreen", .r = 0x7C, .g = 0xFC, .b = 0x00 }, + { .name = "LemonChiffon", .r = 0xFF, .g = 0xFA, .b = 0xCD }, + { .name = "LightBlue", .r = 0xAD, .g = 0xD8, .b = 0xE6 }, + { .name = "LightCoral", .r = 0xF0, .g = 0x80, .b = 0x80 }, + { .name = "LightCyan", .r = 0xE0, .g = 0xFF, .b = 0xFF }, + { .name = "LightGoldenRodYellow", .r = 0xFA, .g = 0xFA, .b = 0xD2 }, + { .name = "LightGray", .r = 0xD3, .g = 0xD3, .b = 0xD3 }, + { .name = "LightGrey", .r = 0xD3, .g = 0xD3, .b = 0xD3 }, + { .name = "LightGreen", .r = 0x90, .g = 0xEE, .b = 0x90 }, + { .name = "LightPink", .r = 0xFF, .g = 0xB6, .b = 0xC1 }, + { .name = "LightSalmon", .r = 0xFF, .g = 0xA0, .b = 0x7A }, + { .name = "LightSeaGreen", .r = 0x20, .g = 0xB2, .b = 0xAA }, + { .name = "LightSkyBlue", .r = 0x87, .g = 0xCE, .b = 0xFA }, + { .name = "LightSlateGray", .r = 0x77, .g = 0x88, .b = 0x99 }, + { .name = "LightSlateGrey", .r = 0x77, .g = 0x88, .b = 0x99 }, + { .name = "LightSteelBlue", .r = 0xB0, .g = 0xC4, .b = 0xDE }, + { .name = "LightYellow", .r = 0xFF, .g = 0xFF, .b = 0xE0 }, + { .name = "Lime", .r = 0x00, .g = 0xFF, .b = 0x00 }, + { .name = "LimeGreen", .r = 0x32, .g = 0xCD, .b = 0x32 }, + { .name = "Linen", .r = 0xFA, .g = 0xF0, .b = 0xE6 }, + { .name = "Magenta", .r = 0xFF, .g = 0x00, .b = 0xFF }, + { .name = "Maroon", .r = 0x80, .g = 0x00, .b = 0x00 }, + { .name = "MediumAquaMarine", .r = 0x66, .g = 0xCD, .b = 0xAA }, + { .name = "MediumBlue", .r = 0x00, .g = 0x00, .b = 0xCD }, + { .name = "MediumOrchid", .r = 0xBA, .g = 0x55, .b = 0xD3 }, + { .name = "MediumPurple", .r = 0x93, .g = 0x70, .b = 0xDB }, + { .name = "MediumSeaGreen", .r = 0x3C, .g = 0xB3, .b = 0x71 }, + { .name = "MediumSlateBlue", .r = 0x7B, .g = 0x68, .b = 0xEE }, + { .name = "MediumSpringGreen", .r = 0x00, .g = 0xFA, .b = 0x9A }, + { .name = "MediumTurquoise", .r = 0x48, .g = 0xD1, .b = 0xCC }, + { .name = "MediumVioletRed", .r = 0xC7, .g = 0x15, .b = 0x85 }, + { .name = "MidnightBlue", .r = 0x19, .g = 0x19, .b = 0x70 }, + { .name = "MintCream", .r = 0xF5, .g = 0xFF, .b = 0xFA }, + { .name = "MistyRose", .r = 0xFF, .g = 0xE4, .b = 0xE1 }, + { .name = "Moccasin", .r = 0xFF, .g = 0xE4, .b = 0xB5 }, + { .name = "NavajoWhite", .r = 0xFF, .g = 0xDE, .b = 0xAD }, + { .name = "Navy", .r = 0x00, .g = 0x00, .b = 0x80 }, + { .name = "OldLace", .r = 0xFD, .g = 0xF5, .b = 0xE6 }, + { .name = "Olive", .r = 0x80, .g = 0x80, .b = 0x00 }, + { .name = "OliveDrab", .r = 0x6B, .g = 0x8E, .b = 0x23 }, + { .name = "Orange", .r = 0xFF, .g = 0xA5, .b = 0x00 }, + { .name = "OrangeRed", .r = 0xFF, .g = 0x45, .b = 0x00 }, + { .name = "Orchid", .r = 0xDA, .g = 0x70, .b = 0xD6 }, + { .name = "PaleGoldenRod", .r = 0xEE, .g = 0xE8, .b = 0xAA }, + { .name = "PaleGreen", .r = 0x98, .g = 0xFB, .b = 0x98 }, + { .name = "PaleTurquoise", .r = 0xAF, .g = 0xEE, .b = 0xEE }, + { .name = "PaleVioletRed", .r = 0xDB, .g = 0x70, .b = 0x93 }, + { .name = "PapayaWhip", .r = 0xFF, .g = 0xEF, .b = 0xD5 }, + { .name = "PeachPuff", .r = 0xFF, .g = 0xDA, .b = 0xB9 }, + { .name = "Peru", .r = 0xCD, .g = 0x85, .b = 0x3F }, + { .name = "Pink", .r = 0xFF, .g = 0xC0, .b = 0xCB }, + { .name = "Plum", .r = 0xDD, .g = 0xA0, .b = 0xDD }, + { .name = "PowderBlue", .r = 0xB0, .g = 0xE0, .b = 0xE6 }, + { .name = "Purple", .r = 0x80, .g = 0x00, .b = 0x80 }, + { .name = "RebeccaPurple", .r = 0x66, .g = 0x33, .b = 0x99 }, + { .name = "Red", .r = 0xFF, .g = 0x00, .b = 0x00 }, + { .name = "RosyBrown", .r = 0xBC, .g = 0x8F, .b = 0x8F }, + { .name = "RoyalBlue", .r = 0x41, .g = 0x69, .b = 0xE1 }, + { .name = "SaddleBrown", .r = 0x8B, .g = 0x45, .b = 0x13 }, + { .name = "Salmon", .r = 0xFA, .g = 0x80, .b = 0x72 }, + { .name = "SandyBrown", .r = 0xF4, .g = 0xA4, .b = 0x60 }, + { .name = "SeaGreen", .r = 0x2E, .g = 0x8B, .b = 0x57 }, + { .name = "SeaShell", .r = 0xFF, .g = 0xF5, .b = 0xEE }, + { .name = "Sienna", .r = 0xA0, .g = 0x52, .b = 0x2D }, + { .name = "Silver", .r = 0xC0, .g = 0xC0, .b = 0xC0 }, + { .name = "SkyBlue", .r = 0x87, .g = 0xCE, .b = 0xEB }, + { .name = "SlateBlue", .r = 0x6A, .g = 0x5A, .b = 0xCD }, + { .name = "SlateGray", .r = 0x70, .g = 0x80, .b = 0x90 }, + { .name = "SlateGrey", .r = 0x70, .g = 0x80, .b = 0x90 }, + { .name = "Snow", .r = 0xFF, .g = 0xFA, .b = 0xFA }, + { .name = "SpringGreen", .r = 0x00, .g = 0xFF, .b = 0x7F }, + { .name = "SteelBlue", .r = 0x46, .g = 0x82, .b = 0xB4 }, + { .name = "Tan", .r = 0xD2, .g = 0xB4, .b = 0x8C }, + { .name = "Teal", .r = 0x00, .g = 0x80, .b = 0x80 }, + { .name = "Thistle", .r = 0xD8, .g = 0xBF, .b = 0xD8 }, + { .name = "Tomato", .r = 0xFF, .g = 0x63, .b = 0x47 }, + { .name = "Turquoise", .r = 0x40, .g = 0xE0, .b = 0xD0 }, + { .name = "Violet", .r = 0xEE, .g = 0x82, .b = 0xEE }, + { .name = "Wheat", .r = 0xF5, .g = 0xDE, .b = 0xB3 }, + { .name = "White", .r = 0xFF, .g = 0xFF, .b = 0xFF }, + { .name = "WhiteSmoke", .r = 0xF5, .g = 0xF5, .b = 0xF5 }, + { .name = "Yellow", .r = 0xFF, .g = 0xFF, .b = 0x00 }, + { .name = "YellowGreen", .r = 0x9A, .g = 0xCD, .b = 0x32 } +}; + +const unsigned int num_CSSColors = sizeof ( CSSColors ) / sizeof ( *CSSColors ); diff --git a/source/theme.c b/source/theme.c index e31d0027..985d62c2 100644 --- a/source/theme.c +++ b/source/theme.c @@ -317,7 +317,7 @@ extern FILE* yyin; */ void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) { - char *what_esc = what?g_markup_escape_text ( what, -1 ):g_strdup(""); + char *what_esc = what ? g_markup_escape_text ( what, -1 ) : g_strdup ( "" ); GString *str = g_string_new ( "" ); g_string_printf ( str, "<big><b>Error while parsing theme:</b></big> <i>%s</i>\n", what_esc ); g_free ( what_esc ); @@ -638,7 +638,7 @@ gboolean rofi_theme_is_empty ( void ) void rofi_theme_convert_old ( void ) { if ( config.color_window ) { - char **retv = g_strsplit ( config.color_window, ",", -1 ); + char **retv = g_strsplit ( config.color_window, ",", -1 ); const char * const conf[] = { "* { background: %s; }", "* { bordercolor: %s; }", @@ -652,7 +652,7 @@ void rofi_theme_convert_old ( void ) g_strfreev ( retv ); } if ( config.color_normal ) { - char **retv = g_strsplit ( config.color_normal, ",", -1 ); + char **retv = g_strsplit ( config.color_normal, ",", -1 ); const char * const conf[] = { "* { normal-background: %s; }", "* { foreground: %s; normal-foreground: @foreground; alternate-normal-foreground: @foreground; }", @@ -668,7 +668,7 @@ void rofi_theme_convert_old ( void ) g_strfreev ( retv ); } if ( config.color_urgent ) { - char **retv = g_strsplit ( config.color_urgent, ",", -1 ); + char **retv = g_strsplit ( config.color_urgent, ",", -1 ); const char * const conf[] = { "* { urgent-background: %s; }", "* { urgent-foreground: %s; alternate-urgent-foreground: @urgent-foreground;}", @@ -684,7 +684,7 @@ void rofi_theme_convert_old ( void ) g_strfreev ( retv ); } if ( config.color_active ) { - char **retv = g_strsplit ( config.color_active, ",", -1 ); + char **retv = g_strsplit ( config.color_active, ",", -1 ); const char * const conf[] = { "* { active-background: %s; }", "* { active-foreground: %s; alternate-active-foreground: @active-foreground;}", diff --git a/source/view.c b/source/view.c index 9c74a0cc..416bad7d 100644 --- a/source/view.c +++ b/source/view.c @@ -70,7 +70,7 @@ #include "xcb.h" #ifdef XkBCOMMON_HAS_CONSUMED2 -#define xkb_state_key_get_consumed_mods(s, k) xkb_state_key_get_consumed_mods2(s, k, XKB_CONSUMED_MODE_GTK) +#define xkb_state_key_get_consumed_mods( s, k ) xkb_state_key_get_consumed_mods2 ( s, k, XKB_CONSUMED_MODE_GTK ) #endif /** @@ -714,8 +714,8 @@ void __create_window ( MenuFlags menu_flags ) } // Setup font. // Dummy widget. - container *win = container_create ( "window.box" ); - const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font ); + container *win = container_create ( "window.box" ); + const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font ); if ( font ) { PangoFontDescription *pfd = pango_font_description_from_string ( font ); if ( helper_validate_font ( pfd, font ) ) { @@ -1297,19 +1297,19 @@ gboolean rofi_view_trigger_action ( RofiViewState *state, KeyBindingAction actio break; // If you add a binding here, make sure to add it to textbox_keybinding too case MOVE_CHAR_BACK: - { - if ( textbox_keybinding ( state->text, action ) == 0 ) { - listview_nav_left ( state->list_view ); - } - break; + { + if ( textbox_keybinding ( state->text, action ) == 0 ) { + listview_nav_left ( state->list_view ); } + break; + } case MOVE_CHAR_FORWARD: - { - if ( textbox_keybinding ( state->text, action ) == 0 ) { - listview_nav_right ( state->list_view ); - } - break; + { + if ( textbox_keybinding ( state->text, action ) == 0 ) { + listview_nav_right ( state->list_view ); } + break; + } case CLEAR_LINE: case MOVE_FRONT: case MOVE_END: diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 32f38330..48c03084 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -135,7 +135,7 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType if ( helper_validate_font ( tbfc->pfd, font ) ) { tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL ); // Cast away consts. (*yuck*) because table_insert does not know it is const. - g_hash_table_insert ( tbfc_cache, (char *)font, tbfc ); + g_hash_table_insert ( tbfc_cache, (char *) font, tbfc ); } else { pango_font_description_free ( tbfc->pfd ); @@ -412,7 +412,7 @@ static int textbox_cursor_inc ( textbox *tb ) { int old = tb->cursor; textbox_cursor ( tb, tb->cursor + 1 ); - return ( old != tb->cursor ); + return old != tb->cursor; } /** @@ -426,7 +426,7 @@ static int textbox_cursor_dec ( textbox *tb ) { int old = tb->cursor; textbox_cursor ( tb, tb->cursor - 1 ); - return ( old != tb->cursor ); + return old != tb->cursor; } // Move word right @@ -633,10 +633,10 @@ int textbox_keybinding ( textbox *tb, KeyBindingAction action ) { // Left or Ctrl-b case MOVE_CHAR_BACK: - return (textbox_cursor_dec ( tb ) == TRUE)?2:0; + return ( textbox_cursor_dec ( tb ) == TRUE ) ? 2 : 0; // Right or Ctrl-F case MOVE_CHAR_FORWARD: - return (textbox_cursor_inc ( tb ) == TRUE)?2:0; + return ( textbox_cursor_inc ( tb ) == TRUE ) ? 2 : 0; // Ctrl-U: Kill from the beginning to the end of the line. case CLEAR_LINE: textbox_text ( tb, "" ); diff --git a/source/x11-helper.c b/source/x11-helper.c index 4a66ba36..5e1dce04 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -659,9 +659,9 @@ unsigned int x11_get_current_mask ( xkb_stuff *xkb ) // convert a Mod+key arg to mod mask and keysym gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release, GString *str ) { - char *input_key = g_strdup ( combo ); - char *mod_key = input_key; - char *error_msg = NULL; + char *input_key = g_strdup ( combo ); + char *mod_key = input_key; + char *error_msg = NULL; unsigned int last_modmask = 0; unsigned int modmask = 0; xkb_keysym_t last_sym = XKB_KEY_NoSymbol; @@ -679,7 +679,7 @@ gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key entry = g_strstrip ( entry ); // Compare against lowered version. last_modmask = modmask; - last_sym = xkb_keysym_from_name ( entry, XKB_KEYSYM_NO_FLAGS ); + last_sym = xkb_keysym_from_name ( entry, XKB_KEYSYM_NO_FLAGS ); char *entry_lowered = g_utf8_strdown ( entry, -1 ); if ( g_utf8_collate ( entry_lowered, "shift" ) == 0 ) { modmask |= x11_mod_masks[X11MOD_SHIFT]; @@ -735,11 +735,10 @@ gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key g_free ( input_key ); if ( ( sym == XKB_KEY_NoSymbol ) && ( last_sym != XKB_KEY_NoSymbol ) ) { - sym = last_sym; + sym = last_sym; modmask = last_modmask; } - if ( error_msg ) { char *name = g_markup_escape_text ( combo, -1 ); g_string_append_printf ( str, "Cannot understand the key combination: <i>%s</i>\n", name ); diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c index 488aa203..ba9538db 100644 --- a/test/theme-parser-test.c +++ b/test/theme-parser-test.c @@ -36,6 +36,7 @@ #include "rofi.h" #include "settings.h" #include "theme.h" +#include "css-colors.h" #include "widgets/widget-internal.h" #include "widgets/textbox.h" @@ -738,6 +739,46 @@ START_TEST ( test_properties_color_cmyk_ws ) ck_assert_double_eq_tol ( p->value.color.blue , 0 , 0.004); } END_TEST +START_TEST ( test_properties_color_names ) +{ + widget wid; + wid.name = "blaat"; + wid.state = NULL; + for ( unsigned int iter = 0; iter < num_CSSColors; iter++ ) { + char * str = g_strdup_printf("* { color: %s;}", CSSColors[iter].name); + rofi_theme_parse_string(str); + ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE ); + Property *p = rofi_theme_find_property ( twid, P_COLOR, "color", FALSE ); + ck_assert_ptr_nonnull ( p ); + ck_assert_double_eq ( p->value.color.alpha , 1.0 ); + ck_assert_double_eq_tol ( p->value.color.red , CSSColors[iter].r/255.0, 0.004); + ck_assert_double_eq_tol ( p->value.color.green, CSSColors[iter].g/255.0, 0.004 ); + ck_assert_double_eq_tol ( p->value.color.blue , CSSColors[iter].b/255.0, 0.004); + + g_free ( str ); + } +} +END_TEST +START_TEST ( test_properties_color_names_alpha ) +{ + widget wid; + wid.name = "blaat"; + wid.state = NULL; + for ( unsigned int iter = 0; iter < num_CSSColors; iter++ ) { + char * str = g_strdup_printf("* { color: %s / %d %%;}", CSSColors[iter].name, iter%101); + rofi_theme_parse_string(str); + ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE ); + Property *p = rofi_theme_find_property ( twid, P_COLOR, "color", FALSE ); + ck_assert_ptr_nonnull ( p ); + ck_assert_double_eq ( p->value.color.alpha , (iter%101)/100.0); + ck_assert_double_eq_tol ( p->value.color.red , CSSColors[iter].r/255.0, 0.004); + ck_assert_double_eq_tol ( p->value.color.green, CSSColors[iter].g/255.0, 0.004 ); + ck_assert_double_eq_tol ( p->value.color.blue , CSSColors[iter].b/255.0, 0.004); + + g_free ( str ); + } +} +END_TEST START_TEST ( test_properties_padding_2 ) { widget wid; @@ -875,7 +916,7 @@ START_TEST ( test_core_properties_error ) rofi_theme_parse_string ( " * { test: cmky(a,e,3); }"); const char *errstr = "<big><b>Error while parsing theme:</b></big> <i> * { test: cmky(a,e,3); }</i>\n"\ " Parser error: <span size=\"smaller\" style=\"italic\">syntax error, unexpected invalid property value</span>\n"\ - " Location: line 1 column 11 to line 1 column 13\n"; + " Location: line 1 column 11 to line 1 column 23\n"; ck_assert_int_eq ( error, 1); ck_assert_str_eq ( error_msg->str, errstr ); g_string_free ( error_msg, TRUE); @@ -968,6 +1009,8 @@ static Suite * theme_parser_suite (void) tcase_add_test ( tc_prop_color, test_properties_color_hwb_ws); tcase_add_test ( tc_prop_color, test_properties_color_cmyk); tcase_add_test ( tc_prop_color, test_properties_color_cmyk_ws); + tcase_add_test ( tc_prop_color, test_properties_color_names); + tcase_add_test ( tc_prop_color, test_properties_color_names_alpha); suite_add_tcase(s, tc_prop_color ); } { |