mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 09:38:38 +00:00
Fix for regression introduced by 951cb1ac7e34347f54dc968e68371d5c334abc5e.
This commit is contained in:
parent
4463a100ba
commit
e08ccb7512
74
src/conky.cc
74
src/conky.cc
@ -1526,6 +1526,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
|||||||
w = current->width;
|
w = current->width;
|
||||||
if (w == 0) {
|
if (w == 0) {
|
||||||
w = text_start_x + text_width - cur_x - 1;
|
w = text_start_x + text_width - cur_x - 1;
|
||||||
|
current->graph_width = w - 1;
|
||||||
}
|
}
|
||||||
if (w < 0) {
|
if (w < 0) {
|
||||||
w = 0;
|
w = 0;
|
||||||
@ -1539,48 +1540,53 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
|
|||||||
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
||||||
CapButt, JoinMiter);
|
CapButt, JoinMiter);
|
||||||
|
|
||||||
if (current->last_colour != 0
|
/* in case we don't have a graph yet */
|
||||||
|| current->first_colour != 0) {
|
if (current->graph) {
|
||||||
tmpcolour = do_gradient(w - 1, current->last_colour, current->first_colour);
|
|
||||||
}
|
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||||
colour_idx = 0;
|
tmpcolour = do_gradient(w - 1,
|
||||||
for (i = w - 2; i > -1; i--) {
|
current->last_colour, current->first_colour);
|
||||||
if (current->last_colour != 0
|
}
|
||||||
|| current->first_colour != 0) {
|
colour_idx = 0;
|
||||||
if (current->tempgrad) {
|
for (i = w - 2; i > -1; i--) {
|
||||||
|
if (current->last_colour != 0 || current->first_colour != 0) {
|
||||||
|
if (current->tempgrad) {
|
||||||
#ifdef DEBUG_lol
|
#ifdef DEBUG_lol
|
||||||
assert(
|
|
||||||
(int)((float)(w - 2) - current->graph[j] *
|
|
||||||
(w - 2) / (float)current->scale)
|
|
||||||
< w - 1
|
|
||||||
);
|
|
||||||
assert(
|
|
||||||
(int)((float)(w - 2) - current->graph[j] *
|
|
||||||
(w - 2) / (float)current->scale)
|
|
||||||
> -1
|
|
||||||
);
|
|
||||||
if (current->graph[j] == current->scale) {
|
|
||||||
assert(
|
assert(
|
||||||
(int)((float)(w - 2) - current->graph[j] *
|
(int)((float)(w - 2) - current->graph[j] *
|
||||||
(w - 2) / (float)current->scale)
|
(w - 2) / (float)current->scale)
|
||||||
== 0
|
< w-1
|
||||||
);
|
);
|
||||||
}
|
assert(
|
||||||
|
(int)((float)(w - 2) - current->graph[j] *
|
||||||
|
(w - 2) / (float)current->scale)
|
||||||
|
> -1
|
||||||
|
);
|
||||||
|
if (current->graph[j] == current->scale) {
|
||||||
|
assert(
|
||||||
|
(int)((float)(w - 2) - current->graph[j] *
|
||||||
|
(w - 2) / (float)current->scale)
|
||||||
|
== 0
|
||||||
|
);
|
||||||
|
}
|
||||||
#endif /* DEBUG_lol */
|
#endif /* DEBUG_lol */
|
||||||
set_foreground_color(tmpcolour[
|
set_foreground_color(tmpcolour[
|
||||||
(int)((float)(w - 2) - current->graph[j] *
|
(int)((float)(w - 2) -
|
||||||
(w - 2) / (float)current->scale)
|
current->graph[j] * (w - 2) /
|
||||||
]);
|
(float)current->scale)
|
||||||
} else {
|
]);
|
||||||
set_foreground_color(tmpcolour[colour_idx++]);
|
} else {
|
||||||
|
set_foreground_color(tmpcolour[colour_idx++]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* this is mugfugly, but it works */
|
||||||
|
XDrawLine(display, window.drawable, window.gc,
|
||||||
|
cur_x + i + 1, by + h, cur_x + i + 1,
|
||||||
|
round_to_int((double)by + h - current->graph[j] *
|
||||||
|
(h - 1) / current->scale));
|
||||||
|
++j;
|
||||||
}
|
}
|
||||||
/* this is mugfugly, but it works */
|
if (tmpcolour) free(tmpcolour);
|
||||||
XDrawLine(display, window.drawable, window.gc,
|
|
||||||
cur_x + i + 1, by + h, cur_x + i + 1,
|
|
||||||
round_to_int((double)by + h - current->graph[j] *
|
|
||||||
(h - 1) / current->scale));
|
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
free_and_zero(tmpcolour);
|
free_and_zero(tmpcolour);
|
||||||
if (h > cur_y_add
|
if (h > cur_y_add
|
||||||
|
@ -381,6 +381,9 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
/* do nothing if we don't even have a graph yet */
|
||||||
|
if (!graph->graph) return;
|
||||||
|
|
||||||
if (showaslog) {
|
if (showaslog) {
|
||||||
#ifdef MATH
|
#ifdef MATH
|
||||||
f = log10(f + 1);
|
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 */
|
/* 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[i] = graph->graph[i - 1];
|
||||||
}
|
}
|
||||||
graph->graph[0] = f; /* add new data */
|
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 = new_special(buf, GRAPH);
|
||||||
|
|
||||||
s->width = g->width;
|
s->width = g->width;
|
||||||
if (s->graph == NULL) {
|
if (s->width) s->graph_width = s->width;
|
||||||
s->graph = (double*)malloc(s->width * sizeof(double));
|
|
||||||
memset(s->graph, 0, s->width * sizeof(double));
|
if (s->graph_width != s->graph_allocated) {
|
||||||
s->scale = 100;
|
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->height = g->height;
|
||||||
s->first_colour = adjust_colours(g->first_colour);
|
s->first_colour = adjust_colours(g->first_colour);
|
||||||
|
@ -65,6 +65,8 @@ struct special_t {
|
|||||||
double *graph;
|
double *graph;
|
||||||
double scale; /* maximum value */
|
double scale; /* maximum value */
|
||||||
short show_scale;
|
short show_scale;
|
||||||
|
int graph_width;
|
||||||
|
int graph_allocated;
|
||||||
int scaled; /* auto adjust maximum */
|
int scaled; /* auto adjust maximum */
|
||||||
unsigned long first_colour; // for graph gradient
|
unsigned long first_colour; // for graph gradient
|
||||||
unsigned long last_colour;
|
unsigned long last_colour;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user