OBJ(battery_bar) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
- }else{
-#endif /* X11 */
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55, obj->a);
-#ifdef X11
- }
+ new_bar(obj, p, get_battery_perct_bar(obj->data.s));
+ }else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, get_battery_perct_bar(obj->data.s) / 2.55);
}
OBJ(battery_short) {
get_battery_short_status(p, p_max_size, obj->data.s);
OBJ(cpubar) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b,
- round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
- }else{
-#endif /* X11 */
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100), obj->a);
-#ifdef X11
- }
+ new_bar(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
+ }else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 100));
}
#ifdef X11
OBJ(cpugraph) {
if (llua_getnumber(obj->data.s, &per)) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b, (per/100.0 * 255));
- } else {
-#endif /* X11 */
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, per, obj->a);
-#ifdef X11
- }
+ new_bar(obj, p, (per/100.0 * 255));
+ } else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, per);
}
}
#ifdef X11
OBJ(membar) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->data.pair.a, obj->data.pair.b,
- cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
- }else{
-#endif /* X11 */
- if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0, obj->data.pair.a);
-#ifdef X11
- }
+ new_bar(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
+ }else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, cur->memmax ? (cur->mem * 100) / (cur->memmax) : 0);
}
#ifdef X11
OBJ(memgraph) {
OBJ(swapbar) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->data.pair.a, obj->data.pair.b,
- cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
- }else{
-#endif /* X11 */
- if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0, obj->data.pair.a);
-#ifdef X11
- }
+ new_bar(obj, p, cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
+ }else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, cur->swapmax ? (cur->swap * 100) / (cur->swapmax) : 0);
}
OBJ(sysname) {
snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
OBJ(mpd_bar) {
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->data.pair.a, obj->data.pair.b,
- (int) (mpd_get_info()->progress * 255.0f));
- } else {
-#endif /* X11 */
- if(!obj->data.pair.a) obj->data.pair.a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, (int) (mpd_get_info()->progress * 100.0f), obj->data.pair.a);
-#ifdef X11
- }
+ new_bar(obj, p, (int) (mpd_get_info()->progress * 255.0f));
+ } else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, (int) (mpd_get_info()->progress * 100.0f));
}
OBJ(mpd_smart) {
struct mpd_s *mpd = mpd_get_info();
}
#ifdef X11
OBJ(xmms2_bar) {
- new_bar(p, obj->data.pair.a, obj->data.pair.b,
- (int) (cur->xmms2.progress * 255.0f));
+ new_bar(obj, p, (int) (cur->xmms2.progress * 255.0f));
}
#endif /* X11 */
OBJ(xmms2_playlist) {
progress =
atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
- new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
+ new_bar(obj, p, (int) (progress * 255.0f));
}
#endif /* X11 */
#endif /* AUDACIOUS */
(double) cur->entropy.poolsize;
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
- } else {
-#endif /* X11 */
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, (int) (entropy_perc * 100.0f), obj->a);
-#ifdef X11
- }
+ new_bar(obj, p, (int) (entropy_perc * 255.0f));
+ } else
#endif /* X11 */
+ new_bar_in_shell(obj, p, p_max_size, (int) (entropy_perc * 100.0f));
}
#ifdef IBM
OBJ(smapi) {
#ifdef X11
OBJ(smapi_bat_bar) {
if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
- new_bar(p, obj->a, obj->b, (int)
+ new_bar(obj, p, (int)
(255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
else
- new_bar(p, obj->a, obj->b, 0);
+ new_bar(obj, p, 0);
}
#endif /* X11 */
#endif /* IBM */
#ifdef X11
if(output_methods & TO_X) {
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
- new_bar(p, obj->a, obj->b, (int) progress);
- } else {
+ new_bar(obj, p, (int) progress);
+ } else
#endif /* X11 */
+ {
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, (int) progress, obj->a);
-#ifdef X11
+ new_bar_in_shell(obj, p, p_max_size, (int) progress);
}
-#endif /* X11 */
}
#ifdef X11
OBJ(apcupsd_loadgraph) {
obj->data.s = strndup(bat, text_buffer_size);
END OBJ(battery_bar, 0)
char bat[64];
- SIZE_DEFAULTS(bar);
- obj->b = 6;
if (arg) {
- arg = scan_bar(arg, &obj->a, &obj->b);
+ arg = scan_bar(obj, arg);
sscanf(arg, "%63s", bat);
} else {
strcpy(bat, "BAT0");
DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif /* X11 */
END OBJ(cpubar, &update_cpu_usage)
- SIZE_DEFAULTS(bar);
SCAN_CPU(arg, obj->data.i);
- scan_bar(arg, &obj->a, &obj->b);
+ scan_bar(obj, arg);
DBGP2("Adding $cpubar for CPU %d", obj->data.i);
#ifdef X11
END OBJ(cpugraph, &update_cpu_usage)
END OBJ(execp, 0)
scan_exec_arg(obj, arg);
END OBJ(execbar, 0)
- SIZE_DEFAULTS(bar);
scan_exec_arg(obj, arg);
#ifdef X11
END OBJ(execgauge, 0)
scan_exec_arg(obj, arg);
#endif /* X11 */
END OBJ_ARG(execibar, 0, "execibar needs arguments")
- SIZE_DEFAULTS(bar);
scan_execi_arg(obj, arg);
#ifdef X11
END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
#endif /* X11*/
END OBJ(membar, &update_meminfo)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ scan_bar(obj, arg);
#ifdef X11
END OBJ(memgraph, &update_meminfo)
char *buf = 0;
END OBJ(swapmax, &update_meminfo)
END OBJ(swapperc, &update_meminfo)
END OBJ(swapbar, &update_meminfo)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ scan_bar(obj, arg);
END OBJ(sysname, 0)
END OBJ(time, 0)
scan_time(obj, arg);
#ifdef X11
END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
int cnt;
- SIZE_DEFAULTS(bar);
if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
NORM_ERR("first argument to smapi_bat_bar must be an integer value");
obj->data.i = -1;
- } else {
- obj->b = 4;
- arg = scan_bar(arg + cnt, &obj->a, &obj->b);
- }
+ } else
+ arg = scan_bar(obj, arg + cnt);
#endif /* X11 */
#endif /* IBM */
#ifdef MPD
END OBJ(mpd_bitrate, &update_mpd) init_mpd();
END OBJ(mpd_status, &update_mpd) init_mpd();
END OBJ(mpd_bar, &update_mpd)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ scan_bar(obj, arg);
init_mpd();
END OBJ(mpd_smart, &update_mpd)
mpd_set_maxlen(mpd_smart);
END OBJ(xmms2_percent, &update_xmms2)
#ifdef X11
END OBJ(xmms2_bar, &update_xmms2)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ scan_bar(obj, arg);
#endif /* X11 */
END OBJ(xmms2_smart, &update_xmms2)
END OBJ(xmms2_playlist, &update_xmms2)
END OBJ(audacious_main_volume, &update_audacious)
#ifdef X11
END OBJ(audacious_bar, &update_audacious)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->a, &obj->b);
+ scan_bar(obj, arg);
#endif /* X11 */
#endif
#ifdef BMPX
END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: <function name> [function parameters]")
obj->data.s = strndup(arg, text_buffer_size);
END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: <height>,<width> <function name> [function parameters]")
- SIZE_DEFAULTS(bar);
- arg = scan_bar(arg, &obj->a, &obj->b);
+ arg = scan_bar(obj, arg);
if(arg) {
obj->data.s = strndup(arg, text_buffer_size);
} else {
END OBJ(entropy_perc, &update_entropy)
END OBJ(entropy_poolsize, &update_entropy)
END OBJ(entropy_bar, &update_entropy)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->a, &obj->b);
+ scan_bar(obj, arg);
END OBJ_ARG(include, 0, "include needs a argument")
struct conftree *leaf = conftree_add(currentconffile, arg);
if(leaf) {
END OBJ(apcupsd_linev, &update_apcupsd)
END OBJ(apcupsd_load, &update_apcupsd)
END OBJ(apcupsd_loadbar, &update_apcupsd)
- SIZE_DEFAULTS(bar);
- scan_bar(arg, &obj->a, &obj->b);
+ scan_bar(obj, arg);
#ifdef X11
END OBJ(apcupsd_loadgraph, &update_apcupsd)
char* buf = 0;
#ifdef X11
if(output_methods & TO_X) {
barnum /= 100;
- new_bar(p, obj->a, obj->b, round_to_int(barnum * 255.0));
+ new_bar(obj, p, round_to_int(barnum * 255.0));
}else
#endif /* X11 */
- {
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, barnum, obj->a);
- }
+ new_bar_in_shell(obj, p, p_max_size, barnum);
}
}
}
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b, round_to_int(obj->f * 2.55));
+ new_bar(obj, p, round_to_int(obj->f * 2.55));
} else
#endif /* X11 */
- {
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, round_to_int(obj->f), obj->a);
- }
+ new_bar_in_shell(obj, p, p_max_size, round_to_int(obj->f));
}
void free_exec(struct text_object *obj)
#define MAX_FS_STATS 64
-struct fsbar {
- struct fs_stat *fs;
- int w, h;
-};
-
static struct fs_stat fs_stats_[MAX_FS_STATS];
struct fs_stat *fs_stats = fs_stats_;
void init_fs_bar(struct text_object *obj, const char *arg)
{
- struct fsbar *fb;
-
- fb = malloc(sizeof(struct fsbar));
- memset(fb, 0, sizeof(struct fsbar));
-
- fb->w = default_bar_width;
- fb->h = default_bar_height;
-
- arg = scan_bar(arg, &fb->w, &fb->h);
+ arg = scan_bar(obj, arg);
if (arg) {
while (isspace(*arg)) {
arg++;
} else {
arg = "/";
}
- fb->fs = prepare_fs_stat(arg);
- obj->data.opaque = fb;
+ obj->data.opaque = prepare_fs_stat(arg);
}
void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size)
{
double val = 1.0;
- struct fsbar *fb = obj->data.opaque;
+ struct fs_stat *fs = obj->data.opaque;
- if (!fb || !fb->fs)
+ if (!fs)
return;
- if (fb->fs->size)
- val = (double)fb->fs->avail / (double)fb->fs->size;
+ if (fs->size)
+ val = (double)fs->avail / (double)fs->size;
if (!be_free_bar)
val = 1.0 - val;
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, fb->w, fb->h, (int)(255 * val));
+ new_bar(obj, p, (int)(255 * val));
}else
#endif /* X11 */
- {
- if(!fb->w) fb->w = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, (int)(100 * val), fb->w);
- }
+ new_bar_in_shell(obj, p, p_max_size, (int)(100 * val));
}
void init_fs(struct text_object *obj, const char *arg)
}
#ifdef X11
-struct mixerbar_data {
- int l;
- int w, h;
-};
-
void scan_mixer_bar(struct text_object *obj, const char *arg)
{
char buf1[64];
- struct mixerbar_data *mbd;
int n;
- mbd = malloc(sizeof(struct mixerbar_data));
- memset(mbd, 0, sizeof(struct mixerbar_data));
-
if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
- mbd->l = mixer_init(buf1);
- scan_bar(arg + n, &mbd->w, &mbd->h);
+ obj->data.i = mixer_init(buf1);
+ scan_bar(obj, arg + n);
} else {
- mbd->l = mixer_init(NULL);
- scan_bar(arg, &mbd->w, &mbd->h);
+ obj->data.i = mixer_init(NULL);
+ scan_bar(obj, arg);
}
- obj->data.opaque = mbd;
}
/* see print_mixer() above for a description of 'chan' */
void print_mixer_bar(struct text_object *obj, int chan, char *p)
{
- struct mixerbar_data *mdp = obj->data.opaque;
int val;
- if (!mdp)
- return;
-
if (chan < 0)
- val = mixer_get_left(mdp->l);
+ val = mixer_get_left(obj->data.i);
else if (chan == 0)
- val = mixer_get_avg(mdp->l);
+ val = mixer_get_avg(obj->data.i);
else
- val = mixer_get_right(mdp->l);
+ val = mixer_get_right(obj->data.i);
- new_bar(p, mdp->w, mdp->h, mixer_to_255(mdp->l, val));
+ new_bar(obj, p, mixer_to_255(obj->data.i, val));
}
#endif /* X11 */
void parse_net_stat_bar_arg(struct text_object *obj, const char *arg, void *free_at_crash)
{
- SIZE_DEFAULTS(bar);
if (arg) {
- arg = scan_bar(arg, &obj->a, &obj->b);
+ arg = scan_bar(obj, arg);
obj->data.opaque = get_net_stat(arg, obj, free_at_crash);
} else {
// default to DEFAULTNETDEV
#ifdef X11
if(output_methods & TO_X) {
- new_bar(p, obj->a, obj->b, ((double) ns->link_qual /
+ new_bar(obj, p, ((double) ns->link_qual /
ns->link_qual_max) * 255.0);
} else
#endif /* X11 */
- {
- if(!obj->a) obj->a = DEFAULT_BAR_WIDTH_NO_X;
- new_bar_in_shell(p, p_max_size, ((double) ns->link_qual /
- ns->link_qual_max) * 100.0, obj->a);
- }
+ new_bar_in_shell(obj, p, p_max_size, ((double) ns->link_qual /
+ ns->link_qual_max) * 100.0);
}
#endif /* HAVE_IWLIB */
#endif /* __linux__ */
#endif /* X11 */
/*
+ * Special data typedefs
+ */
+
+struct bar {
+ int width, height;
+};
+
+/*
* Scanning arguments to various special text objects
*/
}
#endif /* X11 */
-const char *scan_bar(const char *args, int *w, int *h)
+const char *scan_bar(struct text_object *obj, const char *args)
{
+ struct bar *b;
+
+ b = malloc(sizeof(struct bar));
+ memset(b, 0, sizeof(struct bar));
+
/* zero width means all space that is available */
- *w = default_bar_width;
- *h = default_bar_height;
+ b->width = default_bar_width;
+ b->height = default_bar_height;
/* bar's argument is either height or height,width */
if (args) {
int n = 0;
- if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
- sscanf(args, "%d %n", h, &n);
+ if (sscanf(args, "%d,%d %n", &b->height, &b->width, &n) <= 1) {
+ sscanf(args, "%d %n", &b->height, &n);
}
args += n;
}
+ obj->special_data = b;
return args;
}
s->height = h;
}
-void new_bar(char *buf, int w, int h, int usage)
+void new_bar(struct text_object *obj, char *buf, int usage)
{
struct special_t *s = 0;
+ struct bar *b = obj->special_data;
if ((output_methods & TO_X) == 0)
return;
+ if (!b)
+ return;
+
s = new_special(buf, BAR);
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
- s->width = w;
- s->height = h;
+ s->width = b->width;
+ s->height = b->height;
}
void new_font(char *buf, char *args)
}
#endif /* X11 */
-void new_bar_in_shell(char* buffer, int buf_max_size, double usage, int width)
+void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
{
+ struct bar *b = obj->special_data;
+ int width;
+
+ if (!b)
+ return;
+
+ width = b->width;
+ if (!width)
+ width = DEFAULT_BAR_WIDTH_NO_X;
+
if(width<=buf_max_size){
int i = 0, j = 0, scaledusage = round_to_int( usage * width / 100);
obj->b = default_##arg##_height; \
}
+/* forward declare to avoid mutual inclusion between specials.h and text_object.h */
+struct text_object;
+
/* max number of specials allowed (TODO: use linked list instead) */
extern int max_specials;
/* scanning special arguments */
-const char *scan_bar(const char *, int *, int *);
+const char *scan_bar(struct text_object *, const char *);
#ifdef X11
const char *scan_gauge(const char *, int *, int *);
char *scan_font(const char *);
/* printing specials */
void new_gauge(char *, int, int, int);
-void new_bar(char *, int, int, int);
+void new_bar(struct text_object *, char *, int);
void new_font(char *, char *);
void new_graph(char *, int, int, unsigned int,
unsigned int, double, int, int, char, char);
void new_hr(char *, int);
void new_stippled_hr(char *, int, int);
#endif
-void new_bar_in_shell(char *, int, double, int);
+void new_bar_in_shell(struct text_object *, char *, int, double);
void new_fg(char *, long);
void new_bg(char *, long);
void new_outline(char *, long);
#define _TEXT_OBJECT_H
#include "config.h" /* for the defines */
+#include "specials.h" /* enum special_types */
enum text_object_type {
OBJ_read_tcp,
} pair; /* 2 */
} data;
+
+ void *special_data;
int type;
int a, b;
long line;