From 9dd3cb312e46575637627fbfd78980b9aee39533 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 4 Jan 2017 22:27:27 +0100 Subject: [PATCH] Support linestyle on border --- include/theme.h | 58 ++++++---- lexer/theme-lexer.l | 42 ++++++++ source/theme.c | 211 +++++++++++++++++++++++++------------ source/view.c | 37 +++---- source/widgets/box.c | 6 +- source/widgets/listview.c | 17 ++- source/widgets/scrollbar.c | 3 +- source/widgets/separator.c | 4 +- source/widgets/textbox.c | 2 +- source/widgets/widget.c | 20 ++-- 10 files changed, 266 insertions(+), 134 deletions(-) diff --git a/include/theme.h b/include/theme.h index 58d7b7b8..defa3d05 100644 --- a/include/theme.h +++ b/include/theme.h @@ -2,7 +2,12 @@ #define THEME_H #include #include +#include +typedef enum { + SOLID, + DASH +} LineStyle; /** * Distance unit type. */ @@ -23,6 +28,8 @@ typedef struct { double distance; /** Unit type of the distance */ PixelWidth type; + /** Style of the line */ + LineStyle style; } Distance; /** @@ -150,7 +157,7 @@ void rofi_theme_property_free ( Property *p ); void rofi_theme_free ( ThemeWidget *wid ); /** - * @param file filename to parse. + * @param file filename to parse. * * Parse the input theme file. */ @@ -169,87 +176,87 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table ) */ /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param def The default value. * * Obtain the distance of the widget. * - * @returns The distance value of this property for this widget. + * @returns The distance value of this property for this widget. */ -Distance rofi_theme_get_distance ( const char *name, const char *state, const char *property, int def ); +Distance rofi_theme_get_distance ( const widget *widget, const char *property, int def ); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param def The default value. * * Obtain the integer of the widget. * - * @returns The integer value of this property for this widget. + * @returns The integer value of this property for this widget. */ -int rofi_theme_get_integer ( const char *name, const char *state, const char *property, int def ); +int rofi_theme_get_integer ( const widget *widget, const char *property, int def ); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param def The default value. * * Obtain the boolean of the widget. * - * @returns The boolean value of this property for this widget. + * @returns The boolean value of this property for this widget. */ -int rofi_theme_get_boolean ( const char *name, const char *state, const char *property, int def ); +int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param def The default value. * * Obtain the string of the widget. * - * @returns The string value of this property for this widget. + * @returns The string value of this property for this widget. */ -char *rofi_theme_get_string ( const char *name, const char *state, const char *property, char *def ); +char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param def The default value. * * Obtain the padding of the widget. * - * @returns The double value of this property for this widget. + * @returns The double value of this property for this widget. */ -double rofi_theme_get_double ( const char *name, const char *state, const char *property, double def ); +double rofi_theme_get_double ( const widget *widget, const char *property, double def ); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. - * @param d The drawable to apply color. + * @param d The drawable to apply color. * * Obtain the color of the widget and applies this to the drawable d. * */ -void rofi_theme_get_color ( const char *name, const char *state, const char *property, cairo_t *d); +void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d); /** - * @param name The name class + * @param widget The widget to query * @param state The widget current state * @param property The property to query. * @param pad The default value. * * Obtain the padding of the widget. * - * @returns The padding of this property for this widget. + * @returns The padding of this property for this widget. */ -Padding rofi_theme_get_padding ( const char *name, const char *state, const char *property, Padding pad ); +Padding rofi_theme_get_padding ( const widget *widget, const char *property, Padding pad ); /** * @param d The distance handle. @@ -259,6 +266,13 @@ Padding rofi_theme_get_padding ( const char *name, const char *state, const cha * @returns the number of pixels this distance represents. */ int distance_get_pixel ( Distance d, Orientation ori ); +/** + * @param d The distance handle. + * @param draw The cairo drawable. + * + * Set linestyle. + */ +void distance_get_linestyle ( Distance d, cairo_t *draw ); #ifdef THEME_CONVERTER /** diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l index b66a11bd..6a6f8687 100644 --- a/lexer/theme-lexer.l +++ b/lexer/theme-lexer.l @@ -30,6 +30,9 @@ EM (em) PERCENT (\%) NEWLINES (\r|\n)+ +LS_DASH "dash" +LS_SOLID "solid" + %x PROPERTIES %x NAMESTR %x ENTRY @@ -110,16 +113,55 @@ if ( queue == NULL ){ {REAL}{EM} { yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL); yylval->distance.type = PW_EM; + yylval->distance.style = SOLID; return T_PIXEL; } {NUMBER}+{PX} { yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10); yylval->distance.type = PW_PX; + yylval->distance.style = SOLID; + return T_PIXEL; +} +{NUMBER}+{PX}{WHITESPACE}{LS_DASH} { + yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10); + yylval->distance.type = PW_PX; + yylval->distance.style = DASH; + return T_PIXEL; +} +{NUMBER}+{EM}{WHITESPACE}{LS_DASH} { + yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10); + yylval->distance.type = PW_PX; + yylval->distance.style = DASH; + return T_PIXEL; +} +{NUMBER}+{PX}{WHITESPACE}{LS_SOLID} { + yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10); + yylval->distance.type = PW_PX; + yylval->distance.style = SOLID; + return T_PIXEL; +} +{NUMBER}+{EM}{WHITESPACE}{LS_SOLID} { + yylval->distance.distance = (double)g_ascii_strtoll(yytext, NULL, 10); + yylval->distance.type = PW_PX; + yylval->distance.style = SOLID; return T_PIXEL; } {REAL}{PERCENT} { yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL); yylval->distance.type = PW_PERCENT; + yylval->distance.style = SOLID; + return T_PIXEL; +} +{REAL}{PERCENT}{WHITESPACE}{LS_SOLID} { + yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL); + yylval->distance.type = PW_PERCENT; + yylval->distance.style = SOLID; + return T_PIXEL; +} +{REAL}{PERCENT}{WHITESPACE}{LS_DASH} { + yylval->distance.distance = (double)g_ascii_strtod(yytext, NULL); + yylval->distance.type = PW_PERCENT; + yylval->distance.style = DASH; return T_PIXEL; } #{HEX}{8} { diff --git a/source/theme.c b/source/theme.c index fb11aa09..56252610 100644 --- a/source/theme.c +++ b/source/theme.c @@ -287,67 +287,66 @@ static ThemeWidget *rofi_theme_find_widget ( const char *name, const char *state return widget; } -int rofi_theme_get_integer ( const char *name, const char *state, const char *property, int def ) +int rofi_theme_get_integer ( const widget *widget, const char *property, int def ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_INTEGER, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_INTEGER, property ); if ( p ){ return p->value.i; } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); return def; } -Distance rofi_theme_get_distance ( const char *name, const char *state, const char *property, int def ) +Distance rofi_theme_get_distance ( const widget *widget, const char *property, int def ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_PADDING, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_PADDING, property ); if ( p ){ - return p->value.padding.left; + if ( p->type == P_INTEGER ){ + return (Distance){p->value.i,PW_PX, SOLID}; + } else { + return p->value.padding.left; + } } - // Fall back to px if no metric is given. - p = rofi_theme_find_property ( widget, P_INTEGER, property ); - if ( p ){ - return (Distance){(double)p->value.i, PW_PX}; - } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); - return (Distance){def, PW_PX}; + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); + return (Distance){def, PW_PX, SOLID}; } -int rofi_theme_get_boolean ( const char *name, const char *state, const char *property, int def ) +int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_BOOLEAN, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_BOOLEAN, property ); if ( p ){ return p->value.b; } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); return def; } -char *rofi_theme_get_string ( const char *name, const char *state, const char *property, char *def ) +char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_STRING, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_STRING, property ); if ( p ){ return p->value.s; } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); return def; } -double rofi_theme_get_double ( const char *name, const char *state, const char *property, double def ) +double rofi_theme_get_double ( const widget *widget, const char *property, double def ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_DOUBLE, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_DOUBLE, property ); if ( p ){ return p->value.b; } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); return def; } -void rofi_theme_get_color ( const char *name, const char *state, const char *property, cairo_t *d) +void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_COLOR, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_COLOR, property ); if ( p ){ cairo_set_source_rgba ( d, p->value.color.red, @@ -356,22 +355,22 @@ void rofi_theme_get_color ( const char *name, const char *state, const char *pr p->value.color.alpha ); } else { - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); } } -Padding rofi_theme_get_padding ( const char *name, const char *state, const char *property, Padding pad ) +Padding rofi_theme_get_padding ( const widget *widget, const char *property, Padding pad ) { - ThemeWidget *widget = rofi_theme_find_widget ( name, state ); - Property *p = rofi_theme_find_property ( widget, P_PADDING, property ); + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state ); + Property *p = rofi_theme_find_property ( wid, P_PADDING, property ); if ( p ){ if ( p->type == P_PADDING ){ - pad = p->value.padding; + pad = p->value.padding; } else { - Distance d = (Distance){p->value.i, PW_PX}; + Distance d = (Distance){p->value.i, PW_PX, SOLID}; return (Padding){d,d,d,d}; } } - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", name, state?state:"", property ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Theme entry: #%s %s property %s unset.", widget->name, widget->state?widget->state:"", property ); return pad; } int distance_get_pixel ( Distance d, Orientation ori ) @@ -393,6 +392,14 @@ int distance_get_pixel ( Distance d, Orientation ori ) return d.distance; } +void distance_get_linestyle ( Distance d, cairo_t *draw ) +{ + if ( d.style == DASH ){ + const double dashes[1] = { 4 }; + cairo_set_dash ( draw, dashes, 1, 0.0 ); + } +} + #ifdef THEME_CONVERTER static Property* rofi_theme_convert_get_color ( const char *color, const char *name ) @@ -422,6 +429,35 @@ void rofi_theme_convert_old_theme ( void ) rofi_theme = (ThemeWidget*)g_malloc0 ( sizeof ( ThemeWidget ) ); rofi_theme->name = g_strdup ( "Root" ); rofi_theme_convert_create_property_ht ( rofi_theme ); + ThemeWidget *window_widget = rofi_theme_find_or_create_name ( rofi_theme , "window" ); + rofi_theme_convert_create_property_ht ( window_widget ); + ThemeWidget *mainbox_widget = rofi_theme_find_or_create_name ( window_widget, "mainbox" ); + rofi_theme_convert_create_property_ht ( mainbox_widget ); + ThemeWidget *message = rofi_theme_find_or_create_name ( mainbox_widget, "message" ); + rofi_theme_convert_create_property_ht ( message ); + ThemeWidget *listview_widget = rofi_theme_find_or_create_name ( mainbox_widget, "listview" ); + rofi_theme_convert_create_property_ht ( listview_widget ); + { + Property *p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("border"); + p->value.i = 0; + g_hash_table_replace ( mainbox_widget->properties, p->name, p); + + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("padding"); + p->value.i = config.padding; + g_hash_table_replace ( window_widget->properties, p->name, p); + + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("padding"); + p->value.i = 0; + g_hash_table_replace ( mainbox_widget->properties, p->name, p); + // Spacing + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup("spacing"); + p->value.i = config.line_margin; + g_hash_table_replace ( rofi_theme->properties, p->name, p ); + } { // Background Property *p = rofi_theme_property_create ( P_COLOR ); @@ -431,33 +467,59 @@ void rofi_theme_convert_old_theme ( void ) p->value.color.green= 0; p->value.color.blue= 0; g_hash_table_replace ( rofi_theme->properties, p->name, p ); - // Spacing - p = rofi_theme_property_create ( P_INTEGER ); - p->name = g_strdup("spacing"); - p->value.i = config.padding; - g_hash_table_replace ( rofi_theme->properties, p->name, p ); - p = rofi_theme_property_create ( P_STRING ); - p->name = g_strdup ( "line-style" ); - p->value.s= g_strdup(config.separator_style); - g_hash_table_replace ( rofi_theme->properties, p->name, p ); - - ThemeWidget *inputbar_widget = rofi_theme_find_or_create_name ( rofi_theme , "inputbar" ); + ThemeWidget *inputbar_widget = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" ); rofi_theme_convert_create_property_ht ( inputbar_widget ); p = rofi_theme_property_create ( P_INTEGER ); p->name = g_strdup("spacing"); p->value.i = 0; g_hash_table_replace ( inputbar_widget->properties, p->name, p ); + + + LineStyle style = (g_strcmp0(config.separator_style,"dash") == 0)?DASH:SOLID; + int place_end = ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST ); + p = rofi_theme_property_create ( P_PADDING ); + p->name = g_strdup("border"); + Distance d = (Distance){config.menu_bw, PW_PX, style}; + if ( place_end ){ + p->value.padding.bottom= d; + } else { + p->value.padding.top= d; + } + g_hash_table_replace ( listview_widget->properties, p->name, p ); + + p = rofi_theme_property_create ( P_PADDING ); + p->name = g_strdup("border"); + d = (Distance){config.menu_bw, PW_PX, style}; + if ( place_end ){ + p->value.padding.bottom= d; + } else { + p->value.padding.top= d; + } + g_hash_table_replace ( message->properties, p->name, p ); + p = rofi_theme_property_create ( P_PADDING ); + p->name = g_strdup("padding"); + d = (Distance){config.line_margin, PW_PX, SOLID}; + if ( place_end ){ + p->value.padding.bottom= d; + } else { + p->value.padding.top= d; + } + g_hash_table_replace ( listview_widget->properties, p->name, p ); + + p = rofi_theme_property_create ( P_PADDING ); + p->name = g_strdup("padding"); + d = (Distance){config.line_margin, PW_PX, SOLID}; + if ( place_end ){ + p->value.padding.bottom= d; + } else { + p->value.padding.top= d; + } + g_hash_table_replace ( message->properties, p->name, p ); + } { - // Spacing - ThemeWidget *listview_widget = rofi_theme_find_or_create_name ( rofi_theme , "listview" ); - rofi_theme_convert_create_property_ht ( listview_widget ); Property *p = rofi_theme_property_create ( P_INTEGER ); - p->name = g_strdup("spacing"); - p->value.i = config.padding; - g_hash_table_replace ( listview_widget->properties, p->name, p ); - p = rofi_theme_property_create ( P_INTEGER ); p->name = g_strdup("columns"); p->value.i = config.menu_columns; g_hash_table_replace ( listview_widget->properties, p->name, p ); @@ -468,7 +530,6 @@ void rofi_theme_convert_old_theme ( void ) } { // Border width. - ThemeWidget *window_widget = rofi_theme_find_or_create_name ( rofi_theme , "window" ); rofi_theme_convert_create_property_ht ( window_widget ); // Padding Property *p = rofi_theme_property_create ( P_INTEGER ); @@ -485,24 +546,22 @@ void rofi_theme_convert_old_theme ( void ) gchar **vals = g_strsplit ( config.color_window, ",", 3 ); if ( vals != NULL ){ if ( vals[0] != NULL ) { - ThemeWidget *window = rofi_theme_find_or_create_name ( rofi_theme, "window" ); - rofi_theme_convert_create_property_ht ( window ); Property *p = rofi_theme_convert_get_color ( vals[0], "background" ); - g_hash_table_replace ( window->properties, p->name, p ); + g_hash_table_replace ( window_widget->properties, p->name, p ); if ( vals[1] != NULL ) { p = rofi_theme_convert_get_color ( vals[1], "foreground" ); - g_hash_table_replace ( window->properties, p->name, p ); + g_hash_table_replace ( window_widget->properties, p->name, p ); - ThemeWidget *inputbar = rofi_theme_find_or_create_name ( rofi_theme , "inputbar" ); - ThemeWidget *widget = rofi_theme_find_or_create_name ( inputbar, "separator" ); + ThemeWidget *inputbar = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" ); + ThemeWidget *widget = rofi_theme_find_or_create_name ( inputbar, "box" ); rofi_theme_convert_create_property_ht ( widget ); if ( vals[2] != NULL ) { p = rofi_theme_convert_get_color ( vals[2], "foreground" ); - g_hash_table_replace ( widget->properties, p->name, p ); + g_hash_table_replace ( window_widget->properties, p->name, p ); } else { p = rofi_theme_convert_get_color ( vals[1], "foreground" ); - g_hash_table_replace ( widget->properties, p->name, p ); + g_hash_table_replace ( window_widget->properties, p->name, p ); } } @@ -511,13 +570,30 @@ void rofi_theme_convert_old_theme ( void ) g_strfreev ( vals ); { Property *p = NULL; - ThemeWidget *listview= rofi_theme_find_or_create_name ( rofi_theme , "listview" ); - ThemeWidget *widget = rofi_theme_find_or_create_name ( listview , "element" ); + ThemeWidget *widget = rofi_theme_find_or_create_name ( listview_widget, "element" ); + ThemeWidget *scrollbar = rofi_theme_find_or_create_name ( listview_widget, "scrollbar" ); + ThemeWidget *wnormal = rofi_theme_find_or_create_name ( widget, "normal" ); ThemeWidget *wselected = rofi_theme_find_or_create_name ( widget, "selected" ); ThemeWidget *walternate = rofi_theme_find_or_create_name ( widget, "alternate" ); + rofi_theme_convert_create_property_ht ( widget ); + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("border"); + p->value.i = 0; + g_hash_table_replace ( widget->properties, p->name, p); + + rofi_theme_convert_create_property_ht ( scrollbar ); + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("border"); + p->value.i = 0; + g_hash_table_replace ( scrollbar->properties, p->name, p); + p = rofi_theme_property_create ( P_INTEGER ); + p->name = g_strdup ("padding"); + p->value.i = 0; + g_hash_table_replace ( scrollbar->properties, p->name, p); + gchar **vals = g_strsplit ( config.color_normal, ",", 5 ); if ( g_strv_length (vals) == 5 ) { @@ -542,7 +618,7 @@ void rofi_theme_convert_old_theme ( void ) p = rofi_theme_convert_get_color ( vals[1], "foreground" ); g_hash_table_replace ( wal->properties, p->name, p ); - ThemeWidget *inputbar = rofi_theme_find_or_create_name ( rofi_theme, "inputbar" ); + ThemeWidget *inputbar = rofi_theme_find_or_create_name ( mainbox_widget, "inputbar" ); wnn = rofi_theme_find_or_create_name ( inputbar, "normal" ); rofi_theme_convert_create_property_ht ( wnn ); p = rofi_theme_convert_get_color ( vals[0], "background" ); @@ -550,7 +626,6 @@ void rofi_theme_convert_old_theme ( void ) p = rofi_theme_convert_get_color ( vals[1], "foreground" ); g_hash_table_replace ( wnn->properties, p->name, p ); - ThemeWidget *message = rofi_theme_find_or_create_name ( rofi_theme, "message" ); wnn = rofi_theme_find_or_create_name ( message, "normal" ); rofi_theme_convert_create_property_ht ( wnn ); p = rofi_theme_convert_get_color ( vals[0], "background" ); diff --git a/source/view.c b/source/view.c index 26e723bf..337ee5b0 100644 --- a/source/view.c +++ b/source/view.c @@ -612,7 +612,9 @@ void __create_window ( MenuFlags menu_flags ) pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi ); } // Setup font. - char *font = rofi_theme_get_string ( "window", NULL, "font" , config.menu_font ); + // Dummy widget. + window *win = window_create ( "window" ); + char *font = rofi_theme_get_string ( WIDGET ( win ), "font" , config.menu_font ); if ( font ) { PangoFontDescription *pfd = pango_font_description_from_string ( font ); pango_context_set_font_description ( p, pfd ); @@ -650,7 +652,7 @@ void __create_window ( MenuFlags menu_flags ) CacheState.flags = menu_flags; monitor_active ( &( CacheState.mon ) ); - char *transparency = rofi_theme_get_string ( "window", NULL, "transparency", NULL); + char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL); if ( transparency == NULL && config.fake_transparency ){ transparency = config.fake_background; } @@ -660,6 +662,7 @@ void __create_window ( MenuFlags menu_flags ) if ( xcb->sncontext != NULL ) { sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window ); } + widget_free ( WIDGET ( win ) ); } /** @@ -1450,24 +1453,21 @@ RofiViewState *rofi_view_create ( Mode *sw, TICK_N ( "Get active monitor" ); state->main_window = window_create ( "window" ); - state->main_box = box_create ( "mainbox.box", BOX_VERTICAL ); + state->main_box = box_create ( "window.mainbox.box", BOX_VERTICAL ); window_add ( state->main_window, WIDGET ( state->main_box ) ); - state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL ); - state->input_bar_separator = separator_create ( "inputbar.separator", S_HORIZONTAL, 2 ); + state->input_bar = box_create ( "window.mainbox.inputbar.box", BOX_HORIZONTAL ); // Only enable widget when sidebar is enabled. if ( config.sidebar_mode ) { - state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL ); - separator *sep = separator_create ( "sidebar.separator", S_HORIZONTAL, 2 ); + state->sidebar_bar = box_create ( "window.mainbox.sidebar.box", BOX_HORIZONTAL ); box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE ); - box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE ); state->num_modi = rofi_get_num_enabled_modi (); state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) ); for ( unsigned int j = 0; j < state->num_modi; j++ ) { const Mode * mode = rofi_get_mode ( j ); - state->modi[j] = textbox_create ( "sidebar.button", TB_CENTER|TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, + state->modi[j] = textbox_create ( "window.mainbox.sidebar.button", TB_CENTER|TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, mode_get_display_name ( mode ) ); box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE, FALSE ); widget_set_clicked_handler ( WIDGET ( state->modi[j] ), rofi_view_modi_clicked_cb, state ); @@ -1477,35 +1477,32 @@ RofiViewState *rofi_view_create ( Mode *sw, int end = ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST ); box_add ( state->main_box, WIDGET ( state->input_bar ), FALSE, end ); - state->case_indicator = textbox_create ( "inputbar.case-indicator", TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "*" ); + state->case_indicator = textbox_create ( "window.mainbox.inputbar.case-indicator", TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "*" ); // Add small separator between case indicator and text box. box_add ( state->input_bar, WIDGET ( state->case_indicator ), FALSE, TRUE ); // Prompt box. - state->prompt = textbox_create ( "inputbar.prompt",TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "" ); + state->prompt = textbox_create ( "window.mainbox.inputbar.prompt",TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "" ); rofi_view_update_prompt ( state ); box_add ( state->input_bar, WIDGET ( state->prompt ), FALSE, FALSE ); // Entry box TextboxFlags tfl = TB_EDITABLE; tfl |= ( ( menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0; - state->text = textbox_create ( "inputbar.entry", tfl|TB_AUTOHEIGHT, NORMAL, input ); + state->text = textbox_create ( "window.mainbox.inputbar.entry", tfl|TB_AUTOHEIGHT, NORMAL, input ); box_add ( state->input_bar, WIDGET ( state->text ), TRUE, FALSE ); textbox_text ( state->case_indicator, get_matching_state () ); if ( message ) { - textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message ); - separator *sep = separator_create ( "message.separator", S_HORIZONTAL, 2 ); - box_add ( state->main_box, WIDGET ( sep ), FALSE, end); + textbox *message_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message ); box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end); } - box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, end ); - state->overlay = textbox_create ( "overlay.textbox", TB_AUTOWIDTH|TB_AUTOHEIGHT, URGENT, "blaat" ); + state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH|TB_AUTOHEIGHT, URGENT, "blaat" ); widget_disable ( WIDGET ( state->overlay ) ); - state->list_view = listview_create ( "listview", update_callback, state, config.element_height, end ); + state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end ); // Set configuration listview_set_multi_select ( state->list_view, ( state->menu_flags & MENU_INDICATOR ) == MENU_INDICATOR ); listview_set_scroll_type ( state->list_view, config.scroll_method ); @@ -1550,9 +1547,9 @@ int rofi_view_error_dialog ( const char *msg, int markup ) state->finalize = process_result; state->main_window = window_create ( "window" ); - state->main_box = box_create ( "mainbox.box", BOX_VERTICAL); + state->main_box = box_create ( "window.mainbox", BOX_VERTICAL); window_add ( state->main_window, WIDGET ( state->main_box ) ); - state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), + state->text = textbox_create ( "window.mainbox.message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), NORMAL, ( msg != NULL ) ? msg : "" ); box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE ); diff --git a/source/widgets/box.c b/source/widgets/box.c index 108d419f..7bd48537 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -279,8 +279,8 @@ void box_add ( box *box, widget *child, gboolean expand, gboolean end ) height = MAX (height, child->h+widget_padding_get_padding_height ( WIDGET ( box ))); box->widget.h = height; } - child->expand = rofi_theme_get_boolean ( child->name, child->state, "expand", expand); - child->end = rofi_theme_get_boolean ( child->name, child->state, "end", end); + child->expand = rofi_theme_get_boolean ( child, "expand", expand); + child->end = rofi_theme_get_boolean ( child, "end", end); child->parent = WIDGET ( box ); box->children = g_list_append ( box->children, (void *) child ); widget_update ( WIDGET ( box ) ); @@ -346,7 +346,7 @@ box * box_create ( const char *name, boxType type ) b->widget.get_desired_height = box_get_desired_height; b->widget.enabled = TRUE; - b->spacing = rofi_theme_get_distance ( b->widget.name, NULL, "spacing",DEFAULT_SPACING ); + b->spacing = rofi_theme_get_distance ( WIDGET(b), "spacing", DEFAULT_SPACING ); return b; } diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 535465d9..0e0ef223 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -366,15 +366,14 @@ listview *listview_create ( const char *name, listview_update_callback cb, void lv->udata = udata; // Some settings. - lv->spacing = rofi_theme_get_distance ( lv->widget.name, NULL, "spacing", DEFAULT_SPACING ); - lv->menu_columns = rofi_theme_get_integer ( lv->widget.name, NULL, "columns", config.menu_columns ); - lv->fixed_num_lines = rofi_theme_get_boolean ( lv->widget.name, NULL, "fixed-height", config.fixed_num_lines ); - lv->dynamic = rofi_theme_get_boolean ( lv->widget.name, NULL, "dynamic", TRUE ); - - lv->reverse = rofi_theme_get_boolean ( lv->widget.name, NULL, "reverse", reverse ); - listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( lv->widget.name, NULL, "scrollbar", !config.hide_scrollbar )); - listview_set_scrollbar_width ( lv, rofi_theme_get_integer ( lv->widget.name, NULL, "scrollbar-width", config.scrollbar_width )); - lv->cycle = rofi_theme_get_boolean ( lv->widget.name, NULL, "cycle", config.cycle ); + lv->spacing = rofi_theme_get_distance ( WIDGET ( lv ), "spacing", DEFAULT_SPACING ); + lv->menu_columns = rofi_theme_get_integer ( WIDGET ( lv ), "columns", config.menu_columns ); + lv->fixed_num_lines = rofi_theme_get_boolean ( WIDGET ( lv ), "fixed-height", config.fixed_num_lines ); + lv->dynamic = rofi_theme_get_boolean ( WIDGET ( lv ), "dynamic", TRUE ); + lv->reverse = rofi_theme_get_boolean ( WIDGET ( lv ), "reverse", reverse ); + listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( WIDGET ( lv ), "scrollbar", !config.hide_scrollbar )); + listview_set_scrollbar_width ( lv, rofi_theme_get_integer ( WIDGET ( lv ), "scrollbar-width", config.scrollbar_width )); + lv->cycle = rofi_theme_get_boolean ( WIDGET ( lv ), "cycle", config.cycle ); return lv; diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c index 32a0023b..41f18414 100644 --- a/source/widgets/scrollbar.c +++ b/source/widgets/scrollbar.c @@ -45,6 +45,7 @@ scrollbar *scrollbar_create ( const char *name, int width ) { scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) ); widget_init ( WIDGET (sb), name ); + sb->widget.state = g_strdup("handle"); sb->widget.x = 0; sb->widget.y = 0; sb->widget.w = widget_padding_get_padding_width ( WIDGET (sb) ) +width; @@ -118,7 +119,7 @@ static void scrollbar_draw ( widget *wid, cairo_t *draw ) // Never go out of bar. height = MAX ( 2, height ); // Cap length; - rofi_theme_get_color ( sb->widget.name, "handle", "foreground", draw ); + rofi_theme_get_color ( WIDGET (sb ), "foreground", draw ); cairo_rectangle ( draw, widget_padding_get_left ( wid ), diff --git a/source/widgets/separator.c b/source/widgets/separator.c index aa43b83b..695af704 100644 --- a/source/widgets/separator.c +++ b/source/widgets/separator.c @@ -98,7 +98,7 @@ separator *separator_create ( const char *name, separator_type type, short sw ) // Enabled by default sb->widget.enabled = TRUE; - const char *line_style = rofi_theme_get_string ( sb->widget.name, NULL, "line-style", "solid"); + const char *line_style = rofi_theme_get_string ( WIDGET (sb), "line-style", "solid"); separator_set_line_style_from_string ( sb, line_style ); return sb; } @@ -139,7 +139,7 @@ static void separator_draw ( widget *wid, cairo_t *draw ) return; } color_separator ( draw ); - rofi_theme_get_color ( wid->name, NULL, "foreground", draw ); + rofi_theme_get_color ( wid, "foreground", draw ); if ( sep->line_style == S_LINE_DASH ) { const double dashes[1] = { 4 }; cairo_set_dash ( draw, dashes, 1, 0.0 ); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 37082d4a..a224e297 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -365,7 +365,7 @@ static void texbox_update ( textbox *tb ) //cairo_set_source_rgba ( tb->main_draw, 0,0,0,0.0); //cairo_paint ( tb->main_draw ); - rofi_theme_get_color ( tb->widget.name, tb->widget.state, "foreground", tb->main_draw); + rofi_theme_get_color ( WIDGET ( tb ), "foreground", tb->main_draw); // draw the cursor if ( tb->flags & TB_EDITABLE && tb->blink ) { cairo_rectangle ( tb->main_draw, x + cursor_x, y+cursor_y, cursor_width, cursor_height); diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 13f0c1a7..4a53bb59 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -7,13 +7,13 @@ void widget_init ( widget *widget , const char *name ) { widget->name = g_strdup(name); - widget->padding = (Padding){ {0, PW_PX}, {0, PW_PX}, {0, PW_PX}, {0, PW_PX}}; - widget->padding = rofi_theme_get_padding ( widget->name, NULL, "padding", widget->padding); - widget->border = (Padding){ {0, PW_PX}, {0, PW_PX}, {0, PW_PX}, {0, PW_PX}}; - widget->border = rofi_theme_get_padding ( widget->name, NULL, "border", widget->border); + widget->padding = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; + widget->padding = rofi_theme_get_padding ( widget, "padding", widget->padding); + widget->border = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; + widget->border = rofi_theme_get_padding ( widget, "border", widget->border); - widget->margin = (Padding){ {0, PW_PX}, {0, PW_PX}, {0, PW_PX}, {0, PW_PX}}; - widget->margin = rofi_theme_get_padding ( widget->name, NULL, "margin", widget->margin); + widget->margin = (Padding){ {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}, {0, PW_PX, SOLID}}; + widget->margin = rofi_theme_get_padding ( widget, "margin", widget->margin); } void widget_set_state ( widget *widget, const char *state ) @@ -107,7 +107,7 @@ void widget_draw ( widget *widget, cairo_t *d ) ); cairo_clip ( d ); - rofi_theme_get_color ( widget->name, widget->state, "background", d ); + rofi_theme_get_color ( widget, "background", d ); cairo_paint( d ) ; // Set new x/y possition. @@ -118,27 +118,31 @@ void widget_draw ( widget *widget, cairo_t *d ) int right = distance_get_pixel ( widget->border.right, ORIENTATION_VERTICAL ); int bottom = distance_get_pixel ( widget->border.bottom, ORIENTATION_VERTICAL ); if ( left || top || right || bottom ) { - rofi_theme_get_color ( widget->name, widget->state, "foreground", d ); + rofi_theme_get_color ( widget, "foreground", d ); if ( left > 0 ) { cairo_set_line_width ( d, left ); + distance_get_linestyle ( widget->border.left, d); cairo_move_to ( d, margin_left + left/2.0, margin_top ); cairo_line_to ( d, margin_left + left/2.0, widget->h-margin_bottom); cairo_stroke ( d ); } if ( right > 0 ) { cairo_set_line_width ( d, right ); + distance_get_linestyle ( widget->border.right, d); cairo_move_to ( d, widget->w - margin_right - right/2.0, 0 ); cairo_line_to ( d, widget->w - margin_right - right/2.0, widget->h-margin_bottom ); cairo_stroke ( d ); } if ( top > 0 ) { cairo_set_line_width ( d, top ); + distance_get_linestyle ( widget->border.top, d); cairo_move_to ( d, margin_left,margin_top+ top/2.0 ); cairo_line_to ( d, widget->w-margin_right, margin_top+top/2.0 ); cairo_stroke ( d ); } if ( bottom > 0 ) { cairo_set_line_width ( d, bottom ); + distance_get_linestyle ( widget->border.bottom, d); cairo_move_to ( d, margin_left, widget->h-bottom/2.0-margin_bottom); cairo_line_to ( d, widget->w-margin_right, widget->h-bottom/2.0-margin_bottom); cairo_stroke ( d );