14 * Writes an errormessage to statusbar
17 void write_error_to_statusbar(const char *message) {
20 write_to_statusbar("error", message, true);
24 * Returns the correct color format for dzen (^fg(color)) or wmii (color <normcolors>)
27 char *color(const char *colorstr) {
28 static char colorbuf[32];
30 (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
32 (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
34 (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors);
40 * Some color formats (xmobar) require to terminate colors again
52 * Cleans wmii's /rbar directory by deleting all regular files
55 void cleanup_rbar_dir() {
56 #if defined(DZEN) || defined(XMOBAR)
61 char pathbuf[strlen(wmii_path)+256+1];
63 if ((dir = opendir(wmii_path)) == NULL)
66 while ((ent = readdir(dir)) != NULL) {
67 if (ent->d_type == DT_REG) {
68 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name);
69 if (unlink(pathbuf) == -1)
78 * Creates the specified file in wmii's /rbar directory with
79 * correct modes and initializes colors if colormode is enabled
82 void create_file(const char *name) {
83 #if defined(DZEN) || defined(XMOBAR)
86 char pathbuf[strlen(wmii_path)+256+1];
88 int flags = O_CREAT | O_WRONLY;
91 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
93 /* Overwrite file's contents if it exists */
94 if (stat(pathbuf, &statbuf) >= 0)
97 if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
100 char *tmp = color("#888888");
101 if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
108 * Waits until wmii_path/rbar exists (= the filesystem gets mounted),
109 * cleans up all files and creates the needed files
116 #if !defined(DZEN) && !defined(XMOBAR)
118 /* Wait until wmii_path/rbar exists */
119 for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
121 #define cf(orderidx, name) create_file(order_to_str(order[orderidx], name));
125 cf(ORDER_WLAN, "wlan");
127 cf(ORDER_ETH, "eth");
128 if (get_cpu_temperature)
129 cf(ORDER_CPU_TEMPERATURE, "cpu_temperature");
130 cf(ORDER_LOAD, "load");
132 cf(ORDER_TIME, "time");
133 for (i = 0; i < num_run_watches; i += 2) {
134 snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
135 create_file(pathbuf);
140 * Writes the given message in the corresponding file in wmii's /rbar directory
143 void write_to_statusbar(const char *name, const char *message, bool final_entry) {
146 if (printf("%s^p(6)\n", message) < 0) {
154 if (printf("%s" BAR, message) < 0) {
161 if (printf("%s\n", message) < 0) {
169 if (printf("%s" BAR, message) < 0) {
177 char pathbuf[strlen(wmii_path)+256+1];
180 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
181 if ((fd = open(pathbuf, O_RDWR)) == -1) {
182 /* Try to re-setup stuff and just continue */
186 if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))