mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-27 09:08:25 +00:00
specials: convert gauge objects to new style
This commit is contained in:
parent
bbec0db498
commit
50e2b5961a
11
src/conky.c
11
src/conky.c
@ -922,8 +922,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
OBJ(cpugauge)
|
OBJ(cpugauge)
|
||||||
new_gauge(p, obj->a, obj->b,
|
new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
|
||||||
round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
|
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
OBJ(cpubar) {
|
OBJ(cpubar) {
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
@ -1336,7 +1335,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
OBJ(lua_gauge) {
|
OBJ(lua_gauge) {
|
||||||
double per;
|
double per;
|
||||||
if (llua_getnumber(obj->data.s, &per)) {
|
if (llua_getnumber(obj->data.s, &per)) {
|
||||||
new_gauge(p, obj->a, obj->b, (per/100.0 * 255));
|
new_gauge(obj, p, (per/100.0 * 255));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
@ -1466,8 +1465,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
OBJ(memgauge){
|
OBJ(memgauge){
|
||||||
new_gauge(p, obj->data.pair.a, obj->data.pair.b,
|
new_gauge(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
||||||
cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
OBJ(membar) {
|
OBJ(membar) {
|
||||||
@ -2262,8 +2260,7 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
OBJ(apcupsd_loadgauge) {
|
OBJ(apcupsd_loadgauge) {
|
||||||
double progress;
|
double progress;
|
||||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||||
new_gauge(p, obj->a, obj->b,
|
new_gauge(obj, p, (int)progress);
|
||||||
(int)progress);
|
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
OBJ(apcupsd_charge) {
|
OBJ(apcupsd_charge) {
|
||||||
|
14
src/core.c
14
src/core.c
@ -345,9 +345,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
DBGP2("Adding $cpu for CPU %d", obj->data.i);
|
DBGP2("Adding $cpu for CPU %d", obj->data.i);
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
END OBJ(cpugauge, &update_cpu_usage)
|
END OBJ(cpugauge, &update_cpu_usage)
|
||||||
SIZE_DEFAULTS(gauge);
|
|
||||||
SCAN_CPU(arg, obj->data.i);
|
SCAN_CPU(arg, obj->data.i);
|
||||||
scan_gauge(arg, &obj->a, &obj->b);
|
scan_gauge(obj, arg);
|
||||||
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
|
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ(cpubar, &update_cpu_usage)
|
END OBJ(cpubar, &update_cpu_usage)
|
||||||
@ -472,7 +471,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
scan_exec_arg(obj, arg);
|
scan_exec_arg(obj, arg);
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
END OBJ(execgauge, 0)
|
END OBJ(execgauge, 0)
|
||||||
SIZE_DEFAULTS(gauge);
|
|
||||||
scan_exec_arg(obj, arg);
|
scan_exec_arg(obj, arg);
|
||||||
END OBJ(execgraph, 0)
|
END OBJ(execgraph, 0)
|
||||||
scan_execgraph_arg(obj, arg);
|
scan_execgraph_arg(obj, arg);
|
||||||
@ -483,7 +481,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
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);
|
||||||
END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
|
END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
|
||||||
SIZE_DEFAULTS(gauge);
|
|
||||||
scan_execi_arg(obj, arg);
|
scan_execi_arg(obj, arg);
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ_ARG(execi, 0, "execi needs arguments")
|
END OBJ_ARG(execi, 0, "execi needs arguments")
|
||||||
@ -637,8 +634,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
END OBJ(memperc, &update_meminfo)
|
END OBJ(memperc, &update_meminfo)
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
END OBJ(memgauge, &update_meminfo)
|
END OBJ(memgauge, &update_meminfo)
|
||||||
SIZE_DEFAULTS(gauge);
|
scan_gauge(obj, arg);
|
||||||
scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
|
|
||||||
#endif /* X11*/
|
#endif /* X11*/
|
||||||
END OBJ(membar, &update_meminfo)
|
END OBJ(membar, &update_meminfo)
|
||||||
scan_bar(obj, arg);
|
scan_bar(obj, arg);
|
||||||
@ -952,8 +948,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
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]");
|
||||||
}
|
}
|
||||||
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]")
|
||||||
SIZE_DEFAULTS(gauge);
|
arg = scan_gauge(obj, arg);
|
||||||
arg = scan_gauge(arg, &obj->a, &obj->b);
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
obj->data.s = strndup(arg, text_buffer_size);
|
obj->data.s = strndup(arg, text_buffer_size);
|
||||||
} else {
|
} else {
|
||||||
@ -1031,8 +1026,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
buf = scan_graph(obj, arg);
|
buf = scan_graph(obj, arg);
|
||||||
if (buf) free(buf);
|
if (buf) free(buf);
|
||||||
END OBJ(apcupsd_loadgauge, &update_apcupsd)
|
END OBJ(apcupsd_loadgauge, &update_apcupsd)
|
||||||
SIZE_DEFAULTS(gauge);
|
scan_gauge(obj, arg);
|
||||||
scan_gauge(arg, &obj->a, &obj->b);
|
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
END OBJ(apcupsd_charge, &update_apcupsd)
|
END OBJ(apcupsd_charge, &update_apcupsd)
|
||||||
END OBJ(apcupsd_timeleft, &update_apcupsd)
|
END OBJ(apcupsd_timeleft, &update_apcupsd)
|
||||||
|
@ -364,7 +364,7 @@ void print_execgauge(struct text_object *obj, char *p, int p_max_size)
|
|||||||
|
|
||||||
if (barnum >= 0.0) {
|
if (barnum >= 0.0) {
|
||||||
barnum /= 100;
|
barnum /= 100;
|
||||||
new_gauge(p, obj->a, obj->b, round_to_int(barnum * 255.0));
|
new_gauge(obj, p, round_to_int(barnum * 255.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ void print_execigauge(struct text_object *obj, char *p, int p_max_size)
|
|||||||
}
|
}
|
||||||
ed->last_update = current_update_time;
|
ed->last_update = current_update_time;
|
||||||
}
|
}
|
||||||
new_gauge(p, obj->a, obj->b, round_to_int(obj->f));
|
new_gauge(obj, p, round_to_int(obj->f));
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@ struct bar {
|
|||||||
int width, height;
|
int width, height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gauge {
|
||||||
|
int width, height;
|
||||||
|
};
|
||||||
|
|
||||||
struct graph {
|
struct graph {
|
||||||
int width, height;
|
int width, height;
|
||||||
unsigned int first_colour, last_colour;
|
unsigned int first_colour, last_colour;
|
||||||
@ -71,24 +75,30 @@ struct graph {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
const char *scan_gauge(const char *args, int *w, int *h)
|
const char *scan_gauge(struct text_object *obj, const char *args)
|
||||||
{
|
{
|
||||||
|
struct gauge *g;
|
||||||
|
|
||||||
|
g = malloc(sizeof(struct gauge));
|
||||||
|
memset(g, 0, sizeof(struct gauge));
|
||||||
|
|
||||||
/*width and height*/
|
/*width and height*/
|
||||||
*w = default_gauge_width;
|
g->width = default_gauge_width;
|
||||||
*h = default_gauge_height;
|
g->height = default_gauge_height;
|
||||||
|
|
||||||
/* gauge's argument is either height or height,width */
|
/* gauge's argument is either height or height,width */
|
||||||
if (args) {
|
if (args) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
|
if (sscanf(args, "%d,%d %n", &g->height, &g->width, &n) <= 1) {
|
||||||
if (sscanf(args, "%d %n", h, &n) == 2) {
|
if (sscanf(args, "%d %n", &g->height, &n) == 2) {
|
||||||
*w = *h; /*square gauge*/
|
g->width = g->height; /*square gauge*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args += n;
|
args += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj->special_data = g;
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
@ -228,17 +238,22 @@ static struct special_t *new_special(char *buf, enum special_types t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
void new_gauge(char *buf, int w, int h, int usage)
|
void new_gauge(struct text_object *obj, char *buf, int usage)
|
||||||
{
|
{
|
||||||
struct special_t *s = 0;
|
struct special_t *s = 0;
|
||||||
|
struct gauge *g = obj->special_data;
|
||||||
|
|
||||||
if ((output_methods & TO_X) == 0)
|
if ((output_methods & TO_X) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!g)
|
||||||
|
return;
|
||||||
|
|
||||||
s = new_special(buf, GAUGE);
|
s = new_special(buf, GAUGE);
|
||||||
|
|
||||||
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
||||||
s->width = w;
|
s->width = g->width;
|
||||||
s->height = h;
|
s->height = g->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void new_bar(struct text_object *obj, char *buf, int usage)
|
void new_bar(struct text_object *obj, char *buf, int usage)
|
||||||
|
@ -101,12 +101,12 @@ extern int max_specials;
|
|||||||
/* scanning special arguments */
|
/* scanning special arguments */
|
||||||
const char *scan_bar(struct text_object *, const char *);
|
const char *scan_bar(struct text_object *, const char *);
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
const char *scan_gauge(const char *, int *, int *);
|
const char *scan_gauge(struct text_object *, const char *);
|
||||||
char *scan_font(const char *);
|
char *scan_font(const char *);
|
||||||
char *scan_graph(struct text_object *, const char *);
|
char *scan_graph(struct text_object *, const char *);
|
||||||
|
|
||||||
/* printing specials */
|
/* printing specials */
|
||||||
void new_gauge(char *, int, int, int);
|
void new_gauge(struct text_object *, char *, int);
|
||||||
void new_bar(struct text_object *, char *, int);
|
void new_bar(struct text_object *, char *, int);
|
||||||
void new_font(char *, char *);
|
void new_font(char *, char *);
|
||||||
void new_graph(struct text_object *, char *, double);
|
void new_graph(struct text_object *, char *, double);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user