mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 18:45:10 +00:00
realise seamless integration of new_bar_in_shell
The decision about whether to print ASCII or X11 bar is done from within specials.c, so all those #ifdef + if () blocks can be dropped. This also implicitly enables the ASCII bar for some bar printing objects which where forgotten before.
This commit is contained in:
parent
c131c1d129
commit
c2eb77c3f0
52
src/conky.c
52
src/conky.c
@ -870,12 +870,7 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
percent_print(p, p_max_size, get_battery_perct(obj->data.s));
|
||||
}
|
||||
OBJ(battery_bar) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
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);
|
||||
new_bar(obj, p, p_max_size, get_battery_perct_bar(obj->data.s));
|
||||
}
|
||||
OBJ(battery_short) {
|
||||
get_battery_short_status(p, p_max_size, obj->data.s);
|
||||
@ -905,12 +900,7 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
|
||||
#endif /* X11 */
|
||||
OBJ(cpubar) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
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));
|
||||
new_bar(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(cpugraph) {
|
||||
@ -1385,12 +1375,7 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
#endif /* X11 */
|
||||
OBJ(membar) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
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);
|
||||
new_bar(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(memgraph) {
|
||||
@ -1407,7 +1392,6 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(mixerr) {
|
||||
print_mixerr(obj, p, p_max_size);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(mixerbar) {
|
||||
print_mixer_bar(obj, p, p_max_size);
|
||||
}
|
||||
@ -1417,7 +1401,6 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(mixerrbar) {
|
||||
print_mixerr_bar(obj, p, p_max_size);
|
||||
}
|
||||
#endif /* X11 */
|
||||
OBJ(if_mixer_mute) {
|
||||
if (!check_mixer_muted(obj)) {
|
||||
DO_JUMP;
|
||||
@ -1835,12 +1818,7 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
}
|
||||
OBJ(swapbar) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
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);
|
||||
new_bar(obj, p, p_max_size, cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
|
||||
}
|
||||
OBJ(sysname) {
|
||||
snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
|
||||
@ -2076,11 +2054,9 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(xmms2_percent) {
|
||||
snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(xmms2_bar) {
|
||||
new_bar(obj, p, (int) (cur->xmms2.progress * 255.0f));
|
||||
new_bar(obj, p, p_max_size, (int) (cur->xmms2.progress * 255.0f));
|
||||
}
|
||||
#endif /* X11 */
|
||||
OBJ(xmms2_playlist) {
|
||||
snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
|
||||
}
|
||||
@ -2156,16 +2132,14 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
snprintf(p, p_max_size, "%s",
|
||||
cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(audacious_bar) {
|
||||
double progress;
|
||||
|
||||
progress =
|
||||
atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
|
||||
atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
|
||||
new_bar(obj, p, (int) (progress * 255.0f));
|
||||
new_bar(obj, p, p_max_size, (int) (progress * 255.0f));
|
||||
}
|
||||
#endif /* X11 */
|
||||
#endif /* AUDACIOUS */
|
||||
|
||||
#ifdef BMPX
|
||||
@ -2263,11 +2237,9 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(smapi_bat_power) {
|
||||
print_smapi_bat_power(obj, p, p_max_size);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(smapi_bat_bar) {
|
||||
print_smapi_bat_bar(obj, p, p_max_size);
|
||||
}
|
||||
#endif /* X11 */
|
||||
#endif /* IBM */
|
||||
OBJ(include) {
|
||||
if(obj->sub) {
|
||||
@ -2352,16 +2324,8 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
OBJ(apcupsd_loadbar) {
|
||||
double progress;
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_bar(obj, p, (int) progress);
|
||||
} else
|
||||
#endif /* X11 */
|
||||
{
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
|
||||
new_bar_in_shell(obj, p, p_max_size, (int) progress);
|
||||
}
|
||||
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
|
||||
new_bar(obj, p, p_max_size, (int) progress);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(apcupsd_loadgraph) {
|
||||
|
@ -628,14 +628,12 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
parse_mixer_arg(obj, arg);
|
||||
END OBJ(mixerr, 0)
|
||||
parse_mixer_arg(obj, arg);
|
||||
#ifdef X11
|
||||
END OBJ(mixerbar, 0)
|
||||
scan_mixer_bar(obj, arg);
|
||||
END OBJ(mixerlbar, 0)
|
||||
scan_mixer_bar(obj, arg);
|
||||
END OBJ(mixerrbar, 0)
|
||||
scan_mixer_bar(obj, arg);
|
||||
#endif
|
||||
END OBJ_IF(if_mixer_mute, 0)
|
||||
parse_mixer_arg(obj, arg);
|
||||
#ifdef X11
|
||||
@ -875,7 +873,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
obj->data.s = strndup(arg, text_buffer_size);
|
||||
END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument")
|
||||
obj->data.s = strndup(arg, text_buffer_size);
|
||||
#ifdef X11
|
||||
END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument")
|
||||
int cnt;
|
||||
if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
|
||||
@ -883,7 +880,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
obj->data.i = -1;
|
||||
} else
|
||||
arg = scan_bar(obj, arg + cnt);
|
||||
#endif /* X11 */
|
||||
#endif /* IBM */
|
||||
#ifdef MPD
|
||||
#define mpd_set_maxlen(name) \
|
||||
@ -960,10 +956,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
END OBJ(xmms2_size, &update_xmms2)
|
||||
END OBJ(xmms2_status, &update_xmms2)
|
||||
END OBJ(xmms2_percent, &update_xmms2)
|
||||
#ifdef X11
|
||||
END OBJ(xmms2_bar, &update_xmms2)
|
||||
scan_bar(obj, arg);
|
||||
#endif /* X11 */
|
||||
END OBJ(xmms2_smart, &update_xmms2)
|
||||
END OBJ(xmms2_playlist, &update_xmms2)
|
||||
END OBJ(xmms2_timesplayed, &update_xmms2)
|
||||
@ -989,10 +983,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
END OBJ(audacious_playlist_length, &update_audacious)
|
||||
END OBJ(audacious_playlist_position, &update_audacious)
|
||||
END OBJ(audacious_main_volume, &update_audacious)
|
||||
#ifdef X11
|
||||
END OBJ(audacious_bar, &update_audacious)
|
||||
scan_bar(obj, arg);
|
||||
#endif /* X11 */
|
||||
#endif
|
||||
#ifdef BMPX
|
||||
END OBJ(bmpx_title, &update_bmpx)
|
||||
|
@ -82,10 +82,5 @@ void print_entropy_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
|
||||
ratio = (double) entropy.avail /
|
||||
(double) entropy.poolsize;
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
new_bar(obj, p, (int) (ratio * 255.0f));
|
||||
} else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, (int) (ratio * 100.0f));
|
||||
new_bar(obj, p, p_max_size, (int) (ratio * 255.0f));
|
||||
}
|
||||
|
16
src/exec.c
16
src/exec.c
@ -441,13 +441,8 @@ void print_execbar(struct text_object *obj, char *p, int p_max_size)
|
||||
barnum = get_barnum(p);
|
||||
|
||||
if (barnum >= 0.0) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
barnum /= 100;
|
||||
new_bar(obj, p, round_to_int(barnum * 255.0));
|
||||
}else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, barnum);
|
||||
barnum /= 100;
|
||||
new_bar(obj, p, p_max_size, round_to_int(barnum * 255.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,12 +463,7 @@ void print_execibar(struct text_object *obj, char *p, int p_max_size)
|
||||
}
|
||||
ed->last_update = current_update_time;
|
||||
}
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
new_bar(obj, p, round_to_int(ed->barnum * 2.55));
|
||||
} else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, round_to_int(ed->barnum));
|
||||
new_bar(obj, p, p_max_size, round_to_int(ed->barnum * 2.55));
|
||||
}
|
||||
|
||||
void free_exec(struct text_object *obj)
|
||||
|
7
src/fs.c
7
src/fs.c
@ -225,12 +225,7 @@ void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_s
|
||||
if (!be_free_bar)
|
||||
val = 1.0 - val;
|
||||
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
new_bar(obj, p, (int)(255 * val));
|
||||
}else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, (int)(100 * val));
|
||||
new_bar(obj, p, p_max_size, (int)(255 * val));
|
||||
}
|
||||
|
||||
void init_fs(struct text_object *obj, const char *arg)
|
||||
|
@ -550,12 +550,7 @@ void print_lua_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
double per;
|
||||
if (llua_getnumber(obj->data.s, &per)) {
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
new_bar(obj, p, (per/100.0 * 255));
|
||||
} else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, per);
|
||||
new_bar(obj, p, p_max_size, (per/100.0 * 255));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ static void print_mixer_bar_chan(struct text_object *obj, int chan, char *p, int
|
||||
else
|
||||
val = mixer_get_right(obj->data.i);
|
||||
|
||||
new_bar(obj, p, mixer_to_255(obj->data.i, val));
|
||||
new_bar(obj, p, p_max_size, mixer_to_255(obj->data.i, val));
|
||||
}
|
||||
|
||||
void print_mixer_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
|
@ -367,12 +367,7 @@ void print_mpd_percent(struct text_object *obj, char *p, int p_max_size)
|
||||
|
||||
void print_mpd_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
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));
|
||||
new_bar(obj, p, p_max_size, (int) (mpd_get_info()->progress * 255.0f));
|
||||
}
|
||||
|
||||
void print_mpd_smart(struct text_object *obj, char *p, int p_max_size)
|
||||
|
@ -305,14 +305,8 @@ void print_wireless_link_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
if (!ns)
|
||||
return;
|
||||
|
||||
#ifdef X11
|
||||
if(output_methods & TO_X) {
|
||||
new_bar(obj, p, ((double) ns->link_qual /
|
||||
ns->link_qual_max) * 255.0);
|
||||
} else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, ((double) ns->link_qual /
|
||||
ns->link_qual_max) * 100.0);
|
||||
new_bar(obj, p, p_max_size,
|
||||
((double) ns->link_qual / ns->link_qual_max) * 255.0);
|
||||
}
|
||||
#endif /* HAVE_IWLIB */
|
||||
#endif /* __linux__ */
|
||||
|
@ -178,8 +178,8 @@ void print_smapi_bat_bar(struct text_object *obj, char *p, int p_max_size)
|
||||
return;
|
||||
|
||||
if (obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
|
||||
new_bar(obj, p, (int)
|
||||
new_bar(obj, p, p_max_size, (int)
|
||||
(255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
|
||||
else
|
||||
new_bar(obj, p, 0);
|
||||
new_bar(obj, p, p_max_size, 0);
|
||||
}
|
||||
|
@ -264,24 +264,6 @@ void new_gauge(struct text_object *obj, char *buf, int usage)
|
||||
s->height = g->height;
|
||||
}
|
||||
|
||||
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 = b->width;
|
||||
s->height = b->height;
|
||||
}
|
||||
|
||||
void new_font(char *buf, char *args)
|
||||
{
|
||||
if ((output_methods & TO_X) == 0)
|
||||
@ -454,10 +436,10 @@ void new_bg(char *buf, long c)
|
||||
}
|
||||
#endif /* X11 */
|
||||
|
||||
void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, double usage)
|
||||
static 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;
|
||||
int width, i, scaledusage;
|
||||
|
||||
if (!b)
|
||||
return;
|
||||
@ -466,25 +448,54 @@ void new_bar_in_shell(struct text_object *obj, char* buffer, int buf_max_size, d
|
||||
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);
|
||||
if (width > buf_max_size)
|
||||
width = buf_max_size;
|
||||
|
||||
#ifdef HAVE_OPENMP
|
||||
#pragma omp parallel for schedule(dynamic,10)
|
||||
#endif /* HAVE_OPENMP */
|
||||
for(i=0; i<(int)scaledusage; i++) {
|
||||
*(buffer+i)='#';
|
||||
}
|
||||
/* gcc seems to think i is not initialized properly :/ */
|
||||
j = i;
|
||||
#ifdef HAVE_OPENMP
|
||||
#pragma omp parallel for schedule(dynamic,10)
|
||||
#endif /* HAVE_OPENMP */
|
||||
for(i = j/* cheats */; i < width; i++) {
|
||||
*(buffer+i)='_';
|
||||
}
|
||||
*(buffer+i)=0;
|
||||
}
|
||||
scaledusage = round_to_int( usage * width / 255);
|
||||
|
||||
for (i = 0; i < scaledusage; i++)
|
||||
buffer[i] = '#';
|
||||
|
||||
for (; i < width; i++)
|
||||
buffer[i] = '_';
|
||||
|
||||
buffer[i] = 0;
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
static void new_bar_in_x11(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;
|
||||
s->width = b->width;
|
||||
s->height = b->height;
|
||||
}
|
||||
#endif /* X11 */
|
||||
|
||||
/* usage is in range [0,255] */
|
||||
void new_bar(struct text_object *obj, char *p, int p_max_size, int usage)
|
||||
{
|
||||
if (!p_max_size)
|
||||
return;
|
||||
|
||||
usage = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
|
||||
|
||||
#ifdef X11
|
||||
if ((output_methods & TO_X))
|
||||
new_bar_in_x11(obj, p, usage);
|
||||
else
|
||||
#endif /* X11 */
|
||||
new_bar_in_shell(obj, p, p_max_size, usage);
|
||||
}
|
||||
|
||||
void new_outline(char *buf, long c)
|
||||
|
@ -104,13 +104,12 @@ void scan_stippled_hr(struct text_object *, const char*);
|
||||
|
||||
/* printing specials */
|
||||
void new_gauge(struct text_object *, char *, int);
|
||||
void new_bar(struct text_object *, char *, int);
|
||||
void new_bar(struct text_object *, char *, int, int);
|
||||
void new_font(char *, char *);
|
||||
void new_graph(struct text_object *, char *, double);
|
||||
void new_hr(char *, int);
|
||||
void new_stippled_hr(struct text_object *, char *);
|
||||
#endif
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user