diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | blocks.h | 20 | ||||
-rw-r--r-- | config.h | 23 | ||||
-rw-r--r-- | dwmblocks.c | 50 | ||||
-rw-r--r-- | patches/dwmblocks-statuscmd-signal.diff | 93 |
6 files changed, 183 insertions, 31 deletions
@@ -1,7 +1,14 @@ -output: dwmblocks.c blocks.h - cc `pkg-config --cflags x11` `pkg-config --libs x11` dwmblocks.c -o dwmblocks +PREFIX ?= /usr/local + +output: dwmblocks.o + gcc dwmblocks.o -lX11 -o dwmblocks +dwmblocks.o: dwmblocks.c config.h + gcc -c -lX11 dwmblocks.c clean: rm -f *.o *.gch dwmblocks install: output - mkdir -p /usr/local/bin - cp -f dwmblocks /usr/local/bin + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f dwmblocks $(DESTDIR)$(PREFIX)/bin + chmod 755 $(DESTDIR)$(PREFIX)/bin/dwmblocks +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/dwmblocks @@ -3,3 +3,16 @@ Modular status bar for dwm written in c. # modifying blocks The statusbar is made from text output from commandline programs. Blocks are added and removed by editing the blocks.h header file. +# Luke's bulid +I have dwmblocks read my preexisting scripts [here in my dotfiles repo](https://github.com/LukeSmithxyz/voidrice/tree/master/.local/bin/statusbar). +So if you want my build out of the box, download those and put them in your `$PATH`. +I do this to avoid redundancy in LARBS, both i3 and dwm use the same statusbar scripts. +# signalling changes +For example, the audio module has the update signal 10 by default. +Thus, running `pkill -RTMIN+10 dwmblocks` will update it. +# clickable modules +Like i3blocks, this build allows you to build in additional actions into your scripts in response to click events. +See the above linked scripts for examples of this using the `$BLOCK_BUTTON` variable. + +For this feature to work, you need the appropriate patch in dwm as well. See [here](https://gist.github.com/danbyl/54f7c1d57fc6507242a95b71c3d8fdea). +Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com). diff --git a/blocks.h b/blocks.h deleted file mode 100644 index 31e98af..0000000 --- a/blocks.h +++ /dev/null @@ -1,20 +0,0 @@ -//Modify this file to change what commands output to your statusbar, and recompile using the make command. -static const Block blocks[] = { - /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/ - {"", "cat ~/.pacupdate | sed /📦0/d", 0, 9}, - - {"🧠", "free -h | awk '/^Mem/ { print $3\"/\"$2 }' | sed s/i//g", 30, 0}, - - {"", "~/bin/statusbar/volume", 0, 10}, - - {"☀", "xbacklight | sed 's/\\..*//'", 0, 11}, - - {"", "~/bin/statusbar/battery", 5, 0}, - - {"🌡", "sensors | awk '/^temp1:/{print $2}'", 5, 0}, - - {"", "~/bin/statusbar/clock", 5, 0}, -}; - -//sets delimeter between status commands. NULL character ('\0') means no delimeter. -static char delim = '|'; diff --git a/config.h b/config.h new file mode 100644 index 0000000..e664b2f --- /dev/null +++ b/config.h @@ -0,0 +1,23 @@ +//Modify this file to change what commands output to your statusbar, and recompile using the make command. +static const Block blocks[] = { + /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/ + {"", "cat /tmp/recordingicon 2>/dev/null", 0, 9}, + /* {"", "music", 0, 11}, */ + {"", "pacpackages", 0, 8}, + /* {"", "crypto", 0, 13}, */ + {"", "torrent", 20, 7}, + {"", "news", 0, 6}, + /* {"", "memory", 10, 14}, */ + /* {"", "cpu", 10, 13}, */ + /* {"", "moonphase", 18000, 5}, */ + {"", "weather", 18000, 5}, + {"", "mailbox", 180, 12}, + {"", "volume", 1, 10}, + {"", "battery | tr \'\n\' \' \'", 5, 3}, + {"", "clock", 60, 1}, + {"", "internet", 5, 4}, + {"", "help", 0, 15}, +}; + +//sets delimeter between status commands. NULL character ('\0') means no delimeter. +static char delim = '|'; diff --git a/dwmblocks.c b/dwmblocks.c index 88bdfb0..0cd0b54 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -14,6 +14,7 @@ typedef struct { unsigned int signal; } Block; void sighandler(int num); +void buttonhandler(int sig, siginfo_t *si, void *ucontext); void replace(char *str, char old, char new); void getcmds(int time); #ifndef __OpenBSD__ @@ -27,13 +28,15 @@ void statusloop(); void termhandler(int signum); -#include "blocks.h" +#include "config.h" static Display *dpy; static int screen; static Window root; static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][256]; +static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;"; +static int button = 0; static int statusContinue = 1; static void (*writestatus) () = setroot; @@ -48,16 +51,34 @@ void replace(char *str, char old, char new) //opens process *cmd and stores output in *output void getcmd(const Block *block, char *output) { + if (block->signal) + { + output[0] = block->signal; + output++; + } strcpy(output, block->icon); - char *cmd = block->command; - FILE *cmdf = popen(cmd,"r"); + char* cmd; + FILE *cmdf; + if (button) + { + cmd = strcat(exportstring, block->command); + cmd[20] = '0' + button; + button = 0; + cmdf = popen(cmd,"r"); + cmd[22] = '\0'; + } + else + { + cmd = block->command; + cmdf = popen(cmd,"r"); + } if (!cmdf) return; char c; int i = strlen(block->icon); fgets(output+i, CMDLENGTH-i, cmdf); i = strlen(output); - if (delim != '\0' && --i) + if (delim != '\0' && i) output[i++] = delim; output[i++] = '\0'; pclose(cmdf); @@ -67,7 +88,7 @@ void getcmds(int time) { const Block* current; for(int i = 0; i < LENGTH(blocks); i++) - { + { current = blocks + i; if ((current->interval != 0 && time % current->interval == 0) || time == -1) getcmd(current,statusbar[i]); @@ -88,11 +109,18 @@ void getsigcmds(int signal) void setupsignals() { + struct sigaction sa; for(int i = 0; i < LENGTH(blocks); i++) - { + { if (blocks[i].signal > 0) + { signal(SIGRTMIN+blocks[i].signal, sighandler); + sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); + } } + sa.sa_sigaction = buttonhandler; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGUSR1, &sa, NULL); } #endif @@ -152,6 +180,14 @@ void sighandler(int signum) getsigcmds(signum-SIGRTMIN); writestatus(); } + +void buttonhandler(int sig, siginfo_t *si, void *ucontext) +{ + button = si->si_value.sival_int & 0xff; + getsigcmds(si->si_value.sival_int >> 8); + writestatus(); +} + #endif void termhandler(int signum) @@ -163,7 +199,7 @@ void termhandler(int signum) int main(int argc, char** argv) { for(int i = 0; i < argc; i++) - { + { if (!strcmp("-d",argv[i])) delim = argv[++i][0]; else if(!strcmp("-p",argv[i])) diff --git a/patches/dwmblocks-statuscmd-signal.diff b/patches/dwmblocks-statuscmd-signal.diff new file mode 100644 index 0000000..c2092e7 --- /dev/null +++ b/patches/dwmblocks-statuscmd-signal.diff @@ -0,0 +1,93 @@ +diff --git a/dwmblocks.c b/dwmblocks.c +index 88bdfb0..7bd14df 100644 +--- a/dwmblocks.c ++++ b/dwmblocks.c +@@ -14,6 +14,7 @@ typedef struct { + unsigned int signal; + } Block; + void sighandler(int num); ++void buttonhandler(int sig, siginfo_t *si, void *ucontext); + void replace(char *str, char old, char new); + void getcmds(int time); + #ifndef __OpenBSD__ +@@ -34,6 +35,8 @@ static int screen; + static Window root; + static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; + static char statusstr[2][256]; ++static char exportstring[CMDLENGTH + 16] = "export BUTTON=-;"; ++static int button = 0; + static int statusContinue = 1; + static void (*writestatus) () = setroot; + +@@ -48,16 +51,34 @@ void replace(char *str, char old, char new) + //opens process *cmd and stores output in *output + void getcmd(const Block *block, char *output) + { ++ if (block->signal) ++ { ++ output[0] = block->signal; ++ output++; ++ } + strcpy(output, block->icon); +- char *cmd = block->command; +- FILE *cmdf = popen(cmd,"r"); ++ char* cmd; ++ FILE *cmdf; ++ if (button) ++ { ++ cmd = strcat(exportstring, block->command); ++ cmd[14] = '0' + button; ++ button = 0; ++ cmdf = popen(cmd,"r"); ++ cmd[16] = '\0'; ++ } ++ else ++ { ++ cmd = block->command; ++ cmdf = popen(cmd,"r"); ++ } + if (!cmdf) + return; + char c; + int i = strlen(block->icon); + fgets(output+i, CMDLENGTH-i, cmdf); + i = strlen(output); +- if (delim != '\0' && --i) ++ if (delim != '\0' && i) + output[i++] = delim; + output[i++] = '\0'; + pclose(cmdf); +@@ -88,11 +106,18 @@ void getsigcmds(int signal) + + void setupsignals() + { ++ struct sigaction sa; + for(int i = 0; i < LENGTH(blocks); i++) + { + if (blocks[i].signal > 0) ++ { + signal(SIGRTMIN+blocks[i].signal, sighandler); ++ sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); ++ } + } ++ sa.sa_sigaction = buttonhandler; ++ sa.sa_flags = SA_SIGINFO; ++ sigaction(SIGUSR1, &sa, NULL); + + } + #endif +@@ -152,6 +177,14 @@ void sighandler(int signum) + getsigcmds(signum-SIGRTMIN); + writestatus(); + } ++ ++void buttonhandler(int sig, siginfo_t *si, void *ucontext) ++{ ++ button = si->si_value.sival_int & 0xff; ++ getsigcmds(si->si_value.sival_int >> 8); ++ writestatus(); ++} ++ + #endif + + void termhandler(int signum) |