commit 91d449e4dd54dcb76dde2962e292de425072bc2e from: Caleb Stein date: Sat Jun 27 22:01:04 2026 UTC output to fifo, not x11 root window, for use with spectrwm commit - 531c239673c159514ba6035b670a1e650d7ef2a0 commit + 91d449e4dd54dcb76dde2962e292de425072bc2e blob - f7db47470d293159c6d88d9e53cee0dcaef584ec blob + 0e1c49acde83fd31d00b9abca3f8d76fe159368e --- Makefile +++ Makefile @@ -3,7 +3,7 @@ PROG= statbar MAN= CFLAGS += -I/usr/X11R6/include -I/usr/local/include -LDFLAGS += -L/usr/X11R6/lib -lsndio -lX11 +LDFLAGS += -lsndio .include blob - 4012d5ff7fc8d537bd7a071745f16b5298bc13c2 blob + 8bf34584a10a16109475d9e906cd131a37ed59bc --- include/statbar.h +++ include/statbar.h @@ -27,7 +27,8 @@ extern bool weather_loc_valid; extern void read_config(void); extern int open_command_interface(void); -extern void close_command_interface(void); +extern int open_output(void); +extern void close_fifos(void); /* Clock */ extern char clock_string[26]; blob - ac4d36b22ac3fb5df1e313c49572466b3f557c7f blob + 4952920f95c0803025a7b58870ca6d3d1e261a3f --- modules/Makefile +++ modules/Makefile @@ -3,6 +3,6 @@ SRCS= clock.c battery.c volume.c cputemp.c fanspeed.c MAN= CFLAGS += -I../include -I/usr/local/include -LDFLAGS += -L/usr/local/lib -lsndio +LDFLAGS += -lsndio .include blob - 49d8a4846e5fa567b4e7a4568411d1182c218d7f blob + 175d3d70c05ffd87103e5998e7d558076d45a62b --- src/Makefile +++ src/Makefile @@ -3,7 +3,7 @@ SRCS= main.c fs.c MAN= CFLAGS += -I../include -I/usr/X11R6/include -I/usr/local/include -LDFLAGS += -L/usr/local/lib -L/usr/X11R6/lib -L../modules -lsndio -lX11 -lstatbar_modules +LDFLAGS += -L../modules -lsndio -lstatbar_modules .include blob - cc7751e57650ee33fa7bbd84596ce844f64b7149 blob + 4f58a5ada29f8649fdd13eb38c8510099cb3298a --- src/fs.c +++ src/fs.c @@ -9,9 +9,12 @@ #include "statbar.h" -static int fifo_rdfd; -static int fifo_wrfd; -static char *fifopath; +static int cmd_rdfd; +static int cmd_wrfd; +static char *cmdpath; +static int out_rdfd; +static int out_wrfd; +static char *outpath; static int mkdir_recursive(char *path) @@ -153,8 +156,8 @@ read_config(void) (void)fclose(file); } -int -open_command_interface(void) +static int +open_fifo(int *rdfd, int *wrfd, char **path, const char *pathstr, int wr) { uid_t uid; struct passwd *pw; @@ -171,46 +174,62 @@ open_command_interface(void) return -1; } - if (asprintf(&fifopath, "%s/.local/state/statbarcmd", pw->pw_dir) == -1) + if (asprintf(path, "%s%s", pw->pw_dir, pathstr) == -1) { perror("asprintf"); return -1; } - if (mkfifo(fifopath, 0600) != 0 && errno != EEXIST) + if (mkfifo(*path, 0600) != 0 && errno != EEXIST) { perror("mkfifo"); - free(fifopath); + free(path); return -1; } - fifo_rdfd = open(fifopath, O_RDONLY | O_NONBLOCK); - if (fifo_rdfd == -1) + *rdfd = open(*path, O_RDONLY | O_NONBLOCK); + if (*rdfd == -1) { perror("open"); - free(fifopath); + free(*path); return -1; } - fifo_wrfd = open(fifopath, O_WRONLY); - if (fifo_wrfd == -1) + *wrfd = open(*path, O_WRONLY); + if (*wrfd == -1) { perror("open"); - (void)close(fifo_rdfd); - free(fifopath); + (void)close(*rdfd); + free(*path); return -1; } - return fifo_rdfd; + return wr ? *wrfd : *rdfd; } +int +open_command_interface(void) +{ + return open_fifo(&cmd_rdfd, &cmd_wrfd, &cmdpath, "/.local/state/statbarcmd", 0); +} + +int +open_output(void) +{ + return open_fifo(&out_rdfd, &out_wrfd, &outpath, "/.local/state/statbarout", 1); +} + void -close_command_interface(void) +close_fifos(void) { - (void)close(fifo_rdfd); - (void)close(fifo_wrfd); - (void)remove(fifopath); - free(fifopath); + (void)close(cmd_rdfd); + (void)close(cmd_wrfd); + (void)remove(cmdpath); + free(cmdpath); + (void)close(out_rdfd); + (void)close(out_wrfd); + (void)remove(outpath); + free(outpath); } blob - 92680bf0f31b186e21edb4298305a38a480d615f blob + 01276ea7f9874a7eb8c8dbbdbb0c5883d5e4ca0b --- src/main.c +++ src/main.c @@ -12,11 +12,8 @@ #include #include -#include - #include "statbar.h" -#define MAX_STATBAR_LEN 128 #define NFDS 5 enum clocks_e @@ -70,10 +67,8 @@ install_signal_handlers(void) int main(void) { - Display *display; - Window root; - char statbar_text[MAX_STATBAR_LEN]; bool dirty = true; + int output_fd; int batt_fd; int vol_fd; int network_fd; @@ -105,9 +100,16 @@ main(void) ssize_t n; (void)setvbuf(stdout, NULL, _IOLBF, 0); + output_fd = open_output(); + printf("Got fd %d\n", output_fd); + if (output_fd == -1) + { + (void)puts("Failed to open output FIFO"); + + return -1; + } install_signal_handlers(); - statbar_text[0] = '\0'; (void)puts("Welcome to statbar"); /* Init components */ @@ -157,15 +159,6 @@ main(void) } get_mail(); - display = XOpenDisplay(NULL); - if (display == NULL) - { - (void)puts("Failed to get display"); - - return -1; - } - root = DefaultRootWindow(display); - if (pledge("stdio rpath cpath proc exec", NULL) == -1) { perror("pledge"); @@ -295,17 +288,15 @@ main(void) if (dirty) { - (void)snprintf(statbar_text, MAX_STATBAR_LEN - 1, "%s%s| %s | %s | %s | %s | %s | %s", - mail_string, - network_string, - weather_string, - fanspeed_string, - cputemp_string, - volume_string, + (void)dprintf(output_fd, "%s | %s | %s | %s | %s | %s | %s%s\n", + clock_string, battery_string, - clock_string); - (void)XStoreName(display, root, statbar_text); - (void)XFlush(display); + volume_string, + cputemp_string, + fanspeed_string, + weather_string, + network_string, + mail_string); dirty = false; } } @@ -317,14 +308,13 @@ cleanup: if (network_pid > 0) (void)kill(network_pid, SIGTERM); if (weather_loc_valid) close_weather(); close_mail(); - (void)XCloseDisplay(display); if (weather_pfd) { weather_pfd = NULL; (void)close(weather_pipe[0]); (void)close(weather_pipe[1]); } - close_command_interface(); + close_fifos(); return 0; }