diff --git a/src/fs.c b/src/fs.c index c330f612..4575c96a 100644 --- a/src/fs.c +++ b/src/fs.c @@ -58,6 +58,11 @@ #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); } } diff --git a/src/text_object.h b/src/text_object.h index 8bcea1b9..4b38ed5d 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -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;