diff options
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | debian/rules | 5 | ||||
-rw-r--r-- | i3status.c | 4 | ||||
-rw-r--r-- | i3status.h | 7 | ||||
-rw-r--r-- | src/config.c | 5 | ||||
-rw-r--r-- | src/get_wireless_info.c | 6 | ||||
-rw-r--r-- | src/output.c | 36 |
7 files changed, 53 insertions, 12 deletions
@@ -13,7 +13,7 @@ CFLAGS+=-D_GNU_SOURCE endif # Define this if you want i3status to spit out dzen2-compatible output on stdout -CFLAGS+=-DDZEN +#CFLAGS+=-DDZEN CFLAGS+=$(EXTRA_CFLAGS) src/%.o: src/%.c diff --git a/debian/rules b/debian/rules index 8843064..3543851 100755 --- a/debian/rules +++ b/debian/rules @@ -16,6 +16,10 @@ build-stamp: # Build with wmii support $(MAKE) cp $(CURDIR)/i3status $(CURDIR)/i3status-wmii + # Build with xmobar support + $(MAKE) distclean + $(MAKE) EXTRA_CFLAGS="-DXMOBAR" + cp $(CURDIR)/i3status $(CURDIR)/i3status-xmobar # Build with dzen support $(MAKE) distclean $(MAKE) EXTRA_CFLAGS="-DDZEN" @@ -36,6 +40,7 @@ install: build dh_installdirs $(MAKE) DESTDIR=$(CURDIR)/debian/i3status/ install install -m 755 $(CURDIR)/i3status-wmii $(CURDIR)/debian/i3status/usr/bin/i3status-wmii + install -m 755 $(CURDIR)/i3status-xmobar $(CURDIR)/debian/i3status/usr/bin/i3status-xmobar dh_link usr/share/man/man1/i3status.1 usr/share/man/man1/i3status-wmii.1 # Build architecture-independent files here. @@ -136,10 +136,10 @@ int main(int argc, char *argv[]) { for (i = 0; i < num_run_watches; i += 2) { bool running = process_runs(run_watches[i+1]); if (use_colors) - snprintf(part, sizeof(part), "%s%s: %s", + snprintf(part, sizeof(part), "%s%s: %s%s", (running ? color("#00FF00") : color("#FF0000")), run_watches[i], - (running ? "yes" : "no")); + (running ? "yes" : "no"), endcolor()); else snprintf(part, sizeof(part), "%s: %s", run_watches[i], (running ? "yes" : "no")); snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]); write_to_statusbar(pathbuf, part, false); @@ -5,7 +5,11 @@ #include "queue.h" -#define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)" +#ifdef DZEN + #define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)" +#elif XMOBAR + #define BAR "<fc=#333333> | </fc>" +#endif #define BEGINS_WITH(haystack, needle) (strncmp(haystack, needle, strlen(needle)) == 0) #define max(a, b) (a > b ? a : b) @@ -55,6 +59,7 @@ bool slurp(char *filename, char *destination, int size); /* src/output.c */ void write_error_to_statusbar(const char *message); char *color(const char *colorstr); +char *endcolor() __attribute__ ((pure)); void cleanup_rbar_dir(); /* src/config.c */ diff --git a/src/config.c b/src/config.c index 2d9d6b6..19c03e9 100644 --- a/src/config.c +++ b/src/config.c @@ -4,6 +4,7 @@ #include <string.h> #include <stdlib.h> #include <ctype.h> +#include <glob.h> #include "i3status.h" @@ -80,7 +81,7 @@ int load_configuration(const char *configfile) { interval = atoi(dest_value); OPT("wmii_path") { -#ifndef DZEN +#if !defined(DZEN) && !defined(XMOBAR) static glob_t globbuf; struct stat stbuf; if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) @@ -139,7 +140,7 @@ int load_configuration(const char *configfile) { } fclose(handle); -#ifndef DZEN +#if !defined(DZEN) && !defined(XMOBAR) if (wmii_path == NULL) exit(EXIT_FAILURE); #endif diff --git a/src/get_wireless_info.c b/src/get_wireless_info.c index c257f56..529ba71 100644 --- a/src/get_wireless_info.c +++ b/src/get_wireless_info.c @@ -34,10 +34,10 @@ const char *get_wireless_info() { continue; if ((quality == UCHAR_MAX) || (quality == 0)) { if (use_colors) - (void)snprintf(part, sizeof(part), "%sW: down", color("#FF0000")); + (void)snprintf(part, sizeof(part), "%sW: down%s", color("#FF0000"), endcolor()); else (void)snprintf(part, sizeof(part), "W: down"); - } else (void)snprintf(part, sizeof(part), "%sW: (%03d%%) %s", - color("#00FF00"), quality, get_ip_addr(wlan_interface)); + } else (void)snprintf(part, sizeof(part), "%sW: (%03d%%) %s%s", + color("#00FF00"), quality, get_ip_addr(wlan_interface), endcolor()); return part; } diff --git a/src/output.c b/src/output.c index 901a940..c153a01 100644 --- a/src/output.c +++ b/src/output.c @@ -28,6 +28,8 @@ char *color(const char *colorstr) { static char colorbuf[32]; #ifdef DZEN (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr); +#elif XMOBAR + (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr); #else (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors); #endif @@ -35,11 +37,23 @@ char *color(const char *colorstr) { } /* + * Some color formats (xmobar) require to terminate colors again + * + */ +char *endcolor() { +#ifdef XMOBAR + return "</fc>"; +#else + return ""; +#endif +} + +/* * Cleans wmii's /rbar directory by deleting all regular files * */ void cleanup_rbar_dir() { -#ifdef DZEN +#if defined(DZEN) || defined(XMOBAR) return; #endif struct dirent *ent; @@ -66,7 +80,7 @@ void cleanup_rbar_dir() { * */ void create_file(const char *name) { -#ifdef DZEN +#if defined(DZEN) || defined(XMOBAR) return; #endif char pathbuf[strlen(wmii_path)+256+1]; @@ -99,7 +113,7 @@ void setup(void) { unsigned int i; char pathbuf[512]; -#ifndef DZEN +#if !defined(DZEN) && !defined(XMOBAR) struct stat statbuf; /* Wait until wmii_path/rbar exists */ for (; stat(wmii_path, &statbuf) < 0; sleep(interval)); @@ -142,6 +156,22 @@ void write_to_statusbar(const char *name, const char *message, bool final_entry) exit(1); } return; +#elif XMOBAR + if (final_entry) { + if (printf("%s\n", message) < 0) { + perror("printf"); + exit(1); + } + + fflush(stdout); + return; + } + if (printf("%s" BAR, message) < 0) { + perror("printf"); + exit(1); + } + return; + #endif char pathbuf[strlen(wmii_path)+256+1]; |