additonal settings for the progressbar

This commit is contained in:
marco candrian 2008-01-01 15:33:30 +01:00 committed by Julien Danjou
parent 9adfc6eb35
commit 0945e3ad34
2 changed files with 108 additions and 42 deletions

View File

@ -535,12 +535,20 @@ config_parse(const char *confpatharg)
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t bar_opts[] =
{
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bcolor", (char *) NULL, CFGF_NONE),
};
static cfg_opt_t widget_progressbar_opts[] = static cfg_opt_t widget_progressbar_opts[] =
{ {
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_SEC((char *) "bar", bar_opts, CFGF_MULTI),
CFG_INT((char *) "width", 102, CFGF_NONE), CFG_INT((char *) "width", 102, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_INT((char *) "gap", 2, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_INT((char *) "lpadding", 3, CFGF_NONE),
CFG_FLOAT((char *) "height", 0.67, CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t statusbar_opts[] = static cfg_opt_t statusbar_opts[] =

View File

@ -20,6 +20,7 @@
*/ */
#include <confuse.h> #include <confuse.h>
#include <string.h>
#include "util.h" #include "util.h"
#include "draw.h" #include "draw.h"
#include "widget.h" #include "widget.h"
@ -29,47 +30,63 @@ extern AwesomeConf globalconf;
typedef struct typedef struct
{ {
int percent; int *percent; /* 0-100 */
int width; int width; /* width of the bars */
XColor fg; int lpadding; /* padding on the left of the bars */
XColor bg; int gap; /* pixels between bars */
int bars; /* number of bars */
float height; /* height 0-1 (where 1 = height of statusbar */
XColor *fg;
XColor *bg;
XColor *bcolor; /* border color */
} Data; } Data;
static int static int
progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
int width, pwidth, margin, height; int i, width, pwidth, margin_top, pb_height, left_offset;
Data *d = widget->data; Data *d = widget->data;
height = widget->statusbar->height / 2; if (!(d->bars))
margin = (widget->statusbar->height - height) / 2 - 1; return 0;
width = d->width - (margin * 2); margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5;
pb_height = (int) (widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5;
width = d->width - d->lpadding;
widget->location = widget_calculate_offset(widget->statusbar->width, widget->location = widget_calculate_offset(widget->statusbar->width,
d->width, d->width,
offset, offset,
widget->alignment) + margin; widget->alignment);
pwidth = d->percent ? (width * d->percent) / 100 : 0; left_offset = widget->location + d->lpadding;
draw_rectangle(ctx, for (i = 0; i < d->bars; i++)
widget->location + 1, margin, {
width, height, pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0;
False, d->fg);
if(pwidth > 0)
draw_rectangle(ctx, draw_rectangle(ctx,
widget->location + 1, margin + 1, left_offset, margin_top,
pwidth, height - 2, width, pb_height,
True, d->fg); False, d->bcolor[i]);
if(width - pwidth - 2 > 0) if(pwidth > 0)
draw_rectangle(ctx, draw_rectangle(ctx,
widget->location + pwidth + 2, margin + 1, left_offset + 1, margin_top + 1,
width - pwidth - 2, height - 2, pwidth, pb_height - 2,
True, d->bg); True, d->fg[i]);
if(width - 2 - pwidth > 0) /* not filled area */
draw_rectangle(ctx,
left_offset + 1 + pwidth, margin_top + 1,
width - 2 - pwidth, pb_height - 2,
True, d->bg[i]);
margin_top += (pb_height + d->gap);
}
widget->width = d->width; widget->width = d->width;
return widget->width; return widget->width;
@ -79,15 +96,25 @@ static void
progressbar_tell(Widget *widget, char *command) progressbar_tell(Widget *widget, char *command)
{ {
Data *d = widget->data; Data *d = widget->data;
int percent; int i, percent;
char * tok;
if(!command) if(!command)
return; return;
percent = atoi(command); if(!d->bars)
return;
if(percent <= 100 && percent >= 0) i = 0;
d->percent = percent; for (tok = strtok(command, ", "); tok != NULL; tok = strtok(NULL, ", "))
{
percent = atoi(tok);
if(percent <= 100 && percent >= 0)
d->percent[i] = percent;
if (i > d->bars )
break;
i++;
}
} }
Widget * Widget *
@ -96,6 +123,9 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
Widget *w; Widget *w;
Data *d; Data *d;
char *color; char *color;
int i, bars;
cfg_t *cfg;
w = p_new(Widget, 1); w = p_new(Widget, 1);
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
@ -103,17 +133,45 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
w->tell = progressbar_tell; w->tell = progressbar_tell;
d = w->data = p_new(Data, 1); d = w->data = p_new(Data, 1);
d->width = cfg_getint(config, "width"); d->width = cfg_getint(config, "width");
d->percent = 0;
if((color = cfg_getstr(config, "fg"))) bars = cfg_size(config, "bar");
d->fg = initxcolor(statusbar->screen, color); if (!(bars))
else {
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->bars = 0;
warn("A progressbar-widget needs a: bar {} in the .awesomerc\n");
return w;
}
d->bars = bars;
d->bg = p_new(XColor, bars);
d->fg = p_new(XColor, bars);
d->bcolor = p_new(XColor, bars);
d->percent = p_new(int, bars);
if((color = cfg_getstr(config, "bg"))) for(i = 0; i < bars; i++)
d->bg = initxcolor(statusbar->screen, color); {
else cfg = cfg_getnsec(config, "bar", i);
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((color = cfg_getstr(cfg, "fg")))
d->fg[i] = initxcolor(statusbar->screen, color);
else
d->fg[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if((color = cfg_getstr(cfg, "bg")))
d->bg[i] = initxcolor(statusbar->screen, color);
else
d->bg[i] = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((color = cfg_getstr(cfg, "bcolor")))
d->bcolor[i] = initxcolor(statusbar->screen, color);
else
d->bcolor[i] = globalconf.screens[statusbar->screen].colors_normal[ColFG];
}
d->height = cfg_getfloat(config, "height");
d->gap = cfg_getint(config, "gap");
d->lpadding = cfg_getint(config, "lpadding");
return w; return w;
} }