From 92ecfd9b81f856747840650aaf3c802fdb0cca2b Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Wed, 24 Jan 2024 23:02:21 +0100 Subject: [PATCH] custom changes --- .gitignore | 3 +++ Makefile | 9 +++++++-- blocks.def.h | 16 ++++++---------- generate_patch.sh | 1 + someblocks.c | 32 ++++++++++++++++++-------------- 5 files changed, 35 insertions(+), 26 deletions(-) create mode 100755 generate_patch.sh diff --git a/.gitignore b/.gitignore index a7f1a30..0cd705e 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ modules.order Module.symvers Mkfile.old dkms.conf + +# Patch file for NixOS +custom_someblocks.patch diff --git a/Makefile b/Makefile index f0c027b..00243ad 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,19 @@ PREFIX ?= /usr/local MANPREFIX ?= $(PREFIX)/share/man CC ?= cc +DEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused-parameter -Wshadow -Wunused-macros\ + -Werror=strict-prototypes -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types -Wfloat-conversion\ + -Ofast -flto + output: someblocks.c blocks.def.h blocks.h - ${CC} someblocks.c $(LDFLAGS) -o someblocks + ${CC} someblocks.c $(LDFLAGS) $(DEVCFLAGS) -o someblocks + strip someblocks blocks.h: cp blocks.def.h $@ clean: - rm -f *.o *.gch someblocks + rm -f *.o *.gch someblocks blocks.h install: output mkdir -p $(DESTDIR)$(PREFIX)/bin install -m 0755 someblocks $(DESTDIR)$(PREFIX)/bin/someblocks diff --git a/blocks.def.h b/blocks.def.h index 7df3a64..b620421 100644 --- a/blocks.def.h +++ b/blocks.def.h @@ -1,16 +1,12 @@ -//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*/ - {"Mem:", "free -h | awk '/^Mem/ { print $3\"/\"$2 }' | sed s/i//g", 30, 0}, - - {"", "date '+%b %d (%a) %I:%M%p'", 5, 0}, - - /* Updates whenever "pkill -SIGRTMIN+10 someblocks" is ran */ - /* {"", "date '+%b %d (%a) %I:%M%p'", 0, 10}, */ + /*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/ + {"󱄠 ", "pamixer --get-volume-human", 1, 0}, + {"󰍛 ", "free -h | awk '/^Mem/ { print $3\"/\"$2 }'", 1, 0}, + {"󰥔 ", "date -Is", 1, 0}, + /* Updates whenever "pkill -SIGRTMIN+10 someblocks" is ran */ + /* {"", "date '+%b %d (%a) %I:%M%p'", 0, 10}, */ }; - - //sets delimeter between status commands. NULL character ('\0') means no delimeter. static char delim[] = " | "; static unsigned int delimLen = 5; diff --git a/generate_patch.sh b/generate_patch.sh new file mode 100755 index 0000000..9c02db9 --- /dev/null +++ b/generate_patch.sh @@ -0,0 +1 @@ +git diff 540a90e521e7c17c2010e038b934b73d2cf46df3 > custom_someblocks.patch diff --git a/someblocks.c b/someblocks.c index f149896..4b3701b 100644 --- a/someblocks.c +++ b/someblocks.c @@ -30,33 +30,36 @@ void dummysighandler(int num); void sighandler(int num); void getcmds(int time); void getsigcmds(unsigned int signal); -void setupsignals(); +void setupsignals(void); void sighandler(int signum); int getstatus(char *str, char *last); -void statusloop(); -void termhandler(); -void pstdout(); -void psomebar(); -static void (*writestatus) () = psomebar; +void statusloop(void); +void termhandler(int sig); +void pstdout(void); +void psomebar(void); +static void (*writestatus) (void) = psomebar; #include "blocks.h" static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][STATUSLENGTH]; static int statusContinue = 1; -static int returnStatus = 0; static char somebarPath[128]; static int somebarFd = -1; //opens process *cmd and stores output in *output void getcmd(const Block *block, char *output) { + FILE *cmdf; + int i; strcpy(output, block->icon); - FILE *cmdf = popen(block->command, "r"); + cmdf = popen(block->command, "r"); if (!cmdf) return; - int i = strlen(block->icon); - fgets(output+i, CMDLENGTH-i-delimLen, cmdf); + i = strlen(block->icon); + if (fgets(output+i, CMDLENGTH-i-delimLen, cmdf) != (output+i)) { + exit(1); + } i = strlen(output); if (i == 0) { //return if block and command output are both empty @@ -152,15 +155,16 @@ void psomebar() void statusloop() { + int i; setupsignals(); - int i = 0; + i = 0; getcmds(-1); while (1) { getcmds(i++); writestatus(); if (!statusContinue) break; - sleep(1.0); + sleep(1); } } @@ -178,12 +182,12 @@ void sighandler(int signum) writestatus(); } -void termhandler() +void termhandler(int sig) { statusContinue = 0; } -void sigpipehandler() +void sigpipehandler(int sig) { close(somebarFd); somebarFd = -1;