#include "wmiistatus.h"
+#define BAR "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)"
+
/* socket file descriptor for general purposes */
static int general_socket;
return concatbuf;
}
+/*
+ * Returns the correct color format for dzen (^fg(color)) or wmii (color <normcolors>)
+ *
+ */
+static char *color(const char *colorstr) {
+ static char colorbuf[32];
+#ifdef DZEN
+ (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
+#else
+ (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors);
+#endif
+ return colorbuf;
+}
+
/*
* Cleans wmii's /rbar directory by deleting all regular files
*
*/
static void cleanup_rbar_dir() {
+#ifdef DZEN
+ return;
+#endif
struct dirent *ent;
DIR *dir;
char pathbuf[strlen(wmii_path)+256+1];
*
*/
static void create_file(const char *name) {
+#ifdef DZEN
+ return;
+#endif
char pathbuf[strlen(wmii_path)+256+1];
int fd;
int flags = O_CREAT | O_WRONLY;
if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
exit(EXIT_FAILURE);
if (use_colors) {
- char *tmp = concat("#888888 ", wmii_normcolors);
+ char *tmp = color("#888888");
if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
exit(EXIT_FAILURE);
}
*/
static void setup(void) {
unsigned int i;
- struct stat statbuf;
char pathbuf[512];
+#ifndef DZEN
+ struct stat statbuf;
/* Wait until wmii_path/rbar exists */
for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
+#endif
cleanup_rbar_dir();
if (wlan_interface)
* Writes the given message in the corresponding file in wmii's /rbar directory
*
*/
-static void write_to_statusbar(const char *name, const char *message) {
+static void write_to_statusbar(const char *name, const char *message, bool final_entry) {
+#ifdef DZEN
+ if (final_entry) {
+ (void)printf("%s^p(6)\n", message);
+ fflush(stdout);
+ return;
+ }
+ (void)printf("%s" BAR, message);
+ return;
+#endif
+
char pathbuf[strlen(wmii_path)+256+1];
int fd;
static void write_error_to_statusbar(const char *message) {
cleanup_rbar_dir();
create_file("error");
- write_to_statusbar("error", message);
+ write_to_statusbar("error", message, true);
}
/*
last = walk+1;
(void)close(fd);
- if ((full_design != -1) && (remaining != -1) && (present_rate != -1)) {
+ if ((full_design == 1) || (remaining == -1))
+ return part;
+
+ if (present_rate > 0) {
float remaining_time;
int seconds, hours, minutes;
if (status == CS_CHARGING)
(status == CS_DISCHARGING ? "BAT" : "FULL")),
(((float)remaining / (float)full_design) * 100),
hours, minutes, seconds);
+ } else {
+ (void)snprintf(part, sizeof(part), "%s %.02f%%",
+ (status == CS_CHARGING ? "CHR" :
+ (status == CS_DISCHARGING ? "BAT" : "FULL")),
+ (((float)remaining / (float)full_design) * 100));
}
return part;
}
continue;
if ((quality == UCHAR_MAX) || (quality == 0)) {
if (use_colors)
- (void)snprintf(part, sizeof(part), "%s%s",
- concat("#FF0000 ", wmii_normcolors), " W: down");
+ (void)snprintf(part, sizeof(part), "%sW: down", color("#FF0000"));
else (void)snprintf(part, sizeof(part), "W: down");
- } else (void)snprintf(part, sizeof(part), "W: (%03d%%) %s",
- quality, get_ip_address(wlan_interface));
+ } else (void)snprintf(part, sizeof(part), "%sW: (%03d%%) %s",
+ color("#00FF00"), quality, get_ip_address(wlan_interface));
return part;
}
if (handle == NULL)
die("Could not open configfile\n");
char dest_name[512], dest_value[512], whole_buffer[1026];
- struct stat stbuf;
+
while (!feof(handle)) {
char *ret;
if ((ret = fgets(whole_buffer, 1024, handle)) == whole_buffer) {
interval = atoi(dest_value);
OPT("wmii_path")
{
+#ifndef DZEN
static glob_t globbuf;
+ struct stat stbuf;
if (glob(dest_value, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
die("glob() failed\n");
wmii_path = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : dest_value);
}
if (wmii_path[strlen(wmii_path)-1] != '/')
die("wmii_path is not terminated by /\n");
+#endif
}
OPT("run_watch")
{
}
fclose(handle);
+#ifndef DZEN
if (wmii_path == NULL)
exit(EXIT_FAILURE);
+#endif
return result;
}
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",
- (running ?
- concat("#00FF00 ", wmii_normcolors) :
- concat("#FF0000 ", wmii_normcolors)),
+ snprintf(part, sizeof(part), "%s%s: %s",
+ (running ? color("#00FF00") : color("#FF0000")),
run_watches[i],
(running ? "yes" : "no"));
else snprintf(part, sizeof(part), "%s: %s", run_watches[i], (running ? "yes" : "no"));
snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
- write_to_statusbar(pathbuf, part);
+ write_to_statusbar(pathbuf, part, false);
}
if (wlan_interface)
- write_to_statusbar(concat(order[ORDER_WLAN], "wlan"), get_wireless_info());
+ write_to_statusbar(concat(order[ORDER_WLAN], "wlan"), get_wireless_info(), false);
if (eth_interface)
- write_to_statusbar(concat(order[ORDER_ETH], "eth"), get_eth_info());
+ write_to_statusbar(concat(order[ORDER_ETH], "eth"), get_eth_info(), false);
if (battery_path)
- write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info());
+ write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(), false);
/* Get load */
#ifdef LINUX
(double)load.ldavg[1] / scale,
(double)load.ldavg[2] / scale);
#endif
- write_to_statusbar(concat(order[ORDER_LOAD], "load"), part);
+ write_to_statusbar(concat(order[ORDER_LOAD], "load"), part, !time_format);
if (time_format) {
/* Get date & time */
time_t current_time = time(NULL);
struct tm *current_tm = localtime(¤t_time);
(void)strftime(part, sizeof(part), time_format, current_tm);
- write_to_statusbar(concat(order[ORDER_TIME], "time"), part);
+ write_to_statusbar(concat(order[ORDER_TIME], "time"), part, true);
}
sleep(interval);