specials: introduce dedicated per-object data and merge graph objects
authorPhil Sutter <phil@nwl.cc>
Sun, 25 Oct 2009 20:47:47 +0000 (21:47 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 3 Nov 2009 22:23:23 +0000 (23:23 +0100)
src/conky.c
src/core.c
src/exec.c
src/fs.c
src/mixer.c
src/net_stat.c
src/specials.c
src/specials.h
src/text_object.h

index 77d8ec6..4d77aa3 100644 (file)
@@ -894,14 +894,10 @@ void generate_text_internal(char *p, int p_max_size,
                        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);
@@ -931,15 +927,10 @@ void generate_text_internal(char *p, int p_max_size,
                        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) {
@@ -1330,14 +1321,10 @@ void generate_text_internal(char *p, int p_max_size,
                                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
@@ -1488,15 +1475,10 @@ void generate_text_internal(char *p, int p_max_size,
                        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) {
@@ -1652,15 +1634,10 @@ void generate_text_internal(char *p, int p_max_size,
                        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);
@@ -1785,15 +1762,10 @@ void generate_text_internal(char *p, int p_max_size,
                        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();
@@ -1916,8 +1888,7 @@ void generate_text_internal(char *p, int p_max_size,
                        }
 #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) {
@@ -2002,7 +1973,7 @@ void generate_text_internal(char *p, int p_max_size,
                                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 */
@@ -2130,14 +2101,10 @@ void generate_text_internal(char *p, int p_max_size,
                                        (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) {
@@ -2189,10 +2156,10 @@ void generate_text_internal(char *p, int p_max_size,
 #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 */
@@ -2282,15 +2249,13 @@ void generate_text_internal(char *p, int p_max_size,
 #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) {
index 3a600d8..e37ed99 100644 (file)
@@ -269,10 +269,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                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");
@@ -353,9 +351,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                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)
@@ -474,7 +471,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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)
@@ -485,7 +481,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                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")
@@ -650,8 +645,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                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;
@@ -715,8 +709,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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);
@@ -793,14 +786,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #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
@@ -840,8 +830,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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);
@@ -881,8 +870,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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)
@@ -911,8 +899,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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
@@ -955,8 +942,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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 {
@@ -996,8 +982,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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) {
@@ -1047,8 +1032,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        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;
index a8dfd0c..4e1f9ba 100644 (file)
@@ -446,13 +446,10 @@ void print_execbar(struct text_object *obj, char *p, int p_max_size)
 #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);
        }
 }
 
@@ -475,13 +472,10 @@ void print_execibar(struct text_object *obj, char *p, int p_max_size)
        }
 #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)
index fefda8b..92552e9 100644 (file)
--- a/src/fs.c
+++ b/src/fs.c
 
 #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_;
 
@@ -202,15 +197,7 @@ void get_fs_type(const char *path, char *result)
 
 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++;
@@ -221,33 +208,29 @@ void init_fs_bar(struct text_object *obj, const char *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)
index d39b0d4..1e3d962 100644 (file)
@@ -311,46 +311,32 @@ int check_mixer_muted(struct text_object *obj)
 }
 
 #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 */
index 663fe0b..8fd3c0a 100644 (file)
@@ -80,9 +80,8 @@ void parse_net_stat_arg(struct text_object *obj, const char *arg, void *free_at_
 
 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
@@ -310,15 +309,12 @@ void print_wireless_link_bar(struct text_object *obj, char *p, int p_max_size)
 
 #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__ */
index cdd8725..8c4b4ae 100644 (file)
@@ -52,6 +52,14 @@ int default_gauge_width = 40, default_gauge_height = 25;
 #endif /* X11 */
 
 /*
+ * Special data typedefs
+ */
+
+struct bar {
+       int width, height;
+};
+
+/*
  * Scanning arguments to various special text objects
  */
 
@@ -78,21 +86,27 @@ const char *scan_gauge(const char *args, int *w, int *h)
 }
 #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;
 }
 
@@ -216,18 +230,22 @@ void new_gauge(char *buf, int w, int h, int usage)
        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)
@@ -376,8 +394,18 @@ void new_bg(char *buf, long c)
 }
 #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);
 
index c659c1a..a09bda1 100644 (file)
@@ -92,11 +92,14 @@ extern int default_gauge_height;
        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 *);
@@ -105,14 +108,14 @@ char *scan_graph(const char *, int *, int *, unsigned int *,
 
 /* 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);
index c7af24a..3395abc 100644 (file)
@@ -30,6 +30,7 @@
 #define _TEXT_OBJECT_H
 
 #include "config.h"            /* for the defines */
+#include "specials.h"          /* enum special_types */
 
 enum text_object_type {
        OBJ_read_tcp,
@@ -448,6 +449,8 @@ struct text_object {
                } pair;                 /* 2 */
 
        } data;
+
+       void *special_data;
        int type;
        int a, b;
        long line;