And more gperf.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
Pierre Habouzit 2008-06-23 00:38:31 +02:00 committed by Julien Danjou
parent 4d21d0fd98
commit 8d7f45d76a
2 changed files with 146 additions and 134 deletions

View File

@ -2,25 +2,32 @@ bg
border_padding border_padding
border_width border_width
bordercolor bordercolor
bottom
bottomleft bottomleft
bottomright bottomright
center center
data data
draw_style
fg fg
fg_center fg_center
fg_end fg_end
fg_off fg_off
flex flex
gap gap
grow
height height
left left
line
max_value max_value
min_value min_value
reverse reverse
right right
scale
ticks_count ticks_count
ticks_gap ticks_gap
top
topleft topleft
topright topright
vertical vertical
vertical_gradient
width width

View File

@ -24,6 +24,7 @@
#include "widget.h" #include "widget.h"
#include "screen.h" #include "screen.h"
#include "common/tokenize.h"
#include "common/draw.h" #include "common/draw.h"
extern awesome_t globalconf; extern awesome_t globalconf;
@ -281,19 +282,64 @@ graph_tell(widget_t *widget, const char *property, const char *new_value)
float value; float value;
char *title, *setting; char *title, *setting;
char *new_val; char *new_val;
awesome_token_t prop = a_tokenize(property, -1);
if(!new_value) if(!new_value)
return WIDGET_ERROR_NOVALUE; return WIDGET_ERROR_NOVALUE;
/* following properties need a datasection */
else if(!a_strcmp(property, "data") switch (prop) {
|| !a_strcmp(property, "fg") default:
|| !a_strcmp(property, "fg_center") return WIDGET_ERROR;
|| !a_strcmp(property, "fg_end")
|| !a_strcmp(property, "vertical_gradient") case A_TK_HEIGHT:
|| !a_strcmp(property, "scale") d->height = atof(new_value);
|| !a_strcmp(property, "max_value") return WIDGET_NOERROR;
|| !a_strcmp(property, "draw_style")) case A_TK_WIDTH:
d->width = atoi(new_value);
d->size = d->width - 2;
/* re-allocate/initialise necessary values */
for(graph = d->graphs; graph; graph = graph->next)
{ {
p_realloc(&graph->values, d->size);
p_realloc(&graph->lines, d->size);
p_clear(graph->values, d->size);
p_clear(graph->lines, d->size);
graph->index = 0;
graph->current_max = 0;
graph->max_index = 0;
}
return WIDGET_NOERROR;
case A_TK_BG:
if(!xcolor_new(globalconf.connection,
globalconf.default_screen,
new_value, &d->bg))
return WIDGET_ERROR_FORMAT_COLOR;
return WIDGET_NOERROR;
case A_TK_BORDERCOLOR:
if(!xcolor_new(globalconf.connection,
globalconf.default_screen,
new_value, &d->bordercolor))
return WIDGET_ERROR_FORMAT_COLOR;
return WIDGET_NOERROR;
case A_TK_GROW:
switch((d->grow = position_get_from_str(new_value)))
{
case Left:
case Right:
return WIDGET_NOERROR;
default:
warn("error changing property %s of widget %s, must be 'left' or 'right'",
property, widget->name);
return WIDGET_ERROR_CUSTOM;
}
case A_TK_DATA:
case A_TK_FG:
case A_TK_FG_CENTER:
case A_TK_FG_END:
case A_TK_VERTICAL_GRADIENT:
case A_TK_SCALE:
case A_TK_MAX_VALUE:
case A_TK_DRAW_STYLE:
/* 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, " ");
@ -308,10 +354,11 @@ graph_tell(widget_t *widget, const char *property, const char *new_value)
/* no section found -> create one */ /* no section found -> create one */
if(!graph) if(!graph)
graph = graph_data_add(d, title); graph = graph_data_add(d, title);
break;
}
/* change values accordingly... */ switch (prop) {
if(!a_strcmp(property, "data")) case A_TK_DATA:
{
/* assign incoming value */ /* assign incoming value */
value = MAX(atof(setting), 0); value = MAX(atof(setting), 0);
@ -356,89 +403,47 @@ graph_tell(widget_t *widget, const char *property, const char *new_value)
else else
graph->lines[graph->index] = d->box_height; graph->lines[graph->index] = d->box_height;
} }
p_delete(&new_val); break;
return WIDGET_NOERROR; case A_TK_FG:
}
else if(!a_strcmp(property, "fg"))
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &graph->color_start); xcolor_new(globalconf.connection, globalconf.default_screen, setting, &graph->color_start);
else if(!a_strcmp(property, "fg_center")) break;
case A_TK_FG_CENTER:
graph_pcolor_set(&graph->pcolor_center, setting); graph_pcolor_set(&graph->pcolor_center, setting);
else if(!a_strcmp(property, "fg_end")) break;
case A_TK_FG_END:
graph_pcolor_set(&graph->pcolor_end, setting); graph_pcolor_set(&graph->pcolor_end, setting);
else if(!a_strcmp(property, "vertical_gradient")) break;
case A_TK_VERTICAL_GRADIENT:
graph->vertical_gradient = a_strtobool(setting); graph->vertical_gradient = a_strtobool(setting);
else if(!a_strcmp(property, "scale")) break;
case A_TK_SCALE:
graph->scale = a_strtobool(setting); graph->scale = a_strtobool(setting);
else if(!a_strcmp(property, "max_value")) break;
{ case A_TK_MAX_VALUE:
graph->max_value = atof(setting); graph->max_value = atof(setting);
graph->current_max = graph->max_value; graph->current_max = graph->max_value;
} break;
else if(!a_strcmp(property, "draw_style")) case A_TK_DRAW_STYLE:
{ switch (a_tokenize(setting, -1)) {
if(!a_strcmp(setting, "bottom")) case A_TK_BOTTOM:
graph->draw_style = Bottom_Style; graph->draw_style = Bottom_Style;
else if(!a_strcmp(setting, "line")) break;
case A_TK_LINE:
graph->draw_style = Line_Style; graph->draw_style = Line_Style;
else if(!a_strcmp(setting, "top")) break;
case A_TK_TOP:
graph->draw_style = Top_Style; graph->draw_style = Top_Style;
else
{
warn("'error changing property %s of widget %s, must be 'bottom', 'top' or 'line'",
property, widget->name);
p_delete(&new_val);
return WIDGET_ERROR_CUSTOM;
}
}
p_delete(&new_val);
return WIDGET_NOERROR;
}
else if(!a_strcmp(property, "height"))
d->height = atof(new_value);
else if(!a_strcmp(property, "width"))
{
d->width = atoi(new_value);
d->size = d->width - 2;
/* re-allocate/initialise necessary values */
for(graph = d->graphs; graph; graph = graph->next)
{
p_realloc(&graph->values, d->size);
p_realloc(&graph->lines, d->size);
p_clear(graph->values, d->size);
p_clear(graph->lines, d->size);
graph->index = 0;
graph->current_max = 0;
graph->max_index = 0;
}
}
else if(!a_strcmp(property, "bg"))
{
if(!xcolor_new(globalconf.connection,
globalconf.default_screen,
new_value, &d->bg))
return WIDGET_ERROR_FORMAT_COLOR;
}
else if(!a_strcmp(property, "bordercolor"))
{
if(!xcolor_new(globalconf.connection,
globalconf.default_screen,
new_value, &d->bordercolor))
return WIDGET_ERROR_FORMAT_COLOR;
}
else if(!a_strcmp(property, "grow"))
switch((d->grow = position_get_from_str(new_value)))
{
case Left:
case Right:
break; break;
default: default:
warn("error changing property %s of widget %s, must be 'left' or 'right'", warn("'error changing property %s of widget %s, must be 'bottom', 'top' or 'line'",
property, widget->name); property, widget->name);
return WIDGET_ERROR_CUSTOM; break;
} }
else break;
return WIDGET_ERROR; default:
break;
}
p_delete(&new_val);
return WIDGET_NOERROR; return WIDGET_NOERROR;
} }