}
#ifdef X11
OBJ(cpugauge)
- new_gauge(p, obj->a, obj->b,
- round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
+ new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
#endif /* X11 */
OBJ(cpubar) {
#ifdef X11
OBJ(lua_gauge) {
double 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 */
}
#ifdef X11
OBJ(memgauge){
- new_gauge(p, obj->data.pair.a, obj->data.pair.b,
- cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
+ new_gauge(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
}
#endif /* X11 */
OBJ(membar) {
OBJ(apcupsd_loadgauge) {
double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
- new_gauge(p, obj->a, obj->b,
- (int)progress);
+ new_gauge(obj, p, (int)progress);
}
#endif /* X11 */
OBJ(apcupsd_charge) {
DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef X11
END OBJ(cpugauge, &update_cpu_usage)
- SIZE_DEFAULTS(gauge);
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);
#endif /* X11 */
END OBJ(cpubar, &update_cpu_usage)
scan_exec_arg(obj, arg);
#ifdef X11
END OBJ(execgauge, 0)
- SIZE_DEFAULTS(gauge);
scan_exec_arg(obj, arg);
END OBJ(execgraph, 0)
scan_execgraph_arg(obj, arg);
END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
scan_execgraph_arg(obj, arg);
END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
- SIZE_DEFAULTS(gauge);
scan_execi_arg(obj, arg);
#endif /* X11 */
END OBJ_ARG(execi, 0, "execi needs arguments")
END OBJ(memperc, &update_meminfo)
#ifdef X11
END OBJ(memgauge, &update_meminfo)
- SIZE_DEFAULTS(gauge);
- scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
+ scan_gauge(obj, arg);
#endif /* X11*/
END OBJ(membar, &update_meminfo)
scan_bar(obj, arg);
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]")
- SIZE_DEFAULTS(gauge);
- arg = scan_gauge(arg, &obj->a, &obj->b);
+ arg = scan_gauge(obj, arg);
if (arg) {
obj->data.s = strndup(arg, text_buffer_size);
} else {
buf = scan_graph(obj, arg);
if (buf) free(buf);
END OBJ(apcupsd_loadgauge, &update_apcupsd)
- SIZE_DEFAULTS(gauge);
- scan_gauge(arg, &obj->a, &obj->b);
+ scan_gauge(obj, arg);
#endif /* X11 */
END OBJ(apcupsd_charge, &update_apcupsd)
END OBJ(apcupsd_timeleft, &update_apcupsd)
if (barnum >= 0.0) {
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));
}
}
}
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 */
int width, height;
};
+struct gauge {
+ int width, height;
+};
+
struct graph {
int width, height;
unsigned int first_colour, last_colour;
*/
#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*/
- *w = default_gauge_width;
- *h = default_gauge_height;
+ g->width = default_gauge_width;
+ g->height = default_gauge_height;
/* gauge's argument is either height or height,width */
if (args) {
int n = 0;
- if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
- if (sscanf(args, "%d %n", h, &n) == 2) {
- *w = *h; /*square gauge*/
+ if (sscanf(args, "%d,%d %n", &g->height, &g->width, &n) <= 1) {
+ if (sscanf(args, "%d %n", &g->height, &n) == 2) {
+ g->width = g->height; /*square gauge*/
}
}
args += n;
}
+ obj->special_data = g;
return args;
}
#endif /* 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 gauge *g = obj->special_data;
+
if ((output_methods & TO_X) == 0)
return;
+ if (!g)
+ return;
+
s = new_special(buf, GAUGE);
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
- s->width = w;
- s->height = h;
+ s->width = g->width;
+ s->height = g->height;
}
void new_bar(struct text_object *obj, char *buf, int usage)
/* scanning special arguments */
const char *scan_bar(struct text_object *, const char *);
#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_graph(struct text_object *, const char *);
/* 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_font(char *, char *);
void new_graph(struct text_object *, char *, double);