Added support for lemonbar
This commit is contained in:
parent
f3125fdfde
commit
a13b2e7288
21
i3status.c
21
i3status.c
@ -163,11 +163,21 @@ static int parse_min_width(cfg_t *context, cfg_opt_t *option, const char *value,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int valid_color(const char *value) {
|
static int valid_color(const char *value) {
|
||||||
if (strlen(value) != 7)
|
const int len = strlen(value);
|
||||||
return 0;
|
|
||||||
|
if (output_format == O_LEMONBAR) {
|
||||||
|
/* lemonbar supports an optional alpha channel */
|
||||||
|
if (len != strlen("#rrggbb") && len != strlen("#aarrggbb")) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (len != strlen("#rrggbb")) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (value[0] != '#')
|
if (value[0] != '#')
|
||||||
return 0;
|
return 0;
|
||||||
for (int i = 1; i < 7; ++i) {
|
for (int i = 1; i < len; ++i) {
|
||||||
if (value[i] >= '0' && value[i] <= '9')
|
if (value[i] >= '0' && value[i] <= '9')
|
||||||
continue;
|
continue;
|
||||||
if (value[i] >= 'a' && value[i] <= 'f')
|
if (value[i] >= 'a' && value[i] <= 'f')
|
||||||
@ -501,6 +511,8 @@ int main(int argc, char *argv[]) {
|
|||||||
output_format = O_XMOBAR;
|
output_format = O_XMOBAR;
|
||||||
else if (strcasecmp(output_str, "i3bar") == 0)
|
else if (strcasecmp(output_str, "i3bar") == 0)
|
||||||
output_format = O_I3BAR;
|
output_format = O_I3BAR;
|
||||||
|
else if (strcasecmp(output_str, "lemonbar") == 0)
|
||||||
|
output_format = O_LEMONBAR;
|
||||||
else if (strcasecmp(output_str, "term") == 0)
|
else if (strcasecmp(output_str, "term") == 0)
|
||||||
output_format = O_TERM;
|
output_format = O_TERM;
|
||||||
else if (strcasecmp(output_str, "none") == 0)
|
else if (strcasecmp(output_str, "none") == 0)
|
||||||
@ -510,6 +522,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
const char *separator = cfg_getstr(cfg_general, "separator");
|
const char *separator = cfg_getstr(cfg_general, "separator");
|
||||||
|
|
||||||
|
/* lemonbar needs % to be escaped with another % */
|
||||||
|
pct_mark = (output_format == O_LEMONBAR) ? "%%" : "%";
|
||||||
|
|
||||||
// if no custom separator has been provided, use the default one
|
// if no custom separator has been provided, use the default one
|
||||||
if (strcasecmp(separator, "default") == 0)
|
if (strcasecmp(separator, "default") == 0)
|
||||||
separator = get_default_separator();
|
separator = get_default_separator();
|
||||||
|
@ -4,9 +4,12 @@
|
|||||||
enum { O_DZEN2,
|
enum { O_DZEN2,
|
||||||
O_XMOBAR,
|
O_XMOBAR,
|
||||||
O_I3BAR,
|
O_I3BAR,
|
||||||
|
O_LEMONBAR,
|
||||||
O_TERM,
|
O_TERM,
|
||||||
O_NONE } output_format;
|
O_NONE } output_format;
|
||||||
|
|
||||||
|
char *pct_mark;
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <confuse.h>
|
#include <confuse.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -5,7 +5,7 @@ v2.9, March 2015
|
|||||||
|
|
||||||
== NAME
|
== NAME
|
||||||
|
|
||||||
i3status - Generates a status line for i3bar, dzen2 or xmobar
|
i3status - Generates a status line for i3bar, dzen2, xmobar or lemonbar
|
||||||
|
|
||||||
== SYNOPSIS
|
== SYNOPSIS
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ configuration files in the following order:
|
|||||||
== DESCRIPTION
|
== DESCRIPTION
|
||||||
|
|
||||||
i3status is a small program (about 1500 SLOC) for generating a status bar for
|
i3status is a small program (about 1500 SLOC) for generating a status bar for
|
||||||
i3bar, dzen2, xmobar or similar programs. It is designed to be very
|
i3bar, dzen2, xmobar, lemonbar or similar programs. It is designed to be very
|
||||||
efficient by issuing a very small number of system calls, as one generally
|
efficient by issuing a very small number of system calls, as one generally
|
||||||
wants to update such a status line every second. This ensures that even under
|
wants to update such a status line every second. This ensures that even under
|
||||||
high load, your status bar is updated correctly. Also, it saves a bit of energy
|
high load, your status bar is updated correctly. Also, it saves a bit of energy
|
||||||
@ -157,6 +157,9 @@ managers like dwm, wmii and xmonad though it will work with any windowmanger
|
|||||||
xmobar::
|
xmobar::
|
||||||
xmobar is a minimalistic, text based, status bar. It was designed to work
|
xmobar is a minimalistic, text based, status bar. It was designed to work
|
||||||
with the xmonad Window Manager.
|
with the xmonad Window Manager.
|
||||||
|
lemonbar::
|
||||||
|
lemonbar is a lightweight bar based entirely on XCB. It has full UTF-8 support
|
||||||
|
and is EWMH compliant.
|
||||||
term::
|
term::
|
||||||
Use ANSI Escape sequences to produce a terminal-output as close as possible to
|
Use ANSI Escape sequences to produce a terminal-output as close as possible to
|
||||||
the graphical outputs. This makes debugging your config file a little bit
|
the graphical outputs. This makes debugging your config file a little bit
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
#include "i3status.h"
|
#include "i3status.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the correct color format for dzen (^fg(color)) or xmobar (<fc=color>)
|
* Returns the correct color format for dzen (^fg(color)), xmobar (<fc=color>)
|
||||||
|
* or lemonbar (%{Fcolor})
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char *color(const char *colorstr) {
|
char *color(const char *colorstr) {
|
||||||
@ -24,6 +25,8 @@ char *color(const char *colorstr) {
|
|||||||
(void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr));
|
(void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr));
|
||||||
else if (output_format == O_XMOBAR)
|
else if (output_format == O_XMOBAR)
|
||||||
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
|
(void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
|
||||||
|
else if (output_format == O_LEMONBAR)
|
||||||
|
(void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%s}", cfg_getstr(cfg_general, colorstr));
|
||||||
else if (output_format == O_TERM) {
|
else if (output_format == O_TERM) {
|
||||||
/* The escape-sequence for color is <CSI><col>;1m (bright/bold
|
/* The escape-sequence for color is <CSI><col>;1m (bright/bold
|
||||||
* output), where col is a 3-bit rgb-value with b in the
|
* output), where col is a 3-bit rgb-value with b in the
|
||||||
@ -61,6 +64,8 @@ void print_separator(const char *separator) {
|
|||||||
printf("^fg(%s)%s^fg()", cfg_getstr(cfg_general, "color_separator"), separator);
|
printf("^fg(%s)%s^fg()", cfg_getstr(cfg_general, "color_separator"), separator);
|
||||||
else if (output_format == O_XMOBAR)
|
else if (output_format == O_XMOBAR)
|
||||||
printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
|
printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
|
||||||
|
else if (output_format == O_LEMONBAR)
|
||||||
|
printf("%%{F%s}%s%%{F-}", cfg_getstr(cfg_general, "color_separator"), separator);
|
||||||
else if (output_format == O_TERM)
|
else if (output_format == O_TERM)
|
||||||
printf("%s%s%s", color("color_separator"), separator, endcolor());
|
printf("%s%s%s", color("color_separator"), separator, endcolor());
|
||||||
else if (output_format == O_NONE)
|
else if (output_format == O_NONE)
|
||||||
|
@ -146,9 +146,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
|
|||||||
percentage_remaining = 100;
|
percentage_remaining = 100;
|
||||||
}
|
}
|
||||||
if (integer_battery_capacity) {
|
if (integer_battery_capacity) {
|
||||||
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);
|
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%s", percentage_remaining, pct_mark);
|
||||||
} else {
|
} else {
|
||||||
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
|
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%s", percentage_remaining, pct_mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (present_rate > 0) {
|
if (present_rate > 0) {
|
||||||
@ -245,8 +245,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
|
|||||||
|
|
||||||
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
|
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
|
||||||
|
|
||||||
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
|
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s",
|
||||||
present_rate);
|
present_rate, pct_mark);
|
||||||
|
|
||||||
if (state == 1) {
|
if (state == 1) {
|
||||||
int hours, minutes;
|
int hours, minutes;
|
||||||
@ -304,7 +304,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
|
|||||||
|
|
||||||
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
|
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
|
||||||
/* integer_battery_capacity is implied as battery_life is already in whole numbers. */
|
/* integer_battery_capacity is implied as battery_life is already in whole numbers. */
|
||||||
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
|
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%s", apm_info.battery_life, pct_mark);
|
||||||
|
|
||||||
if (status == CS_DISCHARGING && low_threshold > 0) {
|
if (status == CS_DISCHARGING && low_threshold > 0) {
|
||||||
if (strcasecmp(threshold_type, "percentage") == 0 && apm_info.battery_life < low_threshold) {
|
if (strcasecmp(threshold_type, "percentage") == 0 && apm_info.battery_life < low_threshold) {
|
||||||
@ -494,13 +494,13 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
|
|||||||
if (integer_battery_capacity)
|
if (integer_battery_capacity)
|
||||||
(void)snprintf(percentagebuf,
|
(void)snprintf(percentagebuf,
|
||||||
sizeof(percentagebuf),
|
sizeof(percentagebuf),
|
||||||
"%d%%",
|
"%d%s",
|
||||||
(int)percentage_remaining);
|
(int)percentage_remaining, pct_mark);
|
||||||
else
|
else
|
||||||
(void)snprintf(percentagebuf,
|
(void)snprintf(percentagebuf,
|
||||||
sizeof(percentagebuf),
|
sizeof(percentagebuf),
|
||||||
"%.02f%%",
|
"%.02f%s",
|
||||||
percentage_remaining);
|
percentage_remaining, pct_mark);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle percentage low_threshold here, and time low_threshold when
|
* Handle percentage low_threshold here, and time low_threshold when
|
||||||
|
@ -102,7 +102,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BEGINS_WITH(walk + 1, "usage")) {
|
if (BEGINS_WITH(walk + 1, "usage")) {
|
||||||
outwalk += sprintf(outwalk, "%02d%%", diff_usage);
|
outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark);
|
||||||
walk += strlen("usage");
|
walk += strlen("usage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,22 +179,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (BEGINS_WITH(walk + 1, "percentage_free")) {
|
if (BEGINS_WITH(walk + 1, "percentage_free")) {
|
||||||
outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks);
|
outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks, pct_mark);
|
||||||
walk += strlen("percentage_free");
|
walk += strlen("percentage_free");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
|
if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
|
||||||
outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks);
|
outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks, pct_mark);
|
||||||
walk += strlen("percentage_used_of_avail");
|
walk += strlen("percentage_used_of_avail");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BEGINS_WITH(walk + 1, "percentage_used")) {
|
if (BEGINS_WITH(walk + 1, "percentage_used")) {
|
||||||
outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks);
|
outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks, pct_mark);
|
||||||
walk += strlen("percentage_used");
|
walk += strlen("percentage_used");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BEGINS_WITH(walk + 1, "percentage_avail")) {
|
if (BEGINS_WITH(walk + 1, "percentage_avail")) {
|
||||||
outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks);
|
outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark);
|
||||||
walk += strlen("percentage_avail");
|
walk += strlen("percentage_avail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,11 @@ static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (BEGINS_WITH(walk + 1, "%")) {
|
if (BEGINS_WITH(walk + 1, "%")) {
|
||||||
outwalk += sprintf(outwalk, "%%");
|
outwalk += sprintf(outwalk, "%s", pct_mark);
|
||||||
walk += strlen("%");
|
walk += strlen("%");
|
||||||
}
|
}
|
||||||
if (BEGINS_WITH(walk + 1, "volume")) {
|
if (BEGINS_WITH(walk + 1, "volume")) {
|
||||||
outwalk += sprintf(outwalk, "%d%%", ivolume);
|
outwalk += sprintf(outwalk, "%d%s", ivolume, pct_mark);
|
||||||
walk += strlen("volume");
|
walk += strlen("volume");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
if (BEGINS_WITH(walk + 1, "quality")) {
|
if (BEGINS_WITH(walk + 1, "quality")) {
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
|
||||||
if (info.quality_max)
|
if (info.quality_max)
|
||||||
outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.quality, info.quality_max));
|
outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
|
||||||
else
|
else
|
||||||
outwalk += sprintf(outwalk, "%d", info.quality);
|
outwalk += sprintf(outwalk, "%d", info.quality);
|
||||||
} else {
|
} else {
|
||||||
@ -492,7 +492,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
if (BEGINS_WITH(walk + 1, "signal")) {
|
if (BEGINS_WITH(walk + 1, "signal")) {
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
|
||||||
if (info.signal_level_max)
|
if (info.signal_level_max)
|
||||||
outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.signal_level, info.signal_level_max));
|
outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
|
||||||
else
|
else
|
||||||
outwalk += sprintf(outwalk, "%d dBm", info.signal_level);
|
outwalk += sprintf(outwalk, "%d dBm", info.signal_level);
|
||||||
} else {
|
} else {
|
||||||
@ -504,7 +504,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
|
|||||||
if (BEGINS_WITH(walk + 1, "noise")) {
|
if (BEGINS_WITH(walk + 1, "noise")) {
|
||||||
if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
|
if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
|
||||||
if (info.noise_level_max)
|
if (info.noise_level_max)
|
||||||
outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.noise_level, info.noise_level_max));
|
outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
|
||||||
else
|
else
|
||||||
outwalk += sprintf(outwalk, "%d dBm", info.noise_level);
|
outwalk += sprintf(outwalk, "%d dBm", info.noise_level);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user