From 9581914f7dd185743cbac9429b043b70390f0ce0 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 1 Dec 2009 00:10:22 +0100 Subject: [PATCH] reuse barval callbacks where applicable --- src/apcupsd.c | 22 ---------------------- src/apcupsd.h | 2 -- src/conky.c | 8 -------- src/core.c | 18 ++++++++++-------- src/exec.c | 47 +---------------------------------------------- src/exec.h | 6 ------ src/llua.c | 26 -------------------------- src/llua.h | 4 ---- 8 files changed, 11 insertions(+), 122 deletions(-) diff --git a/src/apcupsd.c b/src/apcupsd.c index c1bd11dc..5c701c49 100644 --- a/src/apcupsd.c +++ b/src/apcupsd.c @@ -237,28 +237,6 @@ void print_apcupsd_nop(struct text_object *obj, char *p, int p_max_size) (void)p_max_size; } -void print_apcupsd_loadgraph(struct text_object *obj, char *p, int p_max_size) -{ - double progress; - - if (!p_max_size) - return; - - progress = atof(info.apcupsd.items[APCUPSD_LOAD]); - new_graph(obj, p, p_max_size, (int)progress); -} - -void print_apcupsd_loadgauge(struct text_object *obj, char *p, int p_max_size) -{ - double progress; - - if (!p_max_size) - return; - - progress = atof(info.apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0; - new_gauge(obj, p, p_max_size, (int)progress); -} - uint8_t apcupsd_loadbarval(struct text_object *obj) { (void)obj; diff --git a/src/apcupsd.h b/src/apcupsd.h index ee488775..787b6989 100644 --- a/src/apcupsd.h +++ b/src/apcupsd.h @@ -52,8 +52,6 @@ typedef struct apcupsd_s { void update_apcupsd(void); void print_apcupsd_nop(struct text_object *, char *, int); -void print_apcupsd_loadgraph(struct text_object *, char *, int); -void print_apcupsd_loadgauge(struct text_object *, char *, int); uint8_t apcupsd_loadbarval(struct text_object *); void print_apcupsd_name(struct text_object *, char *, int); diff --git a/src/conky.c b/src/conky.c index 4be737b3..93712ad4 100644 --- a/src/conky.c +++ b/src/conky.c @@ -883,14 +883,6 @@ void generate_text_internal(char *p, int p_max_size, percent_print(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100.0)); } - OBJ(cpugauge) { - new_gauge(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0)); - } -#ifdef X11 - OBJ(cpugraph) { - new_graph(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100)); - } -#endif /* X11 */ #ifdef X11 OBJ(font) { new_font(p, obj->data.s); diff --git a/src/core.c b/src/core.c index 9803764e..96a7dfeb 100644 --- a/src/core.c +++ b/src/core.c @@ -390,6 +390,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(cpugauge, &update_cpu_usage) SCAN_CPU(arg, obj->data.i); scan_gauge(obj, arg); + obj->callbacks.gaugeval = &cpu_barval; DBGP2("Adding $cpugauge for CPU %d", obj->data.i); END OBJ(cpubar, &update_cpu_usage) SCAN_CPU(arg, obj->data.i); @@ -403,6 +404,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long buf = scan_graph(obj, arg, 100); DBGP2("Adding $cpugraph for CPU %d", obj->data.i); if (buf) free(buf); + obj->callbacks.graphval = &cpu_barval; END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg); obj->callbacks.print = &print_loadgraph; @@ -550,12 +552,12 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->callbacks.free = &free_exec; END OBJ(execgauge, 0) scan_exec_arg(obj, arg); - obj->callbacks.print = &print_execgauge; + obj->callbacks.gaugeval = &execbarval; obj->callbacks.free = &free_exec; #ifdef X11 END OBJ(execgraph, 0) scan_execgraph_arg(obj, arg); - obj->callbacks.print = &print_execgraph; + obj->callbacks.graphval = &execbarval; obj->callbacks.free = &free_exec; #endif /* X11 */ END OBJ_ARG(execibar, 0, "execibar needs arguments") @@ -565,12 +567,12 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #ifdef X11 END OBJ_ARG(execigraph, 0, "execigraph needs arguments") scan_execgraph_arg(obj, arg); - obj->callbacks.print = &print_execigraph; + obj->callbacks.graphval = &execi_barval; obj->callbacks.free = &free_execi; #endif /* X11 */ END OBJ_ARG(execigauge, 0, "execigauge needs arguments") scan_execi_arg(obj, arg); - obj->callbacks.gaugeval = &execigaugeval; + obj->callbacks.gaugeval = &execi_barval; obj->callbacks.free = &free_execi; END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); @@ -1341,7 +1343,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long } else { CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); } - obj->callbacks.print = &print_lua_graph; + obj->callbacks.graphval = &lua_barval; obj->callbacks.free = &gen_free_opaque; #endif /* X11 */ END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: , [function parameters]") @@ -1351,7 +1353,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long } else { CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: , [function parameters]"); } - obj->callbacks.print = &print_lua_gauge; + obj->callbacks.gaugeval = &lua_barval; obj->callbacks.free = &gen_free_opaque; #endif /* HAVE_LUA */ #ifdef HDDTEMP @@ -1450,11 +1452,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long char* buf = 0; buf = scan_graph(obj, arg, 0); if (buf) free(buf); - obj->callbacks.print = &print_apcupsd_loadgraph; + obj->callbacks.graphval = &apcupsd_loadbarval; #endif /* X11 */ END OBJ(apcupsd_loadgauge, &update_apcupsd) scan_gauge(obj, arg); - obj->callbacks.print = &print_apcupsd_loadgauge; + obj->callbacks.gaugeval = &apcupsd_loadbarval; END OBJ(apcupsd_charge, &update_apcupsd) obj->callbacks.print = &print_apcupsd_charge; END OBJ(apcupsd_timeleft, &update_apcupsd) diff --git a/src/exec.c b/src/exec.c index 973e68dc..8dc224b4 100644 --- a/src/exec.c +++ b/src/exec.c @@ -364,51 +364,6 @@ void print_texeci(struct text_object *obj, char *p, int p_max_size) } } -void print_execgauge(struct text_object *obj, char *p, int p_max_size) -{ - new_gauge(obj, p, p_max_size, round_to_int(read_exec_barnum(obj->data.s) * 2.55)); -} - -#ifdef X11 -void print_execgraph(struct text_object *obj, char *p, int p_max_size) -{ - struct execi_data *ed = obj->data.opaque; - - if (!ed) - return; - - new_graph(obj, p, p_max_size, round_to_int(read_exec_barnum(ed->cmd))); -} - -void print_execigraph(struct text_object *obj, char *p, int p_max_size) -{ - struct execi_data *ed = obj->data.opaque; - - if (!ed) - return; - - if (time_to_update(ed)) { - ed->barnum = read_exec_barnum(ed->cmd) * 2.55; - ed->last_update = current_update_time; - } - new_graph(obj, p, p_max_size, (int) (ed->barnum)); -} -#endif /* X11 */ - -uint8_t execigaugeval(struct text_object *obj) -{ - struct execi_data *ed = obj->data.opaque; - - if (!ed) - return 0; - - if (time_to_update(ed)) { - ed->barnum = read_exec_barnum(ed->cmd) * 2.55; - ed->last_update = current_update_time; - } - return round_to_int(ed->barnum); -} - uint8_t execbarval(struct text_object *obj) { return round_to_int(read_exec_barnum(obj->data.s) * 2.55); @@ -425,7 +380,7 @@ uint8_t execi_barval(struct text_object *obj) ed->barnum = read_exec_barnum(ed->cmd) * 2.55; ed->last_update = current_update_time; } - return round_to_int(ed->barnum * 2.55); + return round_to_int(ed->barnum); } void free_exec(struct text_object *obj) diff --git a/src/exec.h b/src/exec.h index 8307b0b6..e4c44814 100644 --- a/src/exec.h +++ b/src/exec.h @@ -42,12 +42,6 @@ void print_execp(struct text_object *, char *, int); void print_execi(struct text_object *, char *, int); void print_execpi(struct text_object *, char *, int); void print_texeci(struct text_object *, char *, int); -void print_execgauge(struct text_object *, char *, int); -#ifdef X11 -void print_execgraph(struct text_object *, char *, int); -void print_execigraph(struct text_object *, char *, int); -#endif /* X11 */ -uint8_t execigaugeval(struct text_object *); uint8_t execbarval(struct text_object *); uint8_t execi_barval(struct text_object *); void free_exec(struct text_object *); diff --git a/src/llua.c b/src/llua.c index 8c12a2f7..4b4edf44 100644 --- a/src/llua.c +++ b/src/llua.c @@ -554,29 +554,3 @@ uint8_t lua_barval(struct text_object *obj) } return 0; } - -#ifdef X11 -void print_lua_graph(struct text_object *obj, char *p, int p_max_size) -{ - double per; - - if (!p_max_size) - return; - - if (llua_getnumber(obj->data.s, &per)) { - new_graph(obj, p, p_max_size, per); - } -} -#endif /* X11 */ - -void print_lua_gauge(struct text_object *obj, char *p, int p_max_size) -{ - double per; - - if (!p_max_size) - return; - - if (llua_getnumber(obj->data.s, &per)) { - new_gauge(obj, p, p_max_size, (per/100.0 * 255)); - } -} diff --git a/src/llua.h b/src/llua.h index 291b2e77..55cdc0f7 100644 --- a/src/llua.h +++ b/src/llua.h @@ -68,9 +68,5 @@ void llua_update_info(struct information *i, double u_interval); void print_lua(struct text_object *, char *, int); void print_lua_parse(struct text_object *, char *, int); uint8_t lua_barval(struct text_object *); -#ifdef X11 -void print_lua_graph(struct text_object *, char *, int); -#endif /* X11 */ -void print_lua_gauge(struct text_object *, char *, int); #endif /* LUA_H_*/