From: Brendan Van Hook Date: Fri, 2 Oct 2015 06:28:53 +0000 (-0400) Subject: Added support for lemonbar X-Git-Tag: 2.10~10^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F68%2Fhead;p=i3%2Fi3status Added support for lemonbar --- diff --git a/i3status.c b/i3status.c index 000584a..462721b 100644 --- a/i3status.c +++ b/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) { - if (strlen(value) != 7) - return 0; + const int len = strlen(value); + + 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] != '#') return 0; - for (int i = 1; i < 7; ++i) { + for (int i = 1; i < len; ++i) { if (value[i] >= '0' && value[i] <= '9') continue; if (value[i] >= 'a' && value[i] <= 'f') @@ -501,6 +511,8 @@ int main(int argc, char *argv[]) { output_format = O_XMOBAR; else if (strcasecmp(output_str, "i3bar") == 0) output_format = O_I3BAR; + else if (strcasecmp(output_str, "lemonbar") == 0) + output_format = O_LEMONBAR; else if (strcasecmp(output_str, "term") == 0) output_format = O_TERM; 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"); + /* 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 (strcasecmp(separator, "default") == 0) separator = get_default_separator(); diff --git a/include/i3status.h b/include/i3status.h index 024f254..037e154 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -4,9 +4,12 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, + O_LEMONBAR, O_TERM, O_NONE } output_format; +char *pct_mark; + #include #include #include diff --git a/man/i3status.man b/man/i3status.man index b7eddb7..d550b81 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -5,7 +5,7 @@ v2.9, March 2015 == NAME -i3status - Generates a status line for i3bar, dzen2 or xmobar +i3status - Generates a status line for i3bar, dzen2, xmobar or lemonbar == SYNOPSIS @@ -25,7 +25,7 @@ configuration files in the following order: == DESCRIPTION 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 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 @@ -157,6 +157,9 @@ managers like dwm, wmii and xmonad though it will work with any windowmanger xmobar:: xmobar is a minimalistic, text based, status bar. It was designed to work 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:: 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 diff --git a/src/output.c b/src/output.c index b2fb1dd..f7a8888 100644 --- a/src/output.c +++ b/src/output.c @@ -11,7 +11,8 @@ #include "i3status.h" /* - * Returns the correct color format for dzen (^fg(color)) or xmobar () + * Returns the correct color format for dzen (^fg(color)), xmobar () + * or lemonbar (%{Fcolor}) * */ 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)); else if (output_format == O_XMOBAR) (void)snprintf(colorbuf, sizeof(colorbuf), "", 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) { /* The escape-sequence for color is ;1m (bright/bold * 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); else if (output_format == O_XMOBAR) printf("%s", 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) printf("%s%s%s", color("color_separator"), separator, endcolor()); else if (output_format == O_NONE) diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 0853e18..f65090a 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -146,9 +146,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char percentage_remaining = 100; } if (integer_battery_capacity) { - (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining); + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%s", percentage_remaining, pct_mark); } else { - (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%s", percentage_remaining, pct_mark); } 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(percentagebuf, sizeof(percentagebuf), "%02d%%", - present_rate); + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s", + present_rate, pct_mark); if (state == 1) { 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)); /* 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 (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) (void)snprintf(percentagebuf, sizeof(percentagebuf), - "%d%%", - (int)percentage_remaining); + "%d%s", + (int)percentage_remaining, pct_mark); else (void)snprintf(percentagebuf, sizeof(percentagebuf), - "%.02f%%", - percentage_remaining); + "%.02f%s", + percentage_remaining, pct_mark); /* * Handle percentage low_threshold here, and time low_threshold when diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c index 927e763..adf2d04 100644 --- a/src/print_cpu_usage.c +++ b/src/print_cpu_usage.c @@ -102,7 +102,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format) { } if (BEGINS_WITH(walk + 1, "usage")) { - outwalk += sprintf(outwalk, "%02d%%", diff_usage); + outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark); walk += strlen("usage"); } } diff --git a/src/print_disk_info.c b/src/print_disk_info.c index e5e3ab1..12d7585 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -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")) { - 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"); } 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"); } 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"); } 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"); } } diff --git a/src/print_volume.c b/src/print_volume.c index 86b3505..58cba2a 100644 --- a/src/print_volume.c +++ b/src/print_volume.c @@ -37,11 +37,11 @@ static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) { continue; } if (BEGINS_WITH(walk + 1, "%")) { - outwalk += sprintf(outwalk, "%%"); + outwalk += sprintf(outwalk, "%s", pct_mark); walk += strlen("%"); } if (BEGINS_WITH(walk + 1, "volume")) { - outwalk += sprintf(outwalk, "%d%%", ivolume); + outwalk += sprintf(outwalk, "%d%s", ivolume, pct_mark); walk += strlen("volume"); } } diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index 48d81d4..4639625 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -480,7 +480,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, if (BEGINS_WITH(walk + 1, "quality")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) { 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 outwalk += sprintf(outwalk, "%d", info.quality); } 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 (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) { 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 outwalk += sprintf(outwalk, "%d dBm", info.signal_level); } 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 (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) { 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 outwalk += sprintf(outwalk, "%d dBm", info.noise_level); } else {