mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 01:28:30 +00:00
I added Gagues to monitor variables
Signed-off-by: Brenden Matthews <brenden@rty.ca>
This commit is contained in:
parent
e275b05242
commit
98c64d8b3e
86
src/conky.c
86
src/conky.c
@ -699,6 +699,7 @@ static void free_text_objects(struct text_object *root)
|
|||||||
case OBJ_font:
|
case OBJ_font:
|
||||||
case OBJ_image:
|
case OBJ_image:
|
||||||
case OBJ_exec:
|
case OBJ_exec:
|
||||||
|
case OBJ_execgauge:
|
||||||
case OBJ_execbar:
|
case OBJ_execbar:
|
||||||
case OBJ_execgraph:
|
case OBJ_execgraph:
|
||||||
case OBJ_execp:
|
case OBJ_execp:
|
||||||
@ -1283,6 +1284,9 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
} else {
|
} else {
|
||||||
obj->data.cpu_index = 0;
|
obj->data.cpu_index = 0;
|
||||||
}
|
}
|
||||||
|
END OBJ(cpugauge, INFO_CPU)
|
||||||
|
scan_gauge(arg, &obj->a, &obj->b);
|
||||||
|
DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index);
|
||||||
END OBJ(cpubar, INFO_CPU)
|
END OBJ(cpubar, INFO_CPU)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
|
if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
|
||||||
@ -1410,6 +1414,8 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
||||||
END OBJ(execp, 0)
|
END OBJ(execp, 0)
|
||||||
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
||||||
|
END OBJ(execgauge, 0)
|
||||||
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
||||||
END OBJ(execbar, 0)
|
END OBJ(execbar, 0)
|
||||||
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
obj->data.s = strndup(arg ? arg : "", text_buffer_size);
|
||||||
END OBJ(execgraph, 0)
|
END OBJ(execgraph, 0)
|
||||||
@ -2046,6 +2052,8 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
END OBJ(memfree, INFO_MEM)
|
END OBJ(memfree, INFO_MEM)
|
||||||
END OBJ(memmax, INFO_MEM)
|
END OBJ(memmax, INFO_MEM)
|
||||||
END OBJ(memperc, INFO_MEM)
|
END OBJ(memperc, INFO_MEM)
|
||||||
|
END OBJ(memgauge, INFO_MEM)
|
||||||
|
scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
|
||||||
END OBJ(membar, INFO_MEM)
|
END OBJ(membar, INFO_MEM)
|
||||||
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)
|
||||||
@ -2795,10 +2803,9 @@ static int extract_variable_text_internal(struct text_object *retval, const char
|
|||||||
s = p;
|
s = p;
|
||||||
|
|
||||||
var = getenv(buf);
|
var = getenv(buf);
|
||||||
if (var) {
|
|
||||||
strncpy(buf, var, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* if variable wasn't found in environment, use some special */
|
||||||
|
if (!var) {
|
||||||
arg = 0;
|
arg = 0;
|
||||||
|
|
||||||
/* split arg */
|
/* split arg */
|
||||||
@ -2827,7 +2834,7 @@ static int extract_variable_text_internal(struct text_object *retval, const char
|
|||||||
if (obj != NULL) {
|
if (obj != NULL) {
|
||||||
append_object(retval, obj);
|
append_object(retval, obj);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
obj = create_plain_text("$");
|
obj = create_plain_text("$");
|
||||||
@ -3193,6 +3200,9 @@ static void generate_text_internal(char *p, int p_max_size,
|
|||||||
percent_print(p, p_max_size,
|
percent_print(p, p_max_size,
|
||||||
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
|
||||||
}
|
}
|
||||||
|
OBJ(cpugauge)
|
||||||
|
new_gauge(p, obj->a, obj->b,
|
||||||
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
|
||||||
OBJ(cpubar) {
|
OBJ(cpubar) {
|
||||||
new_bar(p, obj->a, obj->b,
|
new_bar(p, obj->a, obj->b,
|
||||||
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
|
round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
|
||||||
@ -3517,6 +3527,17 @@ static void generate_text_internal(char *p, int p_max_size,
|
|||||||
free_text_objects(&subroot);
|
free_text_objects(&subroot);
|
||||||
free(tmp_info);
|
free(tmp_info);
|
||||||
}
|
}
|
||||||
|
OBJ(execgauge) {
|
||||||
|
double barnum;
|
||||||
|
|
||||||
|
read_exec(obj->data.s, p, text_buffer_size);
|
||||||
|
barnum = get_barnum(p); /*using the same function*/
|
||||||
|
|
||||||
|
if (barnum >= 0.0) {
|
||||||
|
barnum /= 100;
|
||||||
|
new_bar(p, 0, 6, round_to_int(barnum * 255.0));
|
||||||
|
}
|
||||||
|
}
|
||||||
OBJ(execbar) {
|
OBJ(execbar) {
|
||||||
double barnum;
|
double barnum;
|
||||||
|
|
||||||
@ -4006,6 +4027,10 @@ static void generate_text_internal(char *p, int p_max_size,
|
|||||||
if (cur->memmax)
|
if (cur->memmax)
|
||||||
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
|
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
|
||||||
}
|
}
|
||||||
|
OBJ(memgauge){
|
||||||
|
new_gauge(p, obj->data.pair.a, obj->data.pair.b,
|
||||||
|
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
||||||
|
}
|
||||||
OBJ(membar) {
|
OBJ(membar) {
|
||||||
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
new_bar(p, obj->data.pair.a, obj->data.pair.b,
|
||||||
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
||||||
@ -5298,6 +5323,59 @@ static void draw_line(char *s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GAUGE: /* new GAUGE */
|
||||||
|
{
|
||||||
|
int h, by = 0;
|
||||||
|
unsigned long last_colour = current_color;
|
||||||
|
float angle, px,py;
|
||||||
|
int usage;
|
||||||
|
|
||||||
|
if (cur_x - text_start_x > maximum_width
|
||||||
|
&& maximum_width > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
h = specials[special_index].height;
|
||||||
|
by = cur_y - (font_ascent() / 2) - 1;
|
||||||
|
|
||||||
|
if (h < font_height()) {
|
||||||
|
by -= h / 2 - 1;
|
||||||
|
}
|
||||||
|
w = specials[special_index].width;
|
||||||
|
if (w == 0) {
|
||||||
|
w = text_start_x + text_width - cur_x - 1;
|
||||||
|
}
|
||||||
|
if (w < 0) {
|
||||||
|
w = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
XSetLineAttributes(display, window.gc, 1, LineSolid,
|
||||||
|
CapButt, JoinMiter);
|
||||||
|
|
||||||
|
XDrawArc(display, window.drawable, window.gc,
|
||||||
|
cur_x, by, w, h*2, 0, 180*64);
|
||||||
|
|
||||||
|
#ifdef MATH
|
||||||
|
usage =specials[special_index].arg;
|
||||||
|
angle = (3.14)*(float)(usage)/255.;
|
||||||
|
px = (float)(cur_x+w/2.)-(float)(w)/2.*0.9*cos(angle);
|
||||||
|
py = (float)(by+h)-(float)(h)*0.9*sin(angle);
|
||||||
|
|
||||||
|
XDrawLine(display, window.drawable, window.gc,
|
||||||
|
cur_x+ w/2, by+h, (int)(px), (int)(py));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (specials[special_index].height > cur_y_add
|
||||||
|
&& specials[special_index].height > font_h) {
|
||||||
|
cur_y_add = specials[special_index].height;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_foreground_color(last_colour);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
case GRAPH:
|
case GRAPH:
|
||||||
{
|
{
|
||||||
int h, by, i, j = 0;
|
int h, by, i, j = 0;
|
||||||
|
@ -43,6 +43,27 @@ unsigned int special_count;
|
|||||||
/*
|
/*
|
||||||
* Scanning arguments to various special text objects
|
* Scanning arguments to various special text objects
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const char *scan_gauge(const char *args, int *w, int *h)
|
||||||
|
{
|
||||||
|
/*width and height*/
|
||||||
|
*w = 25;
|
||||||
|
*h = 25;
|
||||||
|
|
||||||
|
/* gauge's argument is either height or height,width */
|
||||||
|
if (args) {
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
|
||||||
|
sscanf(args, "%d %n", h, &n);
|
||||||
|
*w = *h; /*square gauge*/
|
||||||
|
}
|
||||||
|
args += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
const char *scan_bar(const char *args, int *w, int *h)
|
const char *scan_bar(const char *args, int *w, int *h)
|
||||||
{
|
{
|
||||||
/* zero width means all space that is available */
|
/* zero width means all space that is available */
|
||||||
@ -177,6 +198,15 @@ static struct special_t *new_special(char *buf, enum special_types t)
|
|||||||
return &specials[special_count++];
|
return &specials[special_count++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void new_gauge(char *buf, int w, int h, int usage)
|
||||||
|
{
|
||||||
|
struct special_t *s = new_special(buf, GAUGE);
|
||||||
|
|
||||||
|
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
||||||
|
s->width = w;
|
||||||
|
s->height = h;
|
||||||
|
}
|
||||||
|
|
||||||
void new_bar(char *buf, int w, int h, int usage)
|
void new_bar(char *buf, int w, int h, int usage)
|
||||||
{
|
{
|
||||||
struct special_t *s = new_special(buf, BAR);
|
struct special_t *s = new_special(buf, BAR);
|
||||||
|
@ -48,6 +48,7 @@ enum special_types {
|
|||||||
OUTLINE,
|
OUTLINE,
|
||||||
ALIGNR,
|
ALIGNR,
|
||||||
ALIGNC,
|
ALIGNC,
|
||||||
|
GAUGE,
|
||||||
GRAPH,
|
GRAPH,
|
||||||
OFFSET,
|
OFFSET,
|
||||||
VOFFSET,
|
VOFFSET,
|
||||||
@ -79,12 +80,14 @@ extern unsigned int special_count;
|
|||||||
extern unsigned int max_specials;
|
extern unsigned int max_specials;
|
||||||
|
|
||||||
/* scanning special arguments */
|
/* scanning special arguments */
|
||||||
|
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 *);
|
||||||
|
|
||||||
/* printing specials */
|
/* printing specials */
|
||||||
|
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,
|
||||||
|
@ -76,6 +76,7 @@ enum text_object_type {
|
|||||||
OBJ_conky_build_arch,
|
OBJ_conky_build_arch,
|
||||||
OBJ_font,
|
OBJ_font,
|
||||||
OBJ_cpu,
|
OBJ_cpu,
|
||||||
|
OBJ_cpugauge,
|
||||||
OBJ_cpubar,
|
OBJ_cpubar,
|
||||||
OBJ_cpugraph,
|
OBJ_cpugraph,
|
||||||
OBJ_loadgraph,
|
OBJ_loadgraph,
|
||||||
@ -94,6 +95,7 @@ enum text_object_type {
|
|||||||
OBJ_exec,
|
OBJ_exec,
|
||||||
OBJ_execi,
|
OBJ_execi,
|
||||||
OBJ_texeci,
|
OBJ_texeci,
|
||||||
|
OBJ_execgauge,
|
||||||
OBJ_execbar,
|
OBJ_execbar,
|
||||||
OBJ_execgraph,
|
OBJ_execgraph,
|
||||||
OBJ_execibar,
|
OBJ_execibar,
|
||||||
@ -194,6 +196,7 @@ enum text_object_type {
|
|||||||
OBJ_mem,
|
OBJ_mem,
|
||||||
OBJ_memeasyfree,
|
OBJ_memeasyfree,
|
||||||
OBJ_memfree,
|
OBJ_memfree,
|
||||||
|
OBJ_memgauge,
|
||||||
OBJ_membar,
|
OBJ_membar,
|
||||||
OBJ_memgraph,
|
OBJ_memgraph,
|
||||||
OBJ_memmax,
|
OBJ_memmax,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user