1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-16 18:15:17 +00:00

Added fancy new 'temperature gradients' feature.

See docs for more details on 'temperature gradients', which can be
turned on with the -t switch on graphs.  Also improved parsing of
options with $execgraph and $execigraph, but may cause some breakage.
This commit is contained in:
Brenden Matthews 2009-05-24 15:53:32 -06:00
parent ee9364522a
commit 4ec728fa42
7 changed files with 135 additions and 91 deletions

View File

@ -1,3 +1,7 @@
2009-05-24
* Added fancy new 'temperature gradients' feature for graphs, via the -t
switch at the end of graph arguments.
2009-05-19 2009-05-19
* Added inotify support to reload the config when modified automatically * Added inotify support to reload the config when modified automatically
on systems that support it on systems that support it

View File

@ -171,6 +171,7 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>apcupsd_loadgraph</option></command> <command><option>apcupsd_loadgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
</term> </term>
<listitem> <listitem>
History graph of current load. History graph of current load.
@ -589,10 +590,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>cpugraph</option></command> <command><option>cpugraph</option></command>
<option>(cpuN) ("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option> <option>(cpuN) ("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
</term> </term>
<listitem> <listitem>
CPU usage graph, with optional colours in hex, minus the #. See $cpu for more info on SMP. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". CPU usage graph, with optional colours in hex, minus the #. See $cpu for more info on SMP. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -609,10 +610,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>diskiograph</option></command> <command><option>diskiograph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
</term> </term>
<listitem> <listitem>
Disk IO graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Disk IO graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -629,10 +630,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>diskiograph_read</option></command> <command><option>diskiograph_read</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
</term> </term>
<listitem> <listitem>
Disk IO graph for reads, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Disk IO graph for reads, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -649,10 +650,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>diskiograph_write</option></command> <command><option>diskiograph_write</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
</term> </term>
<listitem> <listitem>
Disk IO graph for writes, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Disk IO graph for writes, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -689,10 +690,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>downspeedgraph</option></command> <command><option>downspeedgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (net)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (net)</option>
</term> </term>
<listitem> <listitem>
Download speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Download speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -776,10 +777,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>execgraph</option></command> <command><option>execgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) command</option> <option>("normal"|"log") (-t) command</option>
</term> </term>
<listitem> <listitem>
Same as execbar, but graphs values. Uses a logaritmic scale when the log option is given (to see small numbers). Values still have to be between 0 and 100. The size for graphs can be controlled via the default_graph_size config setting. Same as execbar, but graphs values. Uses a logaritmic scale when the log option is given (to see small numbers). Values still have to be between 0 and 100. The size for graphs can be controlled via the default_graph_size config setting. Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -806,7 +807,7 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>execigraph</option></command> <command><option>execigraph</option></command>
<option>interval command</option> <option>interval ("normal"|"log") (-t) command</option>
</term> </term>
<listitem> <listitem>
Same as execgraph, but takes an interval arg and graphs values. Same as execgraph, but takes an interval arg and graphs values.
@ -1400,10 +1401,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>loadgraph</option></command> <command><option>loadgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
</term> </term>
<listitem> <listitem>
Load1 average graph, similar to xload, with optional colours in hex, minus the #. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Load1 average graph, similar to xload, with optional colours in hex, minus the #. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -1614,10 +1615,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>memgraph</option></command> <command><option>memgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
</term> </term>
<listitem> <listitem>
Memory usage graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Memory usage graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -2394,10 +2395,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>lua_graph</option></command> <command><option>lua_graph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) function_name (function parameters)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) function_name (function parameters)</option>
</term> </term>
<listitem> <listitem>
Executes a Lua function with given parameters and draws a graph. Expects result value to be an integer between 0 and 100. See also 'lua_load' on how to load scripts. Executes a Lua function with given parameters and draws a graph. Expects result value to be an integer between 0 and 100. See also 'lua_load' on how to load scripts. Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>
@ -2585,10 +2586,10 @@
<varlistentry> <varlistentry>
<term> <term>
<command><option>upspeedgraph</option></command> <command><option>upspeedgraph</option></command>
<option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (net)</option> <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (net)</option>
</term> </term>
<listitem> <listitem>
Upload speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Upload speed graph, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal". Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
<para></para></listitem> <para></para></listitem>
</varlistentry> </varlistentry>

View File

@ -88,8 +88,8 @@ unsigned int adjust_colors(unsigned int color)
} }
/* this function returns the next colour between two colours for a gradient */ /* this function returns the next colour between two colours for a gradient */
unsigned long do_gradient(unsigned long first_colour, unsigned long do_gradient(const unsigned long first_colour,
unsigned long last_colour) const unsigned long last_colour)
{ {
int tmp_color = 0; int tmp_color = 0;
int red1, green1, blue1; // first colour int red1, green1, blue1; // first colour

View File

@ -707,22 +707,22 @@ static void free_text_objects(struct text_object *root, int internal)
free(data.local_mail.box); free(data.local_mail.box);
break; break;
case OBJ_imap_unseen: case OBJ_imap_unseen:
if (!obj->global_mode) { if (!obj->char_b) {
free(data.mail); free(data.mail);
} }
break; break;
case OBJ_imap_messages: case OBJ_imap_messages:
if (!obj->global_mode) { if (!obj->char_b) {
free(data.mail); free(data.mail);
} }
break; break;
case OBJ_pop3_unseen: case OBJ_pop3_unseen:
if (!obj->global_mode) { if (!obj->char_b) {
free(data.mail); free(data.mail);
} }
break; break;
case OBJ_pop3_used: case OBJ_pop3_used:
if (!obj->global_mode) { if (!obj->char_b) {
free(data.mail); free(data.mail);
} }
break; break;
@ -1465,11 +1465,11 @@ static struct text_object *construct_text_object(const char *s,
END OBJ(cpugraph, INFO_CPU) END OBJ(cpugraph, INFO_CPU)
SCAN_CPU(arg, obj->data.cpu_index); SCAN_CPU(arg, obj->data.cpu_index);
scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index); DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
END OBJ(loadgraph, INFO_LOADAVG) END OBJ(loadgraph, INFO_LOADAVG)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
if (buf) { if (buf) {
int a = 1, r = 3; int a = 1, r = 3;
if (arg) { if (arg) {
@ -1488,21 +1488,21 @@ static struct text_object *construct_text_object(const char *s,
#ifdef X11 #ifdef X11
END OBJ(diskiograph, INFO_DISKIO) END OBJ(diskiograph, INFO_DISKIO)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf)); obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) if (buf)
free(buf); free(buf);
END OBJ(diskiograph_read, INFO_DISKIO) END OBJ(diskiograph_read, INFO_DISKIO)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf)); obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) if (buf)
free(buf); free(buf);
END OBJ(diskiograph_write, INFO_DISKIO) END OBJ(diskiograph_write, INFO_DISKIO)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
obj->data.diskio = prepare_diskio_stat(dev_name(buf)); obj->data.diskio = prepare_diskio_stat(dev_name(buf));
if (buf) if (buf)
@ -1556,7 +1556,7 @@ static struct text_object *construct_text_object(const char *s,
#ifdef X11 #ifdef X11
END OBJ(downspeedgraph, INFO_NET) END OBJ(downspeedgraph, INFO_NET)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
// default to DEFAULTNETDEV // default to DEFAULTNETDEV
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size); buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
@ -2220,7 +2220,7 @@ static struct text_object *construct_text_object(const char *s,
scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END OBJ(memgraph, INFO_MEM) END OBJ(memgraph, INFO_MEM)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
if (buf) { if (buf) {
free(buf); free(buf);
@ -2372,7 +2372,7 @@ static struct text_object *construct_text_object(const char *s,
#ifdef X11 #ifdef X11
END OBJ(upspeedgraph, INFO_NET) END OBJ(upspeedgraph, INFO_NET)
char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
// default to DEFAULTNETDEV // default to DEFAULTNETDEV
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size); buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
@ -2403,33 +2403,33 @@ static struct text_object *construct_text_object(const char *s,
if (arg) { if (arg) {
// proccss // proccss
obj->data.mail = parse_mail_args(IMAP_TYPE, arg); obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
obj->global_mode = 0; obj->char_b = 0;
} else { } else {
obj->global_mode = 1; obj->char_b = 1;
} }
END OBJ_THREAD(imap_messages, 0) END OBJ_THREAD(imap_messages, 0)
if (arg) { if (arg) {
// proccss // proccss
obj->data.mail = parse_mail_args(IMAP_TYPE, arg); obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
obj->global_mode = 0; obj->char_b = 0;
} else { } else {
obj->global_mode = 1; obj->char_b = 1;
} }
END OBJ_THREAD(pop3_unseen, 0) END OBJ_THREAD(pop3_unseen, 0)
if (arg) { if (arg) {
// proccss // proccss
obj->data.mail = parse_mail_args(POP3_TYPE, arg); obj->data.mail = parse_mail_args(POP3_TYPE, arg);
obj->global_mode = 0; obj->char_b = 0;
} else { } else {
obj->global_mode = 1; obj->char_b = 1;
} }
END OBJ_THREAD(pop3_used, 0) END OBJ_THREAD(pop3_used, 0)
if (arg) { if (arg) {
// proccss // proccss
obj->data.mail = parse_mail_args(POP3_TYPE, arg); obj->data.mail = parse_mail_args(POP3_TYPE, arg);
obj->global_mode = 0; obj->char_b = 0;
} else { } else {
obj->global_mode = 1; obj->char_b = 1;
} }
#ifdef IBM #ifdef IBM
END OBJ(smapi, 0) END OBJ(smapi, 0)
@ -2668,7 +2668,7 @@ static struct text_object *construct_text_object(const char *s,
END OBJ(lua_graph, 0) END OBJ(lua_graph, 0)
if (arg) { if (arg) {
arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->showaslog); &obj->e, &obj->char_a, &obj->char_b);
if (arg) { if (arg) {
obj->data.s = strndup(arg, text_buffer_size); obj->data.s = strndup(arg, text_buffer_size);
} else { } else {
@ -2803,7 +2803,8 @@ static struct text_object *construct_text_object(const char *s,
END OBJ(apcupsd_loadbar, INFO_APCUPSD) END OBJ(apcupsd_loadbar, INFO_APCUPSD)
scan_bar(arg, &obj->a, &obj->b); scan_bar(arg, &obj->a, &obj->b);
END OBJ(apcupsd_loadgraph, INFO_APCUPSD) END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e, &obj->showaslog); char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
&obj->e, &obj->char_a, &obj->char_b);
if (buf) free(buf); if (buf) free(buf);
END OBJ(apcupsd_loadgauge, INFO_APCUPSD) END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
scan_gauge(arg, &obj->a, &obj->b); scan_gauge(arg, &obj->a, &obj->b);
@ -3236,7 +3237,7 @@ int parse_conky_vars(struct text_object *root, char *txt, char *p, struct inform
static inline struct mail_s *ensure_mail_thread(struct text_object *obj, static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
void *thread(void *), const char *text) void *thread(void *), const char *text)
{ {
if (obj->global_mode && info.mail) { if (obj->char_b && info.mail) {
// this means we use info // this means we use info
if (!info.mail->p_timed_thread) { if (!info.mail->p_timed_thread) {
info.mail->p_timed_thread = info.mail->p_timed_thread =
@ -3563,11 +3564,11 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(cpugraph) { OBJ(cpugraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100), round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
100, 1, obj->showaslog); 100, 1, obj->char_a, obj->char_b);
} }
OBJ(loadgraph) { OBJ(loadgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0], new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
obj->e, 1, obj->showaslog); obj->e, 1, obj->char_a, obj->char_b);
} }
OBJ(color) { OBJ(color) {
new_fg(p, obj->data.l); new_fg(p, obj->data.l);
@ -3779,15 +3780,15 @@ static void generate_text_internal(char *p, int p_max_size,
#ifdef X11 #ifdef X11
OBJ(diskiograph) { OBJ(diskiograph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current, obj->e, 1, obj->showaslog); obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
} }
OBJ(diskiograph_read) { OBJ(diskiograph_read) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current_read, obj->e, 1, obj->showaslog); obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
} }
OBJ(diskiograph_write) { OBJ(diskiograph_write) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.diskio->current_write, obj->e, 1, obj->showaslog); obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
} }
#endif #endif
OBJ(downspeed) { OBJ(downspeed) {
@ -3800,7 +3801,7 @@ static void generate_text_internal(char *p, int p_max_size,
#ifdef X11 #ifdef X11
OBJ(downspeedgraph) { OBJ(downspeedgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog); obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
} }
#endif #endif
OBJ(else) { OBJ(else) {
@ -3928,21 +3929,26 @@ static void generate_text_internal(char *p, int p_max_size,
#ifdef X11 #ifdef X11
OBJ(execgraph) { OBJ(execgraph) {
char showaslog = FALSE; char showaslog = FALSE;
char tempgrad = FALSE;
double barnum; double barnum;
char *cmd = obj->data.s;
if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) { if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
showaslog = TRUE; showaslog = TRUE;
read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, text_buffer_size); cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
} else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) { } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, text_buffer_size); cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
} else {
read_exec(obj->data.s, p, text_buffer_size);
} }
if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
tempgrad = TRUE;
cmd += strlen(" "TEMPGRAD);
}
read_exec(cmd, p, text_buffer_size);
barnum = get_barnum(p); barnum = get_barnum(p);
if (barnum >= 0.0) { if (barnum >= 0.0) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum), new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
100, 1, showaslog); 100, 1, showaslog, tempgrad);
} }
} }
OBJ(execibar) { OBJ(execibar) {
@ -3964,8 +3970,23 @@ static void generate_text_internal(char *p, int p_max_size,
if (current_update_time - obj->data.execi.last_update if (current_update_time - obj->data.execi.last_update
>= obj->data.execi.interval) { >= obj->data.execi.interval) {
double barnum; double barnum;
char showaslog = FALSE;
char tempgrad = FALSE;
char *cmd = obj->data.execi.cmd;
read_exec(obj->data.execi.cmd, p, text_buffer_size); if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
showaslog = TRUE;
cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
} else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
}
if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
tempgrad = TRUE;
cmd += strlen(" "TEMPGRAD);
}
obj->char_a = showaslog;
obj->char_b = tempgrad;
read_exec(cmd, p, text_buffer_size);
barnum = get_barnum(p); barnum = get_barnum(p);
if (barnum >= 0.0) { if (barnum >= 0.0) {
@ -3973,7 +3994,7 @@ static void generate_text_internal(char *p, int p_max_size,
} }
obj->data.execi.last_update = current_update_time; obj->data.execi.last_update = current_update_time;
} }
new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE); new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
} }
OBJ(execigauge) { OBJ(execigauge) {
if (current_update_time - obj->data.execi.last_update if (current_update_time - obj->data.execi.last_update
@ -4331,7 +4352,7 @@ static void generate_text_internal(char *p, int p_max_size,
int per; int per;
if (llua_getinteger(obj->data.s, &per)) { if (llua_getinteger(obj->data.s, &per)) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
(per/100.0 * 255), 100, 1, obj->showaslog); (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
} }
} }
OBJ(lua_gauge) { OBJ(lua_gauge) {
@ -4527,7 +4548,7 @@ static void generate_text_internal(char *p, int p_max_size,
OBJ(memgraph) { OBJ(memgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
100, 1, obj->showaslog); 100, 1, obj->char_a, obj->char_b);
} }
#endif #endif
/* mixer stuff */ /* mixer stuff */
@ -4738,7 +4759,7 @@ static void generate_text_internal(char *p, int p_max_size,
#ifdef X11 #ifdef X11
OBJ(upspeedgraph) { OBJ(upspeedgraph) {
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog); obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
} }
#endif #endif
OBJ(uptime_short) { OBJ(uptime_short) {
@ -5428,7 +5449,7 @@ static void generate_text_internal(char *p, int p_max_size,
double progress; double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]); progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
new_graph(p, obj->a, obj->b, obj->c, obj->d, new_graph(p, obj->a, obj->b, obj->c, obj->d,
(int)progress, 100, 1, obj->showaslog); (int)progress, 100, 1, obj->char_a, obj->char_b);
} }
OBJ(apcupsd_loadgauge) { OBJ(apcupsd_loadgauge) {
double progress; double progress;
@ -6041,11 +6062,9 @@ static void draw_line(char *s)
case GRAPH: case GRAPH:
{ {
int h, by, i, j = 0; int h, by, i, j = 0;
int gradient_size = 0; int colour_idx = 0;
float gradient_factor = 0;
float gradient_update = 0;
unsigned long last_colour = current_color; unsigned long last_colour = current_color;
unsigned long tmpcolour = current_color; unsigned long *tmpcolour = 0;
if (cur_x - text_start_x > maximum_width if (cur_x - text_start_x > maximum_width
&& maximum_width > 0) { && maximum_width > 0) {
break; break;
@ -6074,21 +6093,34 @@ static void draw_line(char *s)
if (specials[special_index].last_colour != 0 if (specials[special_index].last_colour != 0
|| specials[special_index].first_colour != 0) { || specials[special_index].first_colour != 0) {
tmpcolour = specials[special_index].last_colour; float gradient_factor, gradient_update = 0;
gradient_size = int gradient_size =
gradient_max(specials[special_index].last_colour, gradient_max(specials[special_index].last_colour,
specials[special_index].first_colour); specials[special_index].first_colour);
gradient_factor = (float) gradient_size / (w - 2); gradient_factor = (float) gradient_size / (w - 1);
tmpcolour = malloc((w - 1) * sizeof(unsigned long));
tmpcolour[0] = specials[special_index].last_colour;
gradient_update += gradient_factor;
for (colour_idx = 1; colour_idx < w - 1; colour_idx++) {
tmpcolour[colour_idx] = tmpcolour[colour_idx - 1];
gradient_update += gradient_factor;
while (gradient_update > 0) {
tmpcolour[colour_idx] = do_gradient(tmpcolour[colour_idx],
specials[special_index].first_colour);
gradient_update--;
}
}
} }
colour_idx = 0;
for (i = w - 2; i > -1; i--) { for (i = w - 2; i > -1; i--) {
if (specials[special_index].last_colour != 0 if (specials[special_index].last_colour != 0
|| specials[special_index].first_colour != 0) { || specials[special_index].first_colour != 0) {
XSetForeground(display, window.gc, tmpcolour); if (specials[special_index].tempgrad) {
gradient_update += gradient_factor; XSetForeground(display, window.gc, tmpcolour[
while (gradient_update > 0) { (int)((float)(w - 1) - specials[special_index].graph[j] *
tmpcolour = do_gradient(tmpcolour, (w - 2) / (float)specials[special_index].graph_scale) - 1]);
specials[special_index].first_colour); } else {
gradient_update--; XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
} }
} }
if ((w - i) / ((float) (w - 2) / if ((w - i) / ((float) (w - 2) /
@ -6102,6 +6134,7 @@ static void draw_line(char *s)
by + h - specials[special_index].graph[j] * by + h - specials[special_index].graph[j] *
(h - 1) / specials[special_index].graph_scale); (h - 1) / specials[special_index].graph_scale);
} }
if (tmpcolour) free(tmpcolour);
if (h > cur_y_add if (h > cur_y_add
&& h > font_h) { && h > font_h) {
cur_y_add = h; cur_y_add = h;

View File

@ -103,7 +103,7 @@ char *scan_font(const char *args)
char *scan_graph(const char *args, int *w, int *h, char *scan_graph(const char *args, int *w, int *h,
unsigned int *first_colour, unsigned int *last_colour, unsigned int *first_colour, unsigned int *last_colour,
unsigned int *scale, char *showaslog) unsigned int *scale, char *showaslog, char *tempgrad)
{ {
const char *nographtype; const char *nographtype;
char buf[64]; char buf[64];
@ -115,24 +115,28 @@ char *scan_graph(const char *args, int *w, int *h,
*first_colour = 0; *first_colour = 0;
*last_colour = 0; *last_colour = 0;
*scale = 0; *scale = 0;
*tempgrad = FALSE;
if (args) { if (args) {
//set showaslog and place the rest of the args in nographtype // set showaslog and place the rest of the args in nographtype
if(strcasecmp(args, LOGGRAPH) == EQUAL) { if (strcasecmp(args, LOGGRAPH) == EQUAL) {
*showaslog = TRUE; *showaslog = TRUE;
return NULL; return NULL;
}else if(strcasecmp(args, NORMGRAPH) == EQUAL) { } else if (strcasecmp(args, NORMGRAPH) == EQUAL) {
*showaslog = FALSE; *showaslog = FALSE;
return NULL; return NULL;
}else if(strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) { } else if (strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
*showaslog = TRUE; *showaslog = TRUE;
nographtype = &args[strlen(LOGGRAPH) + 1]; nographtype = &args[strlen(LOGGRAPH) + 1];
}else if(strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) { } else if (strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
*showaslog = FALSE; *showaslog = FALSE;
nographtype = &args[strlen(NORMGRAPH) + 1]; nographtype = &args[strlen(NORMGRAPH) + 1];
}else{ } else {
*showaslog = FALSE; *showaslog = FALSE;
nographtype = args; nographtype = args;
} }
if (strstr(args, " "TEMPGRAD)) {
*tempgrad = TRUE;
}
DBGP("printing graph as %s, other args are: %s", (*showaslog ? "log" : "normal"), nographtype); DBGP("printing graph as %s, other args are: %s", (*showaslog ? "log" : "normal"), nographtype);
//check the rest of the args //check the rest of the args
if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) { if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) {
@ -292,7 +296,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
} }
void new_graph(char *buf, int w, int h, unsigned int first_colour, void new_graph(char *buf, int w, int h, unsigned int first_colour,
unsigned int second_colour, double i, int scale, int append, char showaslog) unsigned int second_colour, double i, int scale, int append, char showaslog, char tempgrad)
{ {
struct special_t *s = 0; struct special_t *s = 0;
@ -325,6 +329,7 @@ void new_graph(char *buf, int w, int h, unsigned int first_colour,
s->graph_scale = 1; s->graph_scale = 1;
s->show_scale = 1; s->show_scale = 1;
} }
s->tempgrad = tempgrad;
/* if (s->width) { /* if (s->width) {
s->graph_width = s->width - 2; // subtract 2 for rectangle around s->graph_width = s->width - 2; // subtract 2 for rectangle around
} */ } */

View File

@ -35,9 +35,10 @@
* and who needs that kind of precision anyway? */ * and who needs that kind of precision anyway? */
#define MAX_GRAPH_DEPTH 256 #define MAX_GRAPH_DEPTH 256
//don't use spaces in LOGGRAPH or NORMGRAPH if you change them // don't use spaces in LOGGRAPH or NORMGRAPH if you change them
#define LOGGRAPH "log" #define LOGGRAPH "log"
#define NORMGRAPH "normal" #define NORMGRAPH "normal"
#define TEMPGRAD "-t"
enum special_types { enum special_types {
HORIZONTAL_LINE, HORIZONTAL_LINE,
@ -70,6 +71,7 @@ struct special_t {
unsigned long first_colour; // for graph gradient unsigned long first_colour; // for graph gradient
unsigned long last_colour; unsigned long last_colour;
short font_added; short font_added;
char tempgrad;
}; };
/* direct access to the registered specials (FIXME: bad encapsulation) */ /* direct access to the registered specials (FIXME: bad encapsulation) */
@ -94,14 +96,14 @@ const char *scan_gauge(const char *, int *, int *);
const char *scan_bar(const char *, int *, int *); const char *scan_bar(const char *, int *, int *);
char *scan_font(const char *); char *scan_font(const char *);
char *scan_graph(const char *, int *, int *, unsigned int *, char *scan_graph(const char *, int *, int *, unsigned int *,
unsigned int *, unsigned int *, char *); unsigned int *, unsigned int *, char *, char *);
/* printing specials */ /* printing specials */
void new_gauge(char *, int, int, int); void new_gauge(char *, int, int, int);
void new_bar(char *, int, int, int); void new_bar(char *, int, int, int);
void new_font(char *, char *); void new_font(char *, char *);
void new_graph(char *, int, int, unsigned int, void new_graph(char *, int, int, unsigned int,
unsigned int, double, int, int, char); unsigned int, double, int, int, char, char);
void new_hr(char *, int); void new_hr(char *, int);
void new_stippled_hr(char *, int, int); void new_stippled_hr(char *, int, int);
#endif #endif

View File

@ -570,8 +570,7 @@ struct text_object {
long line; long line;
unsigned int c, d, e; unsigned int c, d, e;
float f; float f;
char showaslog; char char_a, char_b;
char global_mode;
}; };
/* text object list helpers */ /* text object list helpers */