1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

fs_bar, fs_bar_free: convert to generic object payload

This commit is contained in:
Phil Sutter 2009-10-04 16:12:47 +02:00
parent f6942c8c98
commit f31e5cefe7
2 changed files with 24 additions and 17 deletions

View File

@ -58,6 +58,11 @@
#define MAX_FS_STATS 64 #define MAX_FS_STATS 64
struct fsbar {
struct fs_stat *fs;
int w, h;
};
static struct fs_stat fs_stats_[MAX_FS_STATS]; static struct fs_stat fs_stats_[MAX_FS_STATS];
struct fs_stat *fs_stats = 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) void init_fs_bar(struct text_object *obj, const char *arg)
{ {
SIZE_DEFAULTS(bar); struct fsbar *fb;
arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
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) { if (arg) {
while (isspace(*arg)) { while (isspace(*arg)) {
arg++; arg++;
@ -209,31 +221,31 @@ void init_fs_bar(struct text_object *obj, const char *arg)
} else { } else {
arg = "/"; 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) 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; return;
if (!obj->data.fsbar.fs->size) if (fb->fs->size)
val = 1.0; val = (double)fb->fs->avail / (double)fb->fs->size;
else
val = (double)obj->data.fsbar.fs->avail / (double)obj->data.fsbar.fs->size;
if (!be_free_bar) if (!be_free_bar)
val = 1.0 - val; val = 1.0 - val;
#ifdef X11 #ifdef X11
if(output_methods & TO_X) { 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 }else
#endif /* X11 */ #endif /* X11 */
{ {
if(!obj->data.fsbar.w) obj->data.fsbar.w = DEFAULT_BAR_WIDTH_NO_X; if(!fb->w) fb->w = DEFAULT_BAR_WIDTH_NO_X;
new_bar_in_shell(p, p_max_size, (int)(100 * val), obj->data.fsbar.w); new_bar_in_shell(p, p_max_size, (int)(100 * val), fb->w);
} }
} }

View File

@ -455,11 +455,6 @@ struct text_object {
char *output; char *output;
} mboxscan; } mboxscan;
struct {
struct fs_stat *fs;
int w, h;
} fsbar; /* 3 */
#ifdef X11 #ifdef X11
struct { struct {
int l; int l;