And more gperf.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
parent
4d21d0fd98
commit
8d7f45d76a
|
@ -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
|
||||||
|
|
273
widgets/graph.c
273
widgets/graph.c
|
@ -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,137 +354,96 @@ 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... */
|
|
||||||
if(!a_strcmp(property, "data"))
|
|
||||||
{
|
|
||||||
/* assign incoming value */
|
|
||||||
value = MAX(atof(setting), 0);
|
|
||||||
|
|
||||||
if(++graph->index >= d->size) /* cycle inside the array */
|
|
||||||
graph->index = 0;
|
|
||||||
|
|
||||||
if(graph->scale) /* scale option is true */
|
|
||||||
{
|
|
||||||
graph->values[graph->index] = value;
|
|
||||||
|
|
||||||
if(value > graph->current_max) /* a new maximum value found */
|
|
||||||
{
|
|
||||||
graph->max_index = graph->index;
|
|
||||||
graph->current_max = value;
|
|
||||||
|
|
||||||
/* recalculate */
|
|
||||||
for (i = 0; i < d->size; i++)
|
|
||||||
graph->lines[i] = round(graph->values[i] * d->box_height / graph->current_max);
|
|
||||||
}
|
|
||||||
/* old max_index reached + current_max > normal, re-check/generate */
|
|
||||||
else if(graph->max_index == graph->index
|
|
||||||
&& graph->current_max > graph->max_value)
|
|
||||||
{
|
|
||||||
/* find the new max */
|
|
||||||
for(i = 0; i < d->size; i++)
|
|
||||||
if(graph->values[i] > graph->values[graph->max_index])
|
|
||||||
graph->max_index = i;
|
|
||||||
|
|
||||||
graph->current_max = MAX(graph->values[graph->max_index], graph->max_value);
|
|
||||||
|
|
||||||
/* recalculate */
|
|
||||||
for(i = 0; i < d->size; i++)
|
|
||||||
graph->lines[i] = round(graph->values[i] * d->box_height / graph->current_max);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
graph->lines[graph->index] = round(value * d->box_height / graph->current_max);
|
|
||||||
}
|
|
||||||
else /* scale option is false - limit to d->box_height */
|
|
||||||
{
|
|
||||||
if(value < graph->max_value)
|
|
||||||
graph->lines[graph->index] = round(value * d->box_height / graph->max_value);
|
|
||||||
else
|
|
||||||
graph->lines[graph->index] = d->box_height;
|
|
||||||
}
|
|
||||||
p_delete(&new_val);
|
|
||||||
return WIDGET_NOERROR;
|
|
||||||
}
|
|
||||||
else if(!a_strcmp(property, "fg"))
|
|
||||||
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &graph->color_start);
|
|
||||||
else if(!a_strcmp(property, "fg_center"))
|
|
||||||
graph_pcolor_set(&graph->pcolor_center, setting);
|
|
||||||
else if(!a_strcmp(property, "fg_end"))
|
|
||||||
graph_pcolor_set(&graph->pcolor_end, setting);
|
|
||||||
else if(!a_strcmp(property, "vertical_gradient"))
|
|
||||||
graph->vertical_gradient = a_strtobool(setting);
|
|
||||||
else if(!a_strcmp(property, "scale"))
|
|
||||||
graph->scale = a_strtobool(setting);
|
|
||||||
else if(!a_strcmp(property, "max_value"))
|
|
||||||
{
|
|
||||||
graph->max_value = atof(setting);
|
|
||||||
graph->current_max = graph->max_value;
|
|
||||||
}
|
|
||||||
else if(!a_strcmp(property, "draw_style"))
|
|
||||||
{
|
|
||||||
if(!a_strcmp(setting, "bottom"))
|
|
||||||
graph->draw_style = Bottom_Style;
|
|
||||||
else if(!a_strcmp(setting, "line"))
|
|
||||||
graph->draw_style = Line_Style;
|
|
||||||
else if(!a_strcmp(setting, "top"))
|
|
||||||
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);
|
switch (prop) {
|
||||||
else if(!a_strcmp(property, "width"))
|
case A_TK_DATA:
|
||||||
{
|
/* assign incoming value */
|
||||||
d->width = atoi(new_value);
|
value = MAX(atof(setting), 0);
|
||||||
d->size = d->width - 2;
|
|
||||||
/* re-allocate/initialise necessary values */
|
if(++graph->index >= d->size) /* cycle inside the array */
|
||||||
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->index = 0;
|
||||||
graph->current_max = 0;
|
|
||||||
graph->max_index = 0;
|
if(graph->scale) /* scale option is true */
|
||||||
}
|
|
||||||
}
|
|
||||||
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:
|
graph->values[graph->index] = value;
|
||||||
case Right:
|
|
||||||
|
if(value > graph->current_max) /* a new maximum value found */
|
||||||
|
{
|
||||||
|
graph->max_index = graph->index;
|
||||||
|
graph->current_max = value;
|
||||||
|
|
||||||
|
/* recalculate */
|
||||||
|
for (i = 0; i < d->size; i++)
|
||||||
|
graph->lines[i] = round(graph->values[i] * d->box_height / graph->current_max);
|
||||||
|
}
|
||||||
|
/* old max_index reached + current_max > normal, re-check/generate */
|
||||||
|
else if(graph->max_index == graph->index
|
||||||
|
&& graph->current_max > graph->max_value)
|
||||||
|
{
|
||||||
|
/* find the new max */
|
||||||
|
for(i = 0; i < d->size; i++)
|
||||||
|
if(graph->values[i] > graph->values[graph->max_index])
|
||||||
|
graph->max_index = i;
|
||||||
|
|
||||||
|
graph->current_max = MAX(graph->values[graph->max_index], graph->max_value);
|
||||||
|
|
||||||
|
/* recalculate */
|
||||||
|
for(i = 0; i < d->size; i++)
|
||||||
|
graph->lines[i] = round(graph->values[i] * d->box_height / graph->current_max);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
graph->lines[graph->index] = round(value * d->box_height / graph->current_max);
|
||||||
|
}
|
||||||
|
else /* scale option is false - limit to d->box_height */
|
||||||
|
{
|
||||||
|
if(value < graph->max_value)
|
||||||
|
graph->lines[graph->index] = round(value * d->box_height / graph->max_value);
|
||||||
|
else
|
||||||
|
graph->lines[graph->index] = d->box_height;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case A_TK_FG:
|
||||||
|
xcolor_new(globalconf.connection, globalconf.default_screen, setting, &graph->color_start);
|
||||||
|
break;
|
||||||
|
case A_TK_FG_CENTER:
|
||||||
|
graph_pcolor_set(&graph->pcolor_center, setting);
|
||||||
|
break;
|
||||||
|
case A_TK_FG_END:
|
||||||
|
graph_pcolor_set(&graph->pcolor_end, setting);
|
||||||
|
break;
|
||||||
|
case A_TK_VERTICAL_GRADIENT:
|
||||||
|
graph->vertical_gradient = a_strtobool(setting);
|
||||||
|
break;
|
||||||
|
case A_TK_SCALE:
|
||||||
|
graph->scale = a_strtobool(setting);
|
||||||
|
break;
|
||||||
|
case A_TK_MAX_VALUE:
|
||||||
|
graph->max_value = atof(setting);
|
||||||
|
graph->current_max = graph->max_value;
|
||||||
|
break;
|
||||||
|
case A_TK_DRAW_STYLE:
|
||||||
|
switch (a_tokenize(setting, -1)) {
|
||||||
|
case A_TK_BOTTOM:
|
||||||
|
graph->draw_style = Bottom_Style;
|
||||||
|
break;
|
||||||
|
case A_TK_LINE:
|
||||||
|
graph->draw_style = Line_Style;
|
||||||
|
break;
|
||||||
|
case A_TK_TOP:
|
||||||
|
graph->draw_style = Top_Style;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue