mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 10:35:10 +00:00
gradients
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@39 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
2b3b776843
commit
fddc7d1c65
@ -1,3 +1,8 @@
|
|||||||
|
2005-07-01
|
||||||
|
* stabilized code
|
||||||
|
* added gradiest to graphs (very pretty)
|
||||||
|
* things
|
||||||
|
|
||||||
2005-07-30
|
2005-07-30
|
||||||
* finalized graphing code, see $cpugraph, $memgraph, $execgraph,
|
* finalized graphing code, see $cpugraph, $memgraph, $execgraph,
|
||||||
$downspeedgraph, and $upspeedgraph
|
$downspeedgraph, and $upspeedgraph
|
||||||
|
9
README
9
README
@ -158,11 +158,13 @@
|
|||||||
cpu CPU usage in percents
|
cpu CPU usage in percents
|
||||||
cpubar (height) Bar that shows CPU usage, height is
|
cpubar (height) Bar that shows CPU usage, height is
|
||||||
bar's height in pixels
|
bar's height in pixels
|
||||||
cpugraph (height),(width)CPU usage graph
|
cpugraph (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
CPU usage graph
|
||||||
downspeed net Download speed in kilobytes
|
downspeed net Download speed in kilobytes
|
||||||
downspeedf net Download speed in kilobytes with one
|
downspeedf net Download speed in kilobytes with one
|
||||||
decimal
|
decimal
|
||||||
downspeedgraph net (height),(width) Download speed graph
|
downspeedgraph net (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
Download speed graph
|
||||||
exec shell command Executes a shell command and displays
|
exec shell command Executes a shell command and displays
|
||||||
the output in conky. warning: this
|
the output in conky. warning: this
|
||||||
takes a lot more resources than other
|
takes a lot more resources than other
|
||||||
@ -300,7 +302,8 @@
|
|||||||
upspeed net Upload speed in kilobytes
|
upspeed net Upload speed in kilobytes
|
||||||
upspeedf net Upload speed in kilobytes with one
|
upspeedf net Upload speed in kilobytes with one
|
||||||
decimal
|
decimal
|
||||||
upspeedgraph net (height),(width) Upload speed graph
|
upspeedgraph net (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
Upload speed graph
|
||||||
uptime Uptime
|
uptime Uptime
|
||||||
uptime_short Uptime in a shorter format
|
uptime_short Uptime in a shorter format
|
||||||
|
|
||||||
|
156
conky.c
156
conky.c
@ -228,6 +228,8 @@ static struct special_t {
|
|||||||
double graph_scale;
|
double graph_scale;
|
||||||
int graph_width;
|
int graph_width;
|
||||||
int scaled;
|
int scaled;
|
||||||
|
unsigned long first_colour; // for graph gradient
|
||||||
|
unsigned long last_colour;
|
||||||
} specials[128];
|
} specials[128];
|
||||||
|
|
||||||
static int special_count;
|
static int special_count;
|
||||||
@ -325,11 +327,13 @@ inline void graph_append(struct special_t *graph, double f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void new_graph(char *buf, int w, int h, double i, int scaled)
|
static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scaled)
|
||||||
{
|
{
|
||||||
struct special_t *s = new_special(buf, GRAPH);
|
struct special_t *s = new_special(buf, GRAPH);
|
||||||
s->width = w;
|
s->width = w;
|
||||||
s->height = h;
|
s->height = h;
|
||||||
|
s->first_colour = first_colour;
|
||||||
|
s->last_colour = second_colour;
|
||||||
s->scaled = scaled;
|
s->scaled = scaled;
|
||||||
if (s->width) {
|
if (s->width) {
|
||||||
s->graph_width = s->width - 3; // subtract 3 for rectangle around
|
s->graph_width = s->width - 3; // subtract 3 for rectangle around
|
||||||
@ -342,16 +346,27 @@ static void new_graph(char *buf, int w, int h, double i, int scaled)
|
|||||||
graph_append(s, i);
|
graph_append(s, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *scan_graph(const char *args, int *w, int *h)
|
static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour)
|
||||||
{
|
{
|
||||||
*w = 0; /* zero width means all space that is available */
|
*w = 0; /* zero width means all space that is available */
|
||||||
*h = 25;
|
*h = 25;
|
||||||
|
*first_colour = 0;
|
||||||
|
*last_colour = 0;
|
||||||
/* graph's argument is either height or height,width */
|
/* graph's argument is either height or height,width */
|
||||||
if (args) {
|
if (args) {
|
||||||
int n = 0;
|
if (sscanf(args, "%x %x", first_colour, last_colour) < 2) {
|
||||||
if (sscanf(args, "%d,%d %n", h, w, &n) <= 1)
|
if (sscanf(args, "%d,%d", h, w) < 2) {
|
||||||
sscanf(args, "%*s %d %n", h, &n);
|
if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
|
||||||
//args += n;
|
if (sscanf(args, "%*s %d,%d", h, w) < 2) {
|
||||||
|
if (sscanf(args, "%d,%d %x %x", h, w, first_colour, last_colour) < 4) {
|
||||||
|
if (sscanf(args, "%*s %x %x", first_colour, last_colour) < 2) {
|
||||||
|
sscanf(args, "%*s %d,%d %x %x", h, w, first_colour, last_colour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
@ -589,6 +604,7 @@ enum text_object_type {
|
|||||||
struct text_object {
|
struct text_object {
|
||||||
int type;
|
int type;
|
||||||
int a, b;
|
int a, b;
|
||||||
|
unsigned int c, d;
|
||||||
union {
|
union {
|
||||||
char *s; /* some string */
|
char *s; /* some string */
|
||||||
int i; /* some integer */
|
int i; /* some integer */
|
||||||
@ -750,13 +766,13 @@ static void construct_text_object(const char *s, const char *arg)
|
|||||||
END OBJ(cpubar, INFO_CPU)
|
END OBJ(cpubar, INFO_CPU)
|
||||||
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
||||||
END OBJ(cpugraph, INFO_CPU)
|
END OBJ(cpugraph, INFO_CPU)
|
||||||
(void) scan_graph(arg, &obj->data.pair.a, &obj->data.pair.b);
|
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
|
||||||
END OBJ(color, 0) obj->data.l =
|
END OBJ(color, 0) obj->data.l =
|
||||||
arg ? get_x11_color(arg) : default_fg_color;
|
arg ? get_x11_color(arg) : default_fg_color;
|
||||||
END OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
|
END OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
|
||||||
END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
|
END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
|
||||||
END OBJ(downspeedgraph, INFO_NET)
|
END OBJ(downspeedgraph, INFO_NET)
|
||||||
(void) scan_graph(arg, &obj->a, &obj->b);
|
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
|
||||||
char buf[64];
|
char buf[64];
|
||||||
sscanf(arg, "%63s %*i,%*i %*i", buf);
|
sscanf(arg, "%63s %*i,%*i %*i", buf);
|
||||||
obj->data.net = get_net_stat(buf);
|
obj->data.net = get_net_stat(buf);
|
||||||
@ -1074,7 +1090,7 @@ static void construct_text_object(const char *s, const char *arg)
|
|||||||
END OBJ(membar, INFO_MEM)
|
END OBJ(membar, INFO_MEM)
|
||||||
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
|
||||||
END OBJ(membar, INFO_MEM)
|
END OBJ(membar, INFO_MEM)
|
||||||
(void) scan_graph(arg, &obj->data.pair.a, &obj->data.pair.b);
|
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
|
||||||
END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
|
END OBJ(mixer, INFO_MIXER) obj->data.l = mixer_init(arg);
|
||||||
END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
|
END OBJ(mixerl, INFO_MIXER) obj->data.l = mixer_init(arg);
|
||||||
END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
|
END OBJ(mixerr, INFO_MIXER) obj->data.l = mixer_init(arg);
|
||||||
@ -1140,7 +1156,7 @@ static void construct_text_object(const char *s, const char *arg)
|
|||||||
END OBJ(upspeed, INFO_NET) obj->data.net = get_net_stat(arg);
|
END OBJ(upspeed, INFO_NET) obj->data.net = get_net_stat(arg);
|
||||||
END OBJ(upspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
|
END OBJ(upspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
|
||||||
END OBJ(upspeedgraph, INFO_NET)
|
END OBJ(upspeedgraph, INFO_NET)
|
||||||
(void) scan_graph(arg, &obj->a, &obj->b);
|
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d);
|
||||||
char buf[64];
|
char buf[64];
|
||||||
sscanf(arg, "%63s %*i,%*i %*i", buf);
|
sscanf(arg, "%63s %*i,%*i %*i", buf);
|
||||||
obj->data.net = get_net_stat(buf);
|
obj->data.net = get_net_stat(buf);
|
||||||
@ -1396,8 +1412,8 @@ static void generate_text()
|
|||||||
(int) (cur->cpu_usage * 255.0));
|
(int) (cur->cpu_usage * 255.0));
|
||||||
}
|
}
|
||||||
OBJ(cpugraph) {
|
OBJ(cpugraph) {
|
||||||
new_graph(p, obj->data.pair.a,
|
new_graph(p, obj->a,
|
||||||
obj->data.pair.b,
|
obj->b, obj->c, obj->d,
|
||||||
(unsigned int) (cur->cpu_usage *
|
(unsigned int) (cur->cpu_usage *
|
||||||
100), 0);
|
100), 0);
|
||||||
}
|
}
|
||||||
@ -1429,7 +1445,7 @@ static void generate_text()
|
|||||||
OBJ(downspeedgraph) {
|
OBJ(downspeedgraph) {
|
||||||
if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
|
if (obj->data.net->recv_speed == 0) // this is just to make the ugliness at start go away
|
||||||
obj->data.net->recv_speed = 0.01;
|
obj->data.net->recv_speed = 0.01;
|
||||||
new_graph(p, obj->a, obj->b,
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
||||||
(obj->data.net->recv_speed /
|
(obj->data.net->recv_speed /
|
||||||
1024.0), 1);
|
1024.0), 1);
|
||||||
}
|
}
|
||||||
@ -1530,7 +1546,7 @@ static void generate_text()
|
|||||||
ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
|
ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
|
||||||
} else {
|
} else {
|
||||||
new_graph(p, 0,
|
new_graph(p, 0,
|
||||||
25, (int) (barnum), 0);
|
25, obj->c, obj->d, (int) (barnum), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1763,8 +1779,8 @@ static void generate_text()
|
|||||||
}
|
}
|
||||||
|
|
||||||
OBJ(memgraph) {
|
OBJ(memgraph) {
|
||||||
new_graph(p, obj->data.pair.a,
|
new_graph(p, obj->a,
|
||||||
obj->data.pair.b,
|
obj->b, obj->c, obj->d,
|
||||||
cur->memmax ? (cur->mem) /
|
cur->memmax ? (cur->mem) /
|
||||||
(cur->memmax) : 0, 0);
|
(cur->memmax) : 0, 0);
|
||||||
}
|
}
|
||||||
@ -1967,7 +1983,7 @@ static void generate_text()
|
|||||||
OBJ(upspeedgraph) {
|
OBJ(upspeedgraph) {
|
||||||
if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
|
if (obj->data.net->trans_speed == 0) // this is just to make the ugliness at start go away
|
||||||
obj->data.net->trans_speed = 0.01;
|
obj->data.net->trans_speed = 0.01;
|
||||||
new_graph(p, obj->a, obj->b,
|
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
||||||
(obj->data.net->trans_speed /
|
(obj->data.net->trans_speed /
|
||||||
1024.0), 1);
|
1024.0), 1);
|
||||||
}
|
}
|
||||||
@ -2576,6 +2592,82 @@ static void draw_string(const char *s)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long do_gradient(unsigned long first_colour, unsigned long last_colour) { /* this function returns the next colour between two colours for a gradient */
|
||||||
|
int tmp_color = 0;
|
||||||
|
int red1, green1, blue1; // first colour
|
||||||
|
int red2, green2, blue2; // second colour
|
||||||
|
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
||||||
|
red1 = (first_colour & 0xff0000) >> 16;
|
||||||
|
green1 = (first_colour & 0xff00) >> 8;
|
||||||
|
blue1 = first_colour & 0xff;
|
||||||
|
red2 = (last_colour & 0xff0000) >> 16;
|
||||||
|
green2 = (last_colour & 0xff00) >> 8;
|
||||||
|
blue2 = last_colour & 0xff;
|
||||||
|
if (red1 > red2) {
|
||||||
|
red3 = -1;
|
||||||
|
}
|
||||||
|
if (red1 < red2) {
|
||||||
|
red3 = 1;
|
||||||
|
}
|
||||||
|
if (green1 > green2) {
|
||||||
|
green3 = -1;
|
||||||
|
}
|
||||||
|
if (green1 < green2) {
|
||||||
|
green3 = 1;
|
||||||
|
}
|
||||||
|
if (blue1 > blue2) {
|
||||||
|
blue3 = -1;
|
||||||
|
}
|
||||||
|
if (blue1 < blue2) {
|
||||||
|
blue3 = 1;
|
||||||
|
}
|
||||||
|
red1 += red3;
|
||||||
|
green1 += green3;
|
||||||
|
blue1 += blue3;
|
||||||
|
if (red1 < 0) {
|
||||||
|
red1 = 0;
|
||||||
|
}
|
||||||
|
if (green1 < 0) {
|
||||||
|
green1 = 0;
|
||||||
|
}
|
||||||
|
if (blue1 < 0) {
|
||||||
|
blue1 = 0;
|
||||||
|
}
|
||||||
|
if (red1 > 0xff) {
|
||||||
|
red1 = 0xff;
|
||||||
|
}
|
||||||
|
if (green1 > 0xff) {
|
||||||
|
green1 = 0xff;
|
||||||
|
}
|
||||||
|
if (blue1 > 0xff) {
|
||||||
|
blue1 = 0xff;
|
||||||
|
}
|
||||||
|
tmp_color = (red1 << 16) | (green1 << 8) | blue1;
|
||||||
|
return tmp_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long gradient_max(unsigned long first_colour, unsigned long last_colour) { /* this function returns the max diff for a gradient */
|
||||||
|
int red1, green1, blue1; // first colour
|
||||||
|
int red2, green2, blue2; // second colour
|
||||||
|
int red3 = 0, green3 = 0, blue3 = 0; // difference
|
||||||
|
red1 = (first_colour & 0xff0000) >> 16;
|
||||||
|
green1 = (first_colour & 0xff00) >> 8;
|
||||||
|
blue1 = first_colour & 0xff;
|
||||||
|
red2 = (last_colour & 0xff0000) >> 16;
|
||||||
|
green2 = (last_colour & 0xff00) >> 8;
|
||||||
|
blue2 = last_colour & 0xff;
|
||||||
|
red3 = abs(red1 - red2);
|
||||||
|
green3 = abs(green1 - green2);
|
||||||
|
blue3 = abs(blue1 - blue2);
|
||||||
|
int max = red3;
|
||||||
|
if (green3 > max)
|
||||||
|
max = green3;
|
||||||
|
if (blue3 > max)
|
||||||
|
max = blue3;
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void draw_line(char *s)
|
static void draw_line(char *s)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
@ -2718,7 +2810,23 @@ static void draw_line(char *s)
|
|||||||
JoinMiter);
|
JoinMiter);
|
||||||
int i;
|
int i;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
int gradient_size = 0;
|
||||||
|
float gradient_factor = 0;
|
||||||
|
float gradient_update = 0;
|
||||||
|
if (specials[special_index].first_colour != 0 && specials[special_index].last_colour != 0) {
|
||||||
|
current_color = specials[special_index].first_colour;
|
||||||
|
gradient_size = gradient_max(specials[special_index].first_colour, specials[special_index].last_colour);
|
||||||
|
gradient_factor = (float)gradient_size / (w - 3);
|
||||||
|
}
|
||||||
for (i = 0; i < w - 3; i++) {
|
for (i = 0; i < w - 3; i++) {
|
||||||
|
if (specials[special_index].first_colour != 0 && specials[special_index].last_colour != 0) {
|
||||||
|
XSetForeground(display, window.gc, current_color);
|
||||||
|
gradient_update = gradient_factor;
|
||||||
|
while (gradient_update > 0) {
|
||||||
|
current_color = do_gradient(current_color, specials[special_index].last_colour);
|
||||||
|
gradient_update--;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (i /
|
if (i /
|
||||||
((float) (w - 3) /
|
((float) (w - 3) /
|
||||||
(specials
|
(specials
|
||||||
@ -2726,19 +2834,7 @@ static void draw_line(char *s)
|
|||||||
graph_width)) > j) {
|
graph_width)) > j) {
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
XDrawLine(display,
|
XDrawLine(display, window.drawable, window.gc, cur_x + i + 2, by + h, cur_x + i + 2, by + h - specials[special_index].graph[j] * (h - 1) / specials[special_index].graph_scale); /* this is mugfugly, but it works */
|
||||||
window.drawable,
|
|
||||||
window.gc,
|
|
||||||
cur_x + i + 2,
|
|
||||||
by + h,
|
|
||||||
cur_x + i + 2,
|
|
||||||
by + h -
|
|
||||||
specials
|
|
||||||
[special_index].
|
|
||||||
graph[j] * h /
|
|
||||||
specials
|
|
||||||
[special_index]
|
|
||||||
.graph_scale); /* this is mugfugly, but it works */
|
|
||||||
}
|
}
|
||||||
if (specials[special_index].
|
if (specials[special_index].
|
||||||
height > cur_y_add
|
height > cur_y_add
|
||||||
|
@ -143,11 +143,13 @@ metar_station CYBW
|
|||||||
# cpu CPU usage in percents
|
# cpu CPU usage in percents
|
||||||
# cpubar (height) Bar that shows CPU usage, height is
|
# cpubar (height) Bar that shows CPU usage, height is
|
||||||
# bar's height in pixels
|
# bar's height in pixels
|
||||||
# cpugraph (height),(width)CPU usage graph
|
# cpugraph (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
# CPU usage graph
|
||||||
# downspeed net Download speed in kilobytes
|
# downspeed net Download speed in kilobytes
|
||||||
# downspeedf net Download speed in kilobytes with one
|
# downspeedf net Download speed in kilobytes with one
|
||||||
# decimal
|
# decimal
|
||||||
# downspeedgraph net (height),(width) Download speed graph
|
# downspeedgraph net (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
# Download speed graph
|
||||||
# exec shell command Executes a shell command and displays
|
# exec shell command Executes a shell command and displays
|
||||||
# the output in conky. warning: this
|
# the output in conky. warning: this
|
||||||
# takes a lot more resources than other
|
# takes a lot more resources than other
|
||||||
@ -285,7 +287,8 @@ metar_station CYBW
|
|||||||
# upspeed net Upload speed in kilobytes
|
# upspeed net Upload speed in kilobytes
|
||||||
# upspeedf net Upload speed in kilobytes with one
|
# upspeedf net Upload speed in kilobytes with one
|
||||||
# decimal
|
# decimal
|
||||||
# upspeedgraph net (height),(width) Upload speed graph
|
# upspeedgraph net (height),(width) (gradient colour 1) (gradient colour 2)
|
||||||
|
# Upload speed graph
|
||||||
# uptime Uptime
|
# uptime Uptime
|
||||||
# uptime_short Uptime in a shorter format
|
# uptime_short Uptime in a shorter format
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user