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);
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) {
}
#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) {
OBJ(mixerr) {
print_mixerr(obj, p, p_max_size);
}
-#ifdef X11
OBJ(mixerbar) {
print_mixer_bar(obj, p, 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;
}
}
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);
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);
}
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
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) {
}
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) {
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
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) {
obj->data.i = -1;
} else
arg = scan_bar(obj, arg + cnt);
-#endif /* X11 */
#endif /* IBM */
#ifdef MPD
#define mpd_set_maxlen(name) \
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)
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)
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));
}
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));
}
}
}
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)
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)
{
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));
}
}
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)
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)
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__ */
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);
}
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)
}
#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;
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)
/* 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);