commit e8322139d4e667dcd63b3938e305ff4a85eedf03 from: Brett Fisher date: Fri May 15 19:47:49 2026 UTC bxbar.c: Organize order of functions. - Set order of forward function declarations and functions consistent with when called by main(), then setup(), and run() functions. commit - fc4889eaa5239e25ab0c3fda7d289a5fb5b98ba0 commit + e8322139d4e667dcd63b3938e305ff4a85eedf03 blob - 3f6eb1a9d0e5f85afae8352f1ad97027f0c1afcd blob + 91364d176f04b66de27e0b3679f29888a9a89d2a --- bxbar.c +++ bxbar.c @@ -20,6 +20,7 @@ #include "config.h" +/* Macros */ #define MAXINPUT 256 /* Globals */ @@ -41,12 +42,12 @@ static Atom net_wm_strut_partial; /* Forward function declarations */ static void setup(void); -static void cleanup(int status); -static void logmsg(const char *fmt, ...); static void set_dock_atoms(void); -static int readstdin(void); +static void logmsg(const char *fmt, ...); static void run(void); +static int readstdin(void); static void draw(void); +static void cleanup(int status); int main(void) { if (!(dpy = XOpenDisplay(NULL))) { @@ -115,12 +116,6 @@ static void setup(void) { } } -static void cleanup(int status) { - if (dpy) - XCloseDisplay(dpy); - exit(status); -} - static void set_dock_atoms(void) { net_wm_window_type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); net_wm_window_type_dock = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); @@ -150,6 +145,57 @@ logmsg(const char *fmt, ...) fclose(f); } +void +run(void) +{ + logmsg("run() entered"); + + struct pollfd fds[2]; + int ready; + + fds[0].fd = STDIN_FILENO; + fds[0].events = POLLIN; + fds[1].fd = ConnectionNumber(dpy); + fds[1].events = POLLIN; + + for (;;) { + ready = poll(fds, 2, -1); + if (ready < 0) { + if (errno == EINTR) + continue; + err(1, "poll"); + } + + if (fds[0].revents & (POLLIN | POLLHUP)) { + if (fds[0].revents & POLLIN) { + int rc = readstdin(); + logmsg("readstdin returned %d, slen=%d, stext='%s'", rc, slen, stext); + if (rc == 1) { + fds[0].fd = -1; + logmsg("stdin EOF, fd set to -1"); + } + } + if (fds[0].revents & POLLHUP) + fds[0].fd = -1; + } + + if (fds[1].revents & POLLIN) + while (XPending(dpy) > 0) { + XEvent ev; + XNextEvent(dpy, &ev); + if (ev.type == Expose) + dirty = 1; + } + + if (dirty) { + draw(); + dirty = 0; + XFlush(dpy); /* Ensures the drawing command hits the server */ + } + } + logmsg("run() loop exited unexpectedly"); /* should never reach */ +} + static int readstdin(void) { @@ -214,54 +260,9 @@ draw(void) (FcChar8 *)stext, draw_len); } -void -run(void) -{ - logmsg("run() entered"); - - struct pollfd fds[2]; - int ready; - - fds[0].fd = STDIN_FILENO; - fds[0].events = POLLIN; - fds[1].fd = ConnectionNumber(dpy); - fds[1].events = POLLIN; - - for (;;) { - ready = poll(fds, 2, -1); - if (ready < 0) { - if (errno == EINTR) - continue; - err(1, "poll"); - } - - if (fds[0].revents & (POLLIN | POLLHUP)) { - if (fds[0].revents & POLLIN) { - int rc = readstdin(); - logmsg("readstdin returned %d, slen=%d, stext='%s'", rc, slen, stext); - if (rc == 1) { - fds[0].fd = -1; - logmsg("stdin EOF, fd set to -1"); - } - } - if (fds[0].revents & POLLHUP) - fds[0].fd = -1; - } - - if (fds[1].revents & POLLIN) - while (XPending(dpy) > 0) { - XEvent ev; - XNextEvent(dpy, &ev); - if (ev.type == Expose) - dirty = 1; - } - - if (dirty) { - draw(); - dirty = 0; - XFlush(dpy); /* Ensures the drawing command hits the server */ - } - } - logmsg("run() loop exited unexpectedly"); /* should never reach */ +static void cleanup(int status) { + if (dpy) + XCloseDisplay(dpy); + exit(status); }