From 07f82f5cb60c8a27ba5393745c89833af8194e3c Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 25 Nov 2009 01:30:21 +0100 Subject: [PATCH] convert cpu to callbacks.percentage --- src/common.c | 10 ++++++++++ src/common.h | 1 + src/conky.c | 9 --------- src/core.c | 1 + 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common.c b/src/common.c index 33636e6f..8d5695d8 100644 --- a/src/common.c +++ b/src/common.c @@ -472,6 +472,16 @@ uint8_t loadgraphval(struct text_object *obj) } #endif /* X11 */ +uint8_t cpu_percentage(struct text_object *obj) +{ + if (obj->data.i > info.cpu_count) { + NORM_ERR("obj->data.i %i info.cpu_count %i", + obj->data.i, info.cpu_count); + CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); + } + return round_to_int(info.cpu_usage[obj->data.i] * 100.0); +} + uint8_t cpu_barval(struct text_object *obj) { return round_to_int(info.cpu_usage[obj->data.i] * 255.0); diff --git a/src/common.h b/src/common.h index 9d034c29..c92d79c8 100644 --- a/src/common.h +++ b/src/common.h @@ -75,6 +75,7 @@ void scan_loadgraph_arg(struct text_object *, const char *); uint8_t loadgraphval(struct text_object *); #endif /* X11 */ +uint8_t cpu_percentage(struct text_object *); uint8_t cpu_barval(struct text_object *); uint8_t mem_barval(struct text_object *); uint8_t swap_barval(struct text_object *); diff --git a/src/conky.c b/src/conky.c index 93712ad4..7c835def 100644 --- a/src/conky.c +++ b/src/conky.c @@ -874,15 +874,6 @@ void generate_text_internal(char *p, int p_max_size, OBJ(cmdline_to_pid) { print_cmdline_to_pid(obj, p, p_max_size); } - OBJ(cpu) { - if (obj->data.i > info.cpu_count) { - NORM_ERR("obj->data.i %i info.cpu_count %i", - obj->data.i, info.cpu_count); - CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); - } - percent_print(p, p_max_size, - round_to_int(cur->cpu_usage[obj->data.i] * 100.0)); - } #ifdef X11 OBJ(font) { new_font(p, obj->data.s); diff --git a/src/core.c b/src/core.c index 4de3bdab..03a670df 100644 --- a/src/core.c +++ b/src/core.c @@ -386,6 +386,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long } END OBJ(cpu, &update_cpu_usage) SCAN_CPU(arg, obj->data.i); + obj->callbacks.percentage = &cpu_percentage; DBGP2("Adding $cpu for CPU %d", obj->data.i); END OBJ(cpugauge, &update_cpu_usage) SCAN_CPU(arg, obj->data.i);