dwmblocks

my build of dwmblocks
git clone git://git.kocotian.pl/dwmblocks.git
Log | Files | Refs | README | LICENSE

commit 7df8d64b7c83d5c61319023c6c487d19e1159dbe
parent 8836af58852df7b48716666b321b2dc6291ca492
Author: kocotian <kocotian@kocotian.pl>
Date:   Sat,  2 Jan 2021 20:39:41 +0100

initial fork

Diffstat:
DFUNDING.yml | 3---
AREADME | 37+++++++++++++++++++++++++++++++++++++
DREADME.md | 46----------------------------------------------
Mconfig.h | 61++++++++++++++++++++++++++++++-------------------------------
Mdwmblocks.c | 64++++++++++++++++++++++++++++++++++++++++------------------------
5 files changed, 107 insertions(+), 104 deletions(-)

diff --git a/FUNDING.yml b/FUNDING.yml @@ -1,3 +0,0 @@ -github: lukesmithxyz -custom: ["https://lukesmith.xyz/donate", "https://paypal.me/lukemsmith", "https://lukesmith.xyz/crypto"] -patreon: lukesmith diff --git a/README b/README @@ -0,0 +1,37 @@ +dwmblocks - Modular status bar for dwm written in c. + +This repository is kocotian's fork of Luke Smith's build: +https://git.lukesmith.xyz/dwmblocks + +The statusbar is made from text output from commandline programs. Blocks are +added and removed by editing the config.h file. + +Most statusbars constantly rerun every script every several seconds to update. +This is an option here, but a superior choice is giving your module a signal +that you can signal to it to update on a relevant event, rather than having it +rerun idly. + +For example, the audio module has the update signal 10 by default. +Thus, running: + $ pkill -RTMIN+10 dwmblocks +will update it. + +You can also run: + $ kill -44 $(pidof dwmblocks) +which will have the same effect, but is faster. Just add 34 to your typical +signal number. + +My volume module NEVER updates on its own, instead I have this command run +along side my volume shortcuts in dwm to only update it when relevant. + +Note that if you signal an unexpected signal to dwmblocks, it will probably +crash. So if you disable a module, remember to also disable any cronjobs or +other scripts that might signal to that module. + +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: +https://dwm.suckless.org/patches/statuscmd/ +Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com). diff --git a/README.md b/README.md @@ -1,46 +0,0 @@ -# dwmblocks - -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 config.h file. - -# Luke's build - -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. - -# Signaling changes - -Most statusbars constantly rerun every script every several seconds to update. -This is an option here, but a superior choice is giving your module a signal -that you can signal to it to update on a relevant event, rather than having it -rerun idly. - -For example, the audio module has the update signal 10 by default. Thus, -running `pkill -RTMIN+10 dwmblocks` will update it. - -You can also run `kill -44 $(pidof dwmblocks)` which will have the same effect, -but is faster. Just add 34 to your typical signal number. - -My volume module *never* updates on its own, instead I have this command run -along side my volume shortcuts in dwm to only update it when relevant. - -Note that if you signal an unexpected signal to dwmblocks, it will probably -crash. So if you disable a module, remember to also disable any cronjobs or -other scripts that might signal to that module. - -# 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://dwm.suckless.org/patches/statuscmd/). -Credit for those patches goes to Daniel Bylinka (daniel.bylinka@gmail.com). diff --git a/config.h b/config.h @@ -1,37 +1,36 @@ -//Modify this file to change what commands output to your statusbar, and recompile using the make command. +/* 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*/ - /* {"⌨", "sb-kbselect", 0, 30}, */ - {"", "cat /tmp/recordingicon 2>/dev/null", 0, 9}, - {"", "sb-tasks", 10, 26}, - {"", "sb-music", 0, 11}, - {"", "sb-pacpackages", 0, 8}, - {"", "sb-news", 0, 6}, - /* {"", "sb-crypto", 0, 13}, */ - /* {"", "sb-price lbc \"LBRY Token\" 📚", 9000, 22}, */ - /* {"", "sb-price bat \"Basic Attention Token\" 🦁", 9000, 20}, */ - /* {"", "sb-price link \"Chainlink\" 🔗", 300, 25}, */ - /* {"", "sb-price xmr \"Monero\" 🔒", 9000, 24}, */ - /* {"", "sb-price eth Ethereum 🍸", 9000, 23}, */ - /* {"", "sb-price btc Bitcoin 💰", 9000, 21}, */ - {"", "sb-torrent", 20, 7}, - /* {"", "sb-memory", 10, 14}, */ - /* {"", "sb-cpu", 10, 18}, */ - /* {"", "sb-moonphase", 18000, 17}, */ - {"", "sb-forecast", 18000, 5}, - {"", "sb-mailbox", 180, 12}, - {"", "sb-nettraf", 1, 16}, - {"", "sb-volume", 0, 10}, - {"", "sb-battery", 5, 3}, - {"", "sb-clock", 60, 1}, - {"", "sb-internet", 5, 4}, - {"", "sb-help-icon", 0, 15}, + /* icon command update: time signal*/ + { "", "sb-music", 5, 11}, + { "", "sb-news", 0, 6}, + { "", "sb-mailbox", 180, 12}, + { "", "sb-clock", 60, 1}, + { "", "sb-internet", 5, 4}, + { "", "printf ';'", 0, 4}, + { "", "sb-dwmver", 0, 15}, + { "", "sb-linver", 0, 15}, + { "", "sb-nettraf", 1, 16}, + { "", "sb-notifystat", 1, 17}, + { "", "sb-memory", 5, 14}, + { "", "sb-disk /", 60, 0}, + { "", "sb-disk /dox", 60, 0}, + { "", "sb-pacpackages", 0, 8}, + { "", "sb-allpackages", 0, 8}, + { "", "sb-cpu", 10, 18}, + { "", "sb-cpubars", 1, 18}, + { "", "sb-cpufreq", 1, 18}, + { "", "sb-weather", 18000, 5}, + { "", "sb-volume", 0, 10}, + { "", "sb-battery", 5, 3}, + { "", "sb-torrent", 20, 7}, + { "", "sb-recordings", 0, 9}, }; -//Sets delimiter between status commands. NULL character ('\0') means no delimiter. -static char *delim = " "; +/* Sets delimiter between status commands. NULL character ('\0') means no delimiter. */ +static char *delim = " \177\177 "; -// Have dwmblocks automatically recompile and run when you edit this file in -// vim with the following line in your vimrc/init.vim: +/* Have dwmblocks automatically recompile and run when you edit this file in */ +/* vim with the following line in your vimrc/init.vim: */ // autocmd BufWritePost ~/.local/src/dwmblocks/config.h !cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid dwmblocks & } diff --git a/dwmblocks.c b/dwmblocks.c @@ -1,11 +1,11 @@ -#include<stdlib.h> -#include<stdio.h> -#include<string.h> -#include<unistd.h> -#include<signal.h> -#include<X11/Xlib.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <X11/Xlib.h> #define LENGTH(X) (sizeof(X) / sizeof (X[0])) -#define CMDLENGTH 50 +#define CMDLENGTH 100 typedef struct { char* icon; @@ -35,11 +35,12 @@ static Display *dpy; static int screen; static Window root; static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; -static char statusstr[2][256]; +static char statusstr[2][2048]; static int statusContinue = 1; static void (*writestatus) () = setroot; -void replace(char *str, char old, char new) +void +replace(char *str, char old, char new) { int N = strlen(str); for(int i = 0; i < N; i++) @@ -47,7 +48,9 @@ void replace(char *str, char old, char new) str[i] = new; } -void remove_all(char *str, char to_remove) { +void +remove_all(char *str, char to_remove) +{ char *read = str; char *write = str; while (*read) { @@ -60,8 +63,9 @@ void remove_all(char *str, char to_remove) { } } -//opens process *cmd and stores output in *output -void getcmd(const Block *block, char *output) +/* opens process *cmd and stores output in *output */ +void +getcmd(const Block *block, char *output) { if (block->signal) { @@ -85,7 +89,8 @@ void getcmd(const Block *block, char *output) pclose(cmdf); } -void getcmds(int time) +void +getcmds(int time) { const Block* current; for(int i = 0; i < LENGTH(blocks); i++) @@ -97,7 +102,8 @@ void getcmds(int time) } #ifndef __OpenBSD__ -void getsigcmds(int signal) +void +getsigcmds(int signal) { const Block *current; for (int i = 0; i < LENGTH(blocks); i++) @@ -108,7 +114,8 @@ void getsigcmds(int signal) } } -void setupsignals() +void +setupsignals() { struct sigaction sa; for(int i = 0; i < LENGTH(blocks); i++) @@ -131,7 +138,8 @@ void setupsignals() } #endif -int getstatus(char *str, char *last) +int +getstatus(char *str, char *last) { strcpy(last, str); str[0] = '\0'; @@ -144,7 +152,8 @@ int getstatus(char *str, char *last) return strcmp(str, last);//0 if they are the same } -void setroot() +void +setroot() { if (!getstatus(statusstr[0], statusstr[1]))//Only set root if text has changed. return; @@ -158,7 +167,8 @@ void setroot() XCloseDisplay(dpy); } -void pstdout() +void +pstdout() { if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed. return; @@ -167,7 +177,8 @@ void pstdout() } -void statusloop() +void +statusloop() { #ifndef __OpenBSD__ setupsignals(); @@ -184,13 +195,16 @@ void statusloop() } #ifndef __OpenBSD__ -void sighandler(int signum) +void +sighandler(int signum) { getsigcmds(signum-SIGRTMIN); + printf("caught status: %d\n", signum); writestatus(); } -void buttonhandler(int sig, siginfo_t *si, void *ucontext) +void +buttonhandler(int sig, siginfo_t *si, void *ucontext) { char button[2] = {'0' + si->si_value.sival_int & 0xff, '\0'}; pid_t process_id = getpid(); @@ -204,7 +218,7 @@ void buttonhandler(int sig, siginfo_t *si, void *ucontext) if (current->signal == sig) break; } - char shcmd[1024]; + char shcmd[2048]; sprintf(shcmd,"%s && kill -%d %d",current->command, current->signal+34,process_id); char *command[] = { "/bin/sh", "-c", shcmd, NULL }; setenv("BLOCK_BUTTON", button, 1); @@ -216,13 +230,15 @@ void buttonhandler(int sig, siginfo_t *si, void *ucontext) #endif -void termhandler(int signum) +void +termhandler(int signum) { statusContinue = 0; exit(0); } -int main(int argc, char** argv) +int +main(int argc, char** argv) { for(int i = 0; i < argc; i++) {