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), "%s %s ", colorstr, wmii_normcolors);
38 * Cleans wmii's /rbar directory by deleting all regular files
41 void cleanup_rbar_dir() {
47 char pathbuf[strlen(wmii_path)+256+1];
49 if ((dir = opendir(wmii_path)) == NULL)
52 while ((ent = readdir(dir)) != NULL) {
53 if (ent->d_type == DT_REG) {
54 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name);
55 if (unlink(pathbuf) == -1)
64 * Creates the specified file in wmii's /rbar directory with
65 * correct modes and initializes colors if colormode is enabled
68 void create_file(const char *name) {
72 char pathbuf[strlen(wmii_path)+256+1];
74 int flags = O_CREAT | O_WRONLY;
77 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
79 /* Overwrite file's contents if it exists */
80 if (stat(pathbuf, &statbuf) >= 0)
83 if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
86 char *tmp = color("#888888");
87 if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
94 * Waits until wmii_path/rbar exists (= the filesystem gets mounted),
95 * cleans up all files and creates the needed files
104 /* Wait until wmii_path/rbar exists */
105 for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
107 #define cf(orderidx, name) create_file(order_to_str(order[orderidx], name));
111 cf(ORDER_WLAN, "wlan");
113 cf(ORDER_ETH, "eth");
114 if (get_cpu_temperature)
115 cf(ORDER_CPU_TEMPERATURE, "cpu_temperature");
116 cf(ORDER_LOAD, "load");
118 cf(ORDER_TIME, "time");
119 for (i = 0; i < num_run_watches; i += 2) {
120 snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
121 create_file(pathbuf);
126 * Writes the given message in the corresponding file in wmii's /rbar directory
129 void write_to_statusbar(const char *name, const char *message, bool final_entry) {
132 if (printf("%s^p(6)\n", message) < 0) {
140 if (printf("%s" BAR, message) < 0) {
147 char pathbuf[strlen(wmii_path)+256+1];
150 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
151 if ((fd = open(pathbuf, O_RDWR)) == -1) {
152 /* Try to re-setup stuff and just continue */
156 if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))