simplify some stuff, cosmetic

This commit is contained in:
Julien Danjou 2008-01-01 16:23:28 +01:00
parent 0945e3ad34
commit bb06e80199
2 changed files with 42 additions and 42 deletions

View File

@ -535,7 +535,7 @@ 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[] = static cfg_opt_t widget_progressbar_bar_opts[] =
{ {
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
@ -544,8 +544,8 @@ config_parse(const char *confpatharg)
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_SEC((char *) "bar", widget_progressbar_bar_opts, CFGF_MULTI),
CFG_INT((char *) "width", 102, CFGF_NONE), CFG_INT((char *) "width", 100, CFGF_NONE),
CFG_INT((char *) "gap", 2, CFGF_NONE), CFG_INT((char *) "gap", 2, CFGF_NONE),
CFG_INT((char *) "lpadding", 3, CFGF_NONE), CFG_INT((char *) "lpadding", 3, CFGF_NONE),
CFG_FLOAT((char *) "height", 0.67, CFGF_NONE), CFG_FLOAT((char *) "height", 0.67, CFGF_NONE),

View File

@ -30,15 +30,24 @@ extern AwesomeConf globalconf;
typedef struct typedef struct
{ {
int *percent; /* 0-100 */ /** Percent 0 to 100 */
int width; /* width of the bars */ int *percent;
int lpadding; /* padding on the left of the bars */ /** Width of the bars */
int gap; /* pixels between bars */ int width;
int bars; /* number of bars */ /** Left padding */
float height; /* height 0-1 (where 1 = height of statusbar */ int lpadding;
/** Pixel between bars */
int gap;
/** Number of bars */
int bars;
/** Height 0-1, where 1 is height of statusbar */
float height;
/** Foreground color */
XColor *fg; XColor *fg;
/** Background color */
XColor *bg; XColor *bg;
XColor *bcolor; /* border color */ /** Border color */
XColor *bcolor;
} Data; } Data;
static int static int
@ -58,9 +67,9 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
width = d->width - d->lpadding; 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); widget->alignment);
left_offset = widget->location + d->lpadding; left_offset = widget->location + d->lpadding;
@ -69,21 +78,21 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0; pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0;
draw_rectangle(ctx, draw_rectangle(ctx,
left_offset, margin_top, left_offset, margin_top,
width, pb_height, width, pb_height,
False, d->bcolor[i]); False, d->bcolor[i]);
if(pwidth > 0) if(pwidth > 0)
draw_rectangle(ctx, draw_rectangle(ctx,
left_offset + 1, margin_top + 1, left_offset + 1, margin_top + 1,
pwidth, pb_height - 2, pwidth, pb_height - 2,
True, d->fg[i]); True, d->fg[i]);
if(width - 2 - pwidth > 0) /* not filled area */ if(width - 2 - pwidth > 0) /* not filled area */
draw_rectangle(ctx, draw_rectangle(ctx,
left_offset + 1 + pwidth, margin_top + 1, left_offset + 1 + pwidth, margin_top + 1,
width - 2 - pwidth, pb_height - 2, width - 2 - pwidth, pb_height - 2,
True, d->bg[i]); True, d->bg[i]);
margin_top += (pb_height + d->gap); margin_top += (pb_height + d->gap);
} }
@ -96,24 +105,17 @@ static void
progressbar_tell(Widget *widget, char *command) progressbar_tell(Widget *widget, char *command)
{ {
Data *d = widget->data; Data *d = widget->data;
int i, percent; int i = 0, percent;
char * tok; char * tok;
if(!command) if(!command || !d->bars)
return; return;
if(!d->bars) for (tok = strtok(command, ", "); tok && i < d->bars; tok = strtok(NULL, ", "), i++)
return;
i = 0;
for (tok = strtok(command, ", "); tok != NULL; tok = strtok(NULL, ", "))
{ {
percent = atoi(tok); percent = atoi(tok);
if(percent <= 100 && percent >= 0) if(percent <= 100 && percent >= 0)
d->percent[i] = percent; d->percent[i] = percent;
if (i > d->bars )
break;
i++;
} }
} }
@ -123,7 +125,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
Widget *w; Widget *w;
Data *d; Data *d;
char *color; char *color;
int i, bars; int i;
cfg_t *cfg; cfg_t *cfg;
@ -134,20 +136,18 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
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");
bars = cfg_size(config, "bar"); if(!(d->bars = cfg_size(config, "bar")))
if (!(bars))
{ {
d->bars = 0;
warn("A progressbar-widget needs a: bar {} in the .awesomerc\n"); warn("A progressbar-widget needs a: bar {} in the .awesomerc\n");
return w; 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);
for(i = 0; i < bars; i++) d->bg = p_new(XColor, d->bars);
d->fg = p_new(XColor, d->bars);
d->bcolor = p_new(XColor, d->bars);
d->percent = p_new(int, d->bars);
for(i = 0; i < d->bars; i++)
{ {
cfg = cfg_getnsec(config, "bar", i); cfg = cfg_getnsec(config, "bar", i);