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];
34 (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
36 (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
38 (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors);
44 * Some color formats (xmobar) require to terminate colors again
56 * Cleans wmii's /rbar directory by deleting all regular files
59 void cleanup_rbar_dir() {
60 #if defined(DZEN) || defined(XMOBAR)
65 char pathbuf[strlen(wmii_path)+256+1];
67 if ((dir = opendir(wmii_path)) == NULL)
70 while ((ent = readdir(dir)) != NULL) {
71 if (ent->d_type == DT_REG) {
72 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name);
73 if (unlink(pathbuf) == -1)
82 * Creates the specified file in wmii's /rbar directory with
83 * correct modes and initializes colors if colormode is enabled
86 void create_file(const char *name) {
87 #if defined(DZEN) || defined(XMOBAR)
90 char pathbuf[strlen(wmii_path)+256+1];
92 int flags = O_CREAT | O_WRONLY;
95 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
97 /* Overwrite file's contents if it exists */
98 if (stat(pathbuf, &statbuf) >= 0)
101 if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
104 char *tmp = color("#888888");
105 if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
112 * Waits until wmii_path/rbar exists (= the filesystem gets mounted),
113 * cleans up all files and creates the needed files
120 #if !defined(DZEN) && !defined(XMOBAR)
122 /* Wait until wmii_path/rbar exists */
123 for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
125 #define cf(orderidx, name) create_file(order_to_str(order[orderidx], name));
129 cf(ORDER_WLAN, "wlan");
131 cf(ORDER_ETH, "eth");
132 if (get_cpu_temperature)
133 cf(ORDER_CPU_TEMPERATURE, "cpu_temperature");
134 cf(ORDER_LOAD, "load");
136 cf(ORDER_TIME, "time");
137 for (i = 0; i < num_run_watches; i += 2) {
138 snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
139 create_file(pathbuf);
144 * Writes the given message in the corresponding file in wmii's /rbar directory
147 void write_to_statusbar(const char *name, const char *message, bool final_entry) {
150 if (printf("%s^p(6)\n", message) < 0) {
158 if (printf("%s" BAR, message) < 0) {
165 if (printf("%s\n", message) < 0) {
173 if (printf("%s" BAR, message) < 0) {
181 char pathbuf[strlen(wmii_path)+256+1];
184 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
185 if ((fd = open(pathbuf, O_RDWR)) == -1) {
186 /* Try to re-setup stuff and just continue */
190 if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))