Use more gperf stuff.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
Pierre Habouzit 2008-06-23 00:30:50 +02:00 committed by Julien Danjou
parent f423719bd6
commit 4d21d0fd98
2 changed files with 110 additions and 72 deletions

View File

@ -1,8 +1,26 @@
bg
border_padding
border_width
bordercolor
bottomleft bottomleft
bottomright bottomright
center center
data
fg
fg_center
fg_end
fg_off
flex flex
gap
height
left left
max_value
min_value
reverse
right right
ticks_count
ticks_gap
topleft topleft
topright topright
vertical
width

View File

@ -20,6 +20,7 @@
* *
*/ */
#include "common/tokenize.h"
#include "widget.h" #include "widget.h"
#include "screen.h" #include "screen.h"
@ -406,21 +407,48 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value)
char *title, *setting; char *title, *setting;
char *new_val; char *new_val;
bar_t *bar; bar_t *bar;
awesome_token_t prop = a_tokenize(property, -1);
if(!new_value) if(!new_value)
return WIDGET_ERROR_NOVALUE; return WIDGET_ERROR_NOVALUE;
switch (prop) {
case A_TK_GAP:
d->gap = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_TICKS_COUNT:
d->ticks_count = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_TICKS_GAP:
d->ticks_gap = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_BORDER_PADDING:
d->border_padding = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_BORDER_WIDTH:
d->border_width = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_WIDTH:
d->width = atoi(new_value);
return WIDGET_NOERROR;
case A_TK_HEIGHT:
d->height = atof(new_value);
return WIDGET_NOERROR;
case A_TK_VERTICAL:
d->vertical = a_strtobool(new_value);
return WIDGET_NOERROR;
/* following properties need a datasection */ /* following properties need a datasection */
else if(!a_strcmp(property, "fg") case A_TK_FG:
|| !a_strcmp(property, "data") case A_TK_DATA:
|| !a_strcmp(property, "fg_off") case A_TK_FG_OFF:
|| !a_strcmp(property, "bg") case A_TK_BG:
|| !a_strcmp(property, "bordercolor") case A_TK_BORDERCOLOR:
|| !a_strcmp(property, "fg_center") case A_TK_FG_CENTER:
|| !a_strcmp(property, "fg_end") case A_TK_FG_END:
|| !a_strcmp(property, "min_value") case A_TK_MIN_VALUE:
|| !a_strcmp(property, "max_value") case A_TK_MAX_VALUE:
|| !a_strcmp(property, "reverse")) case A_TK_REVERSE:
{
/* check if this section is defined already */ /* check if this section is defined already */
new_val = a_strdup(new_value); new_val = a_strdup(new_value);
title = strtok(new_val, " "); title = strtok(new_val, " ");
@ -436,69 +464,61 @@ progressbar_tell(widget_t *widget, const char *property, const char *new_value)
/* no section found -> create one */ /* no section found -> create one */
if(!bar) if(!bar)
bar = progressbar_data_add(d, title); bar = progressbar_data_add(d, title);
break;
/* change values accordingly... */ default:
if(!a_strcmp(property, "data"))
{
value = atof(setting);
bar->value = (value < bar->min_value ? bar->min_value :
(value > bar->max_value ? bar->max_value : value));
}
else if(!a_strcmp(property, "fg"))
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->fg);
else if(!a_strcmp(property, "bg"))
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->bg);
else if(!a_strcmp(property, "fg_off"))
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->fg_off);
else if(!a_strcmp(property, "bordercolor"))
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->bordercolor);
else if(!a_strcmp(property, "fg_center"))
progressbar_pcolor_set(&bar->pfg_center, setting);
else if(!a_strcmp(property, "fg_end"))
progressbar_pcolor_set(&bar->pfg_end, setting);
else if(!a_strcmp(property, "min_value"))
{
bar->min_value = atof(setting);
/* hack to prevent max_value beeing less than min_value
* and also preventing a division by zero when both are equal */
if(bar->max_value <= bar->min_value)
bar->max_value = bar->max_value + 0.0001;
/* force a actual value into the newly possible range */
if(bar->value < bar->min_value)
bar->value = bar->min_value;
}
else if(!a_strcmp(property, "max_value"))
{
bar->max_value = atof(setting);
if(bar->min_value >= bar->max_value)
bar->min_value = bar->max_value - 0.0001;
if(bar->value > bar->max_value)
bar->value = bar->max_value;
}
else if(!a_strcmp(property, "reverse"))
bar->reverse = a_strtobool(setting);
p_delete(&new_val);
return WIDGET_NOERROR;
}
else if(!a_strcmp(property, "gap"))
d->gap = atoi(new_value);
else if(!a_strcmp(property, "ticks_count"))
d->ticks_count = atoi(new_value);
else if(!a_strcmp(property, "ticks_gap"))
d->ticks_gap = atoi(new_value);
else if(!a_strcmp(property, "border_padding"))
d->border_padding = atoi(new_value);
else if(!a_strcmp(property, "border_width"))
d->border_width = atoi(new_value);
else if(!a_strcmp(property, "width"))
d->width = atoi(new_value);
else if(!a_strcmp(property, "height"))
d->height = atof(new_value);
else if(!a_strcmp(property, "vertical"))
d->vertical = a_strtobool(new_value);
else
return WIDGET_ERROR; return WIDGET_ERROR;
}
switch (prop) {
case A_TK_DATA:
value = atof(setting);
bar->value = (value < bar->min_value ? bar->min_value :
(value > bar->max_value ? bar->max_value : value));
break;
case A_TK_FG:
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->fg);
break;
case A_TK_BG:
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->bg);
break;
case A_TK_FG_OFF:
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->fg_off);
break;
case A_TK_BORDERCOLOR:
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &bar->bordercolor);
break;
case A_TK_FG_CENTER:
progressbar_pcolor_set(&bar->pfg_center, setting);
break;
case A_TK_FG_END:
progressbar_pcolor_set(&bar->pfg_end, setting);
break;
case A_TK_MIN_VALUE:
bar->min_value = atof(setting);
/* hack to prevent max_value beeing less than min_value
* and also preventing a division by zero when both are equal */
if(bar->max_value <= bar->min_value)
bar->max_value = bar->max_value + 0.0001;
/* force a actual value into the newly possible range */
if(bar->value < bar->min_value)
bar->value = bar->min_value;
break;
case A_TK_MAX_VALUE:
bar->max_value = atof(setting);
if(bar->min_value >= bar->max_value)
bar->min_value = bar->max_value - 0.0001;
if(bar->value > bar->max_value)
bar->value = bar->max_value;
break;
case A_TK_REVERSE:
bar->reverse = a_strtobool(setting);
break;
default:
return WIDGET_ERROR;
}
p_delete(&new_val);
return WIDGET_NOERROR; return WIDGET_NOERROR;
} }