]> git.sur5r.net Git - i3/i3status/commitdiff
Added support for lemonbar 68/head
authorBrendan Van Hook <me@bsvh.me>
Fri, 2 Oct 2015 06:28:53 +0000 (02:28 -0400)
committerBrendan Van Hook <me@bsvh.me>
Sun, 4 Oct 2015 18:52:32 +0000 (14:52 -0400)
i3status.c
include/i3status.h
man/i3status.man
src/output.c
src/print_battery_info.c
src/print_cpu_usage.c
src/print_disk_info.c
src/print_volume.c
src/print_wireless_info.c

index 000584a8405d861cf678b296dc02dc04557e8b0d..462721b9055005234ae6096845b7d2e4bf2e6e2a 100644 (file)
@@ -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)
-        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;
     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')
         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;
         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)
     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");
 
 
     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();
     // if no custom separator has been provided, use the default one
     if (strcasecmp(separator, "default") == 0)
         separator = get_default_separator();
index 024f2541146feb3f698304614cff7d375c8cd7a9..037e1545eda3e7df6af7595317fbf6493116bc66 100644 (file)
@@ -4,9 +4,12 @@
 enum { O_DZEN2,
        O_XMOBAR,
        O_I3BAR,
 enum { O_DZEN2,
        O_XMOBAR,
        O_I3BAR,
+       O_LEMONBAR,
        O_TERM,
        O_NONE } output_format;
 
        O_TERM,
        O_NONE } output_format;
 
+char *pct_mark;
+
 #include <stdbool.h>
 #include <confuse.h>
 #include <time.h>
 #include <stdbool.h>
 #include <confuse.h>
 #include <time.h>
index b7eddb7b2e41c428fc370b277881fe35e83a29cf..d550b812ce2fa0418116c6c8ae4c0edfdd3ed0c2 100644 (file)
@@ -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
 
 i3status is a small program (about 1500 SLOC) for generating a status bar for
 == 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
 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.
 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
 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
index b2fb1dd758f05a9b9265771305b577b00b6593eb..f7a88887a3ca9f6b07a798923ad9dd1f9065605b 100644 (file)
@@ -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));
     else if (output_format == O_XMOBAR)
         (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
         (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr));
     else if (output_format == O_XMOBAR)
         (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) {
         /* The escape-sequence for color is <CSI><col>;1m (bright/bold
          * output), where col is a 3-bit rgb-value with b in the
     else if (output_format == O_TERM) {
         /* The escape-sequence for color is <CSI><col>;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("<fc=%s>%s</fc>", 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)
         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)
         printf("%s%s%s", color("color_separator"), separator, endcolor());
     else if (output_format == O_NONE)
     else if (output_format == O_TERM)
         printf("%s%s%s", color("color_separator"), separator, endcolor());
     else if (output_format == O_NONE)
index 0853e18a862f92829233619e9d9a46e8ac6d8c3d..f65090a4864d9186a892b55da485d27556403c63 100644 (file)
@@ -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) {
         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 {
     } 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%%",
-                   present_rate);
+    (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s",
+                   present_rate, pct_mark);
 
     if (state == 1) {
         int hours, minutes;
 
     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(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) {
 
     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),
     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),
     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
 
     /*
      * Handle percentage low_threshold here, and time low_threshold when
index 927e763891eb78408d295d933db69ba07421603e..adf2d046f2179c74b021f05f7aa8310084316aa4 100644 (file)
@@ -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");
         }
     }
index e5e3ab17587acdc52333adc8e604c581b6b90f7f..12d75857cf8dce882a19521d9726473877c9f972 100644 (file)
@@ -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");
         }
 
         if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
             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")) {
             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")) {
             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");
         }
     }
             walk += strlen("percentage_avail");
         }
     }
index 86b3505713303d304d31bff1676c8cd6c20c0c1b..58cba2a85b71a1c1de0e74869d8c371ad5a65793 100644 (file)
@@ -37,11 +37,11 @@ static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) {
             continue;
         }
         if (BEGINS_WITH(walk + 1, "%")) {
             continue;
         }
         if (BEGINS_WITH(walk + 1, "%")) {
-            outwalk += sprintf(outwalk, "%%");
+            outwalk += sprintf(outwalk, "%s", pct_mark);
             walk += strlen("%");
         }
         if (BEGINS_WITH(walk + 1, "volume")) {
             walk += strlen("%");
         }
         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");
         }
     }
index 48d81d4c9d70427864655a989736b7c3a5873bd6..463962517c30febaf1354d62a9be3ea5501c9a7d 100644 (file)
@@ -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)
         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 {
                 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)
         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 {
                 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)
         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 {
                 else
                     outwalk += sprintf(outwalk, "%d dBm", info.noise_level);
             } else {