diff --git a/common/configopts.c b/common/configopts.c index 92fcce1d1..b64a5ce60 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -152,6 +152,7 @@ cfg_opt_t widget_graph_opts[] = cfg_opt_t widget_progressbar_bar_opts[] = { CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), + CFG_STR((char *) "fg_full", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bordercolor", (char *) NULL, CFGF_NONE), CFG_END() diff --git a/common/draw.c b/common/draw.c index 220b9849d..082883ecd 100644 --- a/common/draw.c +++ b/common/draw.c @@ -151,9 +151,42 @@ draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color) cairo_fill(ctx->cr); } else + { cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1); + cairo_stroke(ctx->cr); + } +} - cairo_stroke(ctx->cr); +/* 'fullwidth' represents a full color-pattern range */ +void +draw_rectangle_gradient(DrawCtx *ctx, Area geometry, int fullwidth, Bool filled, + XColor color, XColor color_full) +{ + cairo_pattern_t *pat; + + cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE); + cairo_set_line_width(ctx->cr, 1.0); + + pat = cairo_pattern_create_linear(geometry.x, geometry.y, geometry.x + fullwidth, geometry.y); + cairo_pattern_add_color_stop_rgb(pat, 0, color.red / 65535.0, + color.green / 65535.0, color.blue / 65535.0); + cairo_pattern_add_color_stop_rgb(pat, 1, color_full.red / 65535.0, + color_full.green / 65535.0, color_full.blue / 65535.0); + + cairo_set_source(ctx->cr, pat); + + if(filled) + { + cairo_rectangle(ctx->cr, geometry.x, geometry.y, geometry.width, geometry.height); + cairo_fill(ctx->cr); + } + else + { + cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1); + cairo_set_source(ctx->cr, pat); + } + + cairo_pattern_destroy(pat); } /* draw_graph functions */ diff --git a/common/draw.h b/common/draw.h index f69735e2c..00afbd7f8 100644 --- a/common/draw.h +++ b/common/draw.h @@ -95,6 +95,7 @@ void draw_context_delete(DrawCtx *); void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg); void draw_rectangle(DrawCtx *, Area, Bool, XColor); +void draw_rectangle_gradient(DrawCtx *, Area, int, Bool, XColor, XColor); void draw_graph_setup(DrawCtx *); void draw_graph(DrawCtx *, int, int, int, int *, int *, int, XColor); diff --git a/widgets/progressbar.c b/widgets/progressbar.c index f4ec1f451..4b98bfbc2 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -42,6 +42,8 @@ typedef struct float height; /** Foreground color */ XColor *fg; + /** Foreground color when bar is full */ + XColor *fg_full; /** Background color */ XColor *bg; /** Border color */ @@ -92,7 +94,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, rectangle.y = margin_top + 1; rectangle.width = pwidth; rectangle.height = pb_height - 2; - draw_rectangle(ctx, rectangle, True, d->fg[i]); + draw_rectangle_gradient(ctx, rectangle, width - 2, True, d->fg[i], d->fg_full[i]); } if(width - 2 - pwidth > 0) /* not filled area */ @@ -152,8 +154,9 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) return w; } - d->bg = p_new(XColor, d->bars); d->fg = p_new(XColor, d->bars); + d->fg_full = p_new(XColor, d->bars); + d->bg = p_new(XColor, d->bars); d->bordercolor = p_new(XColor, d->bars); d->percent = p_new(int, d->bars); @@ -166,6 +169,11 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) else d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG]; + if((color = cfg_getstr(cfg, "fg_full"))) + d->fg_full[i] = draw_color_new(globalconf.display, phys_screen, color); + else + d->fg_full[i] = d->fg[i]; + if((color = cfg_getstr(cfg, "bg"))) d->bg[i] = draw_color_new(globalconf.display, phys_screen, color); else