From 5fd76b75b1e1e0d72f7bb821ac5db5bca4be10b7 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 10 Dec 2016 19:48:44 +0100 Subject: [PATCH] Add some color stuff --- include/theme.h | 15 ++++++++++++++- lexer/theme-lexer.l | 12 ++++++++++-- lexer/theme-parser.y | 2 +- source/theme.c | 6 +++++- source/view.c | 6 ++++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/theme.h b/include/theme.h index 6d0db4b8..1d906a06 100644 --- a/include/theme.h +++ b/include/theme.h @@ -9,6 +9,18 @@ typedef enum { P_COLOR } PropertyType; +typedef struct +{ + /** red channel */ + double red; + /** green channel */ + double green; + /** blue channel */ + double blue; + /** alpha channel */ + double alpha; +} ThemeColor; + typedef struct { char *name; PropertyType type; @@ -17,7 +29,7 @@ typedef struct { double f; char *s; int b; - unsigned int color; + ThemeColor color; } value; } Property; @@ -32,6 +44,7 @@ typedef struct _Widget { struct _Widget *parent; } Widget; + extern Widget *rofi_theme; Widget *rofi_theme_find_or_create_class ( Widget *base, const char *class ); diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index 59c67c28..90e66b39 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -24,8 +24,16 @@ 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]+ { yylval.colorval = (unsigned int)strtoull ( &yytext[1], NULL, 16); return T_COLOR;} -[\r\n]+ ; +#[0-9A-Fa-f]+ { + union { unsigned int val; struct { unsigned char a,r,g,b;};} val; + val.val = (unsigned int)strtoull ( &yytext[1], NULL, 16); + yylval.colorval.alpha = val.a/255.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; +} + [\r\n]+ ; <*><> { yyterminate(); diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 2079ddd1..952303e4 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -21,7 +21,7 @@ Widget *rofi_theme = NULL; double fval; char *sval; int bval; - unsigned int colorval; + ThemeColor colorval; Widget *theme; GList *name_path; Property *property; diff --git a/source/theme.c b/source/theme.c index 16ec8dec..7c0ca370 100644 --- a/source/theme.c +++ b/source/theme.c @@ -79,7 +79,11 @@ static void rofi_theme_print_property_index ( int depth, Property *p ) printf("%s", p->value.b?"true":"false"); break; case P_COLOR: - printf("#%08X", p->value.color); + printf("#%02X%02X%02X%02X", + (unsigned char)(p->value.color.alpha*255.0), + (unsigned char)(p->value.color.red*255.0), + (unsigned char)(p->value.color.green*255.0), + (unsigned char)(p->value.color.blue*255.0)); break; } putchar ( '\n' ); diff --git a/source/view.c b/source/view.c index 162f080c..01198876 100644 --- a/source/view.c +++ b/source/view.c @@ -1413,10 +1413,13 @@ RofiViewState *rofi_view_create ( Mode *sw, state->skip_absorb = FALSE; //We want to filter on the first run. state->refilter = TRUE; - state->border = config.padding + config.menu_bw; + state->border = 0; state->finalize = finalize; state->mouse_seen = FALSE; + state->border = rofi_theme_get_integer ( "window", "padding" , config.padding ); + state->border += rofi_theme_get_integer ( "window", "border-width" , config.menu_bw); + // Request the lines to show. state->num_lines = mode_get_num_entries ( sw ); @@ -1435,7 +1438,6 @@ RofiViewState *rofi_view_create ( Mode *sw, rofi_view_calculate_window_and_element_width ( state ); state->input_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height ); - //box_set_padding ( state->input_bar, config.line_margin ); state->input_bar_separator = separator_create ( S_HORIZONTAL, 2 ); separator_set_line_style_from_string ( state->input_bar_separator, config.separator_style );