fs_bar, fs_bar_free: convert to generic object payload
authorPhil Sutter <phil@nwl.cc>
Sun, 4 Oct 2009 14:12:47 +0000 (16:12 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 3 Nov 2009 22:23:22 +0000 (23:23 +0100)
src/fs.c
src/text_object.h

index c330f61..4575c96 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_;
 
@@ -197,8 +202,15 @@ void get_fs_type(const char *path, char *result)
 
 void init_fs_bar(struct text_object *obj, const char *arg)
 {
-       SIZE_DEFAULTS(bar);
-       arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
+       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);
        if (arg) {
                while (isspace(*arg)) {
                        arg++;
@@ -209,31 +221,31 @@ void init_fs_bar(struct text_object *obj, const char *arg)
        } else {
                arg = "/";
        }
-       obj->data.fsbar.fs = prepare_fs_stat(arg);
+       fb->fs = prepare_fs_stat(arg);
+       obj->data.opaque = fb;
 }
 
 void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size)
 {
-       double val;
+       double val = 1.0;
+       struct fsbar *fb = obj->data.opaque;
 
-       if (!obj->data.fsbar.fs)
+       if (!fb || !fb->fs)
                return;
 
-       if (!obj->data.fsbar.fs->size)
-               val = 1.0;
-       else
-               val = (double)obj->data.fsbar.fs->avail / (double)obj->data.fsbar.fs->size;
+       if (fb->fs->size)
+               val = (double)fb->fs->avail / (double)fb->fs->size;
 
        if (!be_free_bar)
                val = 1.0 - val;
 
 #ifdef X11
                if(output_methods & TO_X) {
-                       new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, (int)(255 * val));
+                       new_bar(p, fb->w, fb->h, (int)(255 * val));
                }else
 #endif /* X11 */
                {
-                       if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X;
-                       new_bar_in_shell(p, p_max_size, (int)(100 * val), obj->data.fsbar.w);
+                       if(!fb->w) fb->w = DEFAULT_BAR_WIDTH_NO_X;
+                       new_bar_in_shell(p, p_max_size, (int)(100 * val), fb->w);
                }
 }
index 8bcea1b..4b38ed5 100644 (file)
@@ -455,11 +455,6 @@ struct text_object {
                        char *output;
                } mboxscan;
 
-               struct {
-                       struct fs_stat *fs;
-                       int w, h;
-               } fsbar;                /* 3 */
-
 #ifdef X11
                struct {
                        int l;