mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-14 11:33:14 +00:00
Fix for regression introduced by 951cb1ac7e
.
This commit is contained in:
parent
4463a100ba
commit
e08ccb7512
22
src/conky.cc
22
src/conky.cc
@ -1526,6 +1526,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
||||
w = current->width;
|
||||
if (w == 0) {
|
||||
w = text_start_x + text_width - cur_x - 1;
|
||||
current->graph_width = w - 1;
|
||||
}
|
||||
if (w < 0) {
|
||||
w = 0;
|
||||
@ -1539,14 +1540,16 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
||||
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
||||
CapButt, JoinMiter);
|
||||
|
||||
if (current->last_colour != 0
|
||||
|| current->first_colour != 0) {
|
||||
tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour);
|
||||
/* in case we don't have a graph yet */
|
||||
if (current->graph) {
|
||||
|
||||
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||
tmpcolour = do_gradient(w - 1,
|
||||
current->last_colour, current->first_colour);
|
||||
}
|
||||
colour_idx = 0;
|
||||
for (i = w - 2; i > -1; i--) {
|
||||
if (current->last_colour != 0
|
||||
|| current->first_colour != 0) {
|
||||
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||
if (current->tempgrad) {
|
||||
#ifdef DEBUG_lol
|
||||
assert(
|
||||
@ -1568,8 +1571,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
||||
}
|
||||
#endif /* DEBUG_lol */
|
||||
set_foreground_color(tmpcolour[
|
||||
(int)((float)(w - 2) - current->graph[j] *
|
||||
(w - 2) / (float)current->scale)
|
||||
(int)((float)(w - 2) -
|
||||
current->graph[j] * (w - 2) /
|
||||
(float)current->scale)
|
||||
]);
|
||||
} else {
|
||||
set_foreground_color(tmpcolour[colour_idx++]);
|
||||
@ -1580,7 +1584,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
||||
cur_x + i + 1, by + h, cur_x + i + 1,
|
||||
round_to_int((double)by + h - current->graph[j] *
|
||||
(h - 1) / current->scale));
|
||||
j++;
|
||||
++j;
|
||||
}
|
||||
if (tmpcolour) free(tmpcolour);
|
||||
}
|
||||
free_and_zero(tmpcolour);
|
||||
if (h > cur_y_add
|
||||
|
@ -381,6 +381,9 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* do nothing if we don't even have a graph yet */
|
||||
if (!graph->graph) return;
|
||||
|
||||
if (showaslog) {
|
||||
#ifdef MATH
|
||||
f = log10(f + 1);
|
||||
@ -392,7 +395,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
|
||||
}
|
||||
|
||||
/* shift all the data by 1 */
|
||||
for (i = graph->width - 1; i > 0; i--) {
|
||||
for (i = graph->graph_allocated - 1; i > 0; i--) {
|
||||
graph->graph[i] = graph->graph[i - 1];
|
||||
}
|
||||
graph->graph[0] = f; /* add new data */
|
||||
@ -421,10 +424,25 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val)
|
||||
s = new_special(buf, GRAPH);
|
||||
|
||||
s->width = g->width;
|
||||
if (s->graph == NULL) {
|
||||
s->graph = (double*)malloc(s->width * sizeof(double));
|
||||
memset(s->graph, 0, s->width * sizeof(double));
|
||||
if (s->width) s->graph_width = s->width;
|
||||
|
||||
if (s->graph_width != s->graph_allocated) {
|
||||
double *graph = static_cast<double *>(realloc(s->graph, s->graph_width * sizeof(double)));
|
||||
DBGP("reallocing graph from %d to %d", s->graph_allocated, s->graph_width);
|
||||
if (!s->graph) {
|
||||
/* initialize */
|
||||
memset(graph, 0, s->graph_width * sizeof(double));
|
||||
s->scale = 100;
|
||||
} else {
|
||||
if (s->graph_width > s->graph_allocated) {
|
||||
/* initialize the new region */
|
||||
memset(graph + (s->graph_allocated * sizeof(double)), 0,
|
||||
(s->graph_width - s->graph_allocated) *
|
||||
sizeof(double));
|
||||
}
|
||||
}
|
||||
s->graph = graph;
|
||||
s->graph_allocated = s->graph_width;
|
||||
}
|
||||
s->height = g->height;
|
||||
s->first_colour = adjust_colours(g->first_colour);
|
||||
|
@ -65,6 +65,8 @@ struct special_t {
|
||||
double *graph;
|
||||
double scale; /* maximum value */
|
||||
short show_scale;
|
||||
int graph_width;
|
||||
int graph_allocated;
|
||||
int scaled; /* auto adjust maximum */
|
||||
unsigned long first_colour; // for graph gradient
|
||||
unsigned long last_colour;
|
||||
|
Loading…
Reference in New Issue
Block a user