Add some color stuff

This commit is contained in:
Dave Davenport 2016-12-10 19:48:44 +01:00
parent db248ea765
commit 5fd76b75b1
5 changed files with 34 additions and 7 deletions

View File

@ -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 );

View File

@ -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]+ ;
<*><<EOF>> {
yyterminate();

View File

@ -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;

View File

@ -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' );

View File

@ -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 );