mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
reuse barval callbacks where applicable
This commit is contained in:
parent
cba2460397
commit
9581914f7d
@ -237,28 +237,6 @@ void print_apcupsd_nop(struct text_object *obj, char *p, int p_max_size)
|
|||||||
(void)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)
|
uint8_t apcupsd_loadbarval(struct text_object *obj)
|
||||||
{
|
{
|
||||||
(void)obj;
|
(void)obj;
|
||||||
|
@ -52,8 +52,6 @@ typedef struct apcupsd_s {
|
|||||||
void update_apcupsd(void);
|
void update_apcupsd(void);
|
||||||
|
|
||||||
void print_apcupsd_nop(struct text_object *, char *, int);
|
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 *);
|
uint8_t apcupsd_loadbarval(struct text_object *);
|
||||||
|
|
||||||
void print_apcupsd_name(struct text_object *, char *, int);
|
void print_apcupsd_name(struct text_object *, char *, int);
|
||||||
|
@ -883,14 +883,6 @@ 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.i] * 100.0));
|
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
|
#ifdef X11
|
||||||
OBJ(font) {
|
OBJ(font) {
|
||||||
new_font(p, obj->data.s);
|
new_font(p, obj->data.s);
|
||||||
|
18
src/core.c
18
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)
|
END OBJ(cpugauge, &update_cpu_usage)
|
||||||
SCAN_CPU(arg, obj->data.i);
|
SCAN_CPU(arg, obj->data.i);
|
||||||
scan_gauge(obj, arg);
|
scan_gauge(obj, arg);
|
||||||
|
obj->callbacks.gaugeval = &cpu_barval;
|
||||||
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
|
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
|
||||||
END OBJ(cpubar, &update_cpu_usage)
|
END OBJ(cpubar, &update_cpu_usage)
|
||||||
SCAN_CPU(arg, obj->data.i);
|
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);
|
buf = scan_graph(obj, arg, 100);
|
||||||
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
|
DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
|
||||||
if (buf) free(buf);
|
if (buf) free(buf);
|
||||||
|
obj->callbacks.graphval = &cpu_barval;
|
||||||
END OBJ(loadgraph, &update_load_average)
|
END OBJ(loadgraph, &update_load_average)
|
||||||
scan_loadgraph_arg(obj, arg);
|
scan_loadgraph_arg(obj, arg);
|
||||||
obj->callbacks.print = &print_loadgraph;
|
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;
|
obj->callbacks.free = &free_exec;
|
||||||
END OBJ(execgauge, 0)
|
END OBJ(execgauge, 0)
|
||||||
scan_exec_arg(obj, arg);
|
scan_exec_arg(obj, arg);
|
||||||
obj->callbacks.print = &print_execgauge;
|
obj->callbacks.gaugeval = &execbarval;
|
||||||
obj->callbacks.free = &free_exec;
|
obj->callbacks.free = &free_exec;
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
END OBJ(execgraph, 0)
|
END OBJ(execgraph, 0)
|
||||||
scan_execgraph_arg(obj, arg);
|
scan_execgraph_arg(obj, arg);
|
||||||
obj->callbacks.print = &print_execgraph;
|
obj->callbacks.graphval = &execbarval;
|
||||||
obj->callbacks.free = &free_exec;
|
obj->callbacks.free = &free_exec;
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ_ARG(execibar, 0, "execibar needs arguments")
|
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
|
#ifdef X11
|
||||||
END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
|
END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
|
||||||
scan_execgraph_arg(obj, arg);
|
scan_execgraph_arg(obj, arg);
|
||||||
obj->callbacks.print = &print_execigraph;
|
obj->callbacks.graphval = &execi_barval;
|
||||||
obj->callbacks.free = &free_execi;
|
obj->callbacks.free = &free_execi;
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
|
END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
|
||||||
scan_execi_arg(obj, arg);
|
scan_execi_arg(obj, arg);
|
||||||
obj->callbacks.gaugeval = &execigaugeval;
|
obj->callbacks.gaugeval = &execi_barval;
|
||||||
obj->callbacks.free = &free_execi;
|
obj->callbacks.free = &free_execi;
|
||||||
END OBJ_ARG(execi, 0, "execi needs arguments")
|
END OBJ_ARG(execi, 0, "execi needs arguments")
|
||||||
scan_execi_arg(obj, arg);
|
scan_execi_arg(obj, arg);
|
||||||
@ -1341,7 +1343,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
|
CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [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;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
|
END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
|
||||||
@ -1351,7 +1353,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
|
CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
|
||||||
}
|
}
|
||||||
obj->callbacks.print = &print_lua_gauge;
|
obj->callbacks.gaugeval = &lua_barval;
|
||||||
obj->callbacks.free = &gen_free_opaque;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
#endif /* HAVE_LUA */
|
#endif /* HAVE_LUA */
|
||||||
#ifdef HDDTEMP
|
#ifdef HDDTEMP
|
||||||
@ -1450,11 +1452,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
char* buf = 0;
|
char* buf = 0;
|
||||||
buf = scan_graph(obj, arg, 0);
|
buf = scan_graph(obj, arg, 0);
|
||||||
if (buf) free(buf);
|
if (buf) free(buf);
|
||||||
obj->callbacks.print = &print_apcupsd_loadgraph;
|
obj->callbacks.graphval = &apcupsd_loadbarval;
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ(apcupsd_loadgauge, &update_apcupsd)
|
END OBJ(apcupsd_loadgauge, &update_apcupsd)
|
||||||
scan_gauge(obj, arg);
|
scan_gauge(obj, arg);
|
||||||
obj->callbacks.print = &print_apcupsd_loadgauge;
|
obj->callbacks.gaugeval = &apcupsd_loadbarval;
|
||||||
END OBJ(apcupsd_charge, &update_apcupsd)
|
END OBJ(apcupsd_charge, &update_apcupsd)
|
||||||
obj->callbacks.print = &print_apcupsd_charge;
|
obj->callbacks.print = &print_apcupsd_charge;
|
||||||
END OBJ(apcupsd_timeleft, &update_apcupsd)
|
END OBJ(apcupsd_timeleft, &update_apcupsd)
|
||||||
|
47
src/exec.c
47
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)
|
uint8_t execbarval(struct text_object *obj)
|
||||||
{
|
{
|
||||||
return round_to_int(read_exec_barnum(obj->data.s) * 2.55);
|
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->barnum = read_exec_barnum(ed->cmd) * 2.55;
|
||||||
ed->last_update = current_update_time;
|
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)
|
void free_exec(struct text_object *obj)
|
||||||
|
@ -42,12 +42,6 @@ void print_execp(struct text_object *, char *, int);
|
|||||||
void print_execi(struct text_object *, char *, int);
|
void print_execi(struct text_object *, char *, int);
|
||||||
void print_execpi(struct text_object *, char *, int);
|
void print_execpi(struct text_object *, char *, int);
|
||||||
void print_texeci(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 execbarval(struct text_object *);
|
||||||
uint8_t execi_barval(struct text_object *);
|
uint8_t execi_barval(struct text_object *);
|
||||||
void free_exec(struct text_object *);
|
void free_exec(struct text_object *);
|
||||||
|
26
src/llua.c
26
src/llua.c
@ -554,29 +554,3 @@ uint8_t lua_barval(struct text_object *obj)
|
|||||||
}
|
}
|
||||||
return 0;
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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(struct text_object *, char *, int);
|
||||||
void print_lua_parse(struct text_object *, char *, int);
|
void print_lua_parse(struct text_object *, char *, int);
|
||||||
uint8_t lua_barval(struct text_object *);
|
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_*/
|
#endif /* LUA_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user