From d2f3ae7e15840d41c82a83fb2bbe4646ccc176b3 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 23 Nov 2009 23:15:34 +0100 Subject: [PATCH] convert mem{gauge,graph,bar} to callbacks --- src/common.c | 9 ++++++++- src/common.h | 1 + src/conky.c | 11 ----------- src/core.c | 3 +++ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/common.c b/src/common.c index a6dbfaf5..204d1c7a 100644 --- a/src/common.c +++ b/src/common.c @@ -475,5 +475,12 @@ void print_loadgraph(struct text_object *obj, char *p, int p_max_size) uint8_t cpu_barval(struct text_object *obj) { - return (uint8_t)(info.cpu_usage[obj->data.i] * 255.0); + return round_to_int(info.cpu_usage[obj->data.i] * 255.0); +} + +uint8_t mem_barval(struct text_object *obj) +{ + (void)obj; + + return round_to_int(info.memmax ? (info.mem * 255 / info.memmax) : 0); } diff --git a/src/common.h b/src/common.h index c8a36759..f8a2709b 100644 --- a/src/common.h +++ b/src/common.h @@ -76,5 +76,6 @@ void print_loadgraph(struct text_object *, char *, int); #endif /* X11 */ uint8_t cpu_barval(struct text_object *); +uint8_t mem_barval(struct text_object *); #endif /* _COMMON_H */ diff --git a/src/conky.c b/src/conky.c index 58162091..ad29b834 100644 --- a/src/conky.c +++ b/src/conky.c @@ -997,17 +997,6 @@ void generate_text_internal(char *p, int p_max_size, if (cur->memmax) percent_print(p, p_max_size, cur->mem * 100 / cur->memmax); } - OBJ(memgauge){ - new_gauge(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); - } - OBJ(membar) { - new_bar(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); - } -#ifdef X11 - OBJ(memgraph) { - new_graph(obj, p, p_max_size, cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0); - } -#endif /* X11 */ #ifdef X11 #define NOT_IN_X "Not running in X" OBJ(monitor) { diff --git a/src/core.c b/src/core.c index f7074828..31575ea7 100644 --- a/src/core.c +++ b/src/core.c @@ -768,14 +768,17 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(memperc, &update_meminfo) END OBJ(memgauge, &update_meminfo) scan_gauge(obj, arg); + obj->callbacks.gaugeval = &mem_barval; END OBJ(membar, &update_meminfo) scan_bar(obj, arg); + obj->callbacks.barval = &mem_barval; #ifdef X11 END OBJ(memgraph, &update_meminfo) char *buf = 0; buf = scan_graph(obj, arg, 100); if (buf) free(buf); + obj->callbacks.graphval = &mem_barval; #endif /* X11*/ END OBJ(mixer, 0) parse_mixer_arg(obj, arg);