13 * Writes an errormessage to statusbar
16 void write_error_to_statusbar(const char *message) {
19 write_to_statusbar("error", message, true);
23 * Returns the correct color format for dzen (^fg(color)) or wmii (color <normcolors>)
26 char *color(const char *colorstr) {
27 static char colorbuf[32];
29 (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
31 (void)snprintf(colorbuf, sizeof(colorbuf), "%s %s ", colorstr, wmii_normcolors);
37 * Cleans wmii's /rbar directory by deleting all regular files
40 void cleanup_rbar_dir() {
46 char pathbuf[strlen(wmii_path)+256+1];
48 if ((dir = opendir(wmii_path)) == NULL)
51 while ((ent = readdir(dir)) != NULL) {
52 if (ent->d_type == DT_REG) {
53 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, ent->d_name);
54 if (unlink(pathbuf) == -1)
63 * Creates the specified file in wmii's /rbar directory with
64 * correct modes and initializes colors if colormode is enabled
67 void create_file(const char *name) {
71 char pathbuf[strlen(wmii_path)+256+1];
73 int flags = O_CREAT | O_WRONLY;
76 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
78 /* Overwrite file's contents if it exists */
79 if (stat(pathbuf, &statbuf) >= 0)
82 if ((fd = open(pathbuf, flags, S_IRUSR | S_IWUSR)) < 0)
85 char *tmp = color("#888888");
86 if (write(fd, tmp, strlen(tmp)) != (ssize_t)strlen(tmp))
93 * Waits until wmii_path/rbar exists (= the filesystem gets mounted),
94 * cleans up all files and creates the needed files
103 /* Wait until wmii_path/rbar exists */
104 for (; stat(wmii_path, &statbuf) < 0; sleep(interval));
106 #define cf(orderidx, name) create_file(order_to_str(order[orderidx], name));
110 cf(ORDER_WLAN, "wlan");
112 cf(ORDER_ETH, "eth");
113 if (get_cpu_temperature)
114 cf(ORDER_CPU_TEMPERATURE, "cpu_temperature");
115 cf(ORDER_LOAD, "load");
117 cf(ORDER_TIME, "time");
118 for (i = 0; i < num_run_watches; i += 2) {
119 snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
120 create_file(pathbuf);
125 * Writes the given message in the corresponding file in wmii's /rbar directory
128 void write_to_statusbar(const char *name, const char *message, bool final_entry) {
131 if (printf("%s^p(6)\n", message) < 0) {
139 if (printf("%s" BAR, message) < 0) {
146 char pathbuf[strlen(wmii_path)+256+1];
149 (void)snprintf(pathbuf, sizeof(pathbuf), "%s%s", wmii_path, name);
150 if ((fd = open(pathbuf, O_RDWR)) == -1) {
151 /* Try to re-setup stuff and just continue */
155 if (write(fd, message, strlen(message)) != (ssize_t)strlen(message))