Added dwmblocks-pulse-listener.c

This commit is contained in:
2023-02-23 09:22:54 -08:00
parent 81dcef14c4
commit e18e6ac3a9
5 changed files with 141 additions and 67 deletions
+10 -10
View File
@@ -64,7 +64,7 @@ void getcmd(const Block *block, char *output) {
return;
}
int i = strlen(block->icon);
fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
fgets(output + i, CMDLENGTH - i - delimLen, cmdf);
i = strlen(output);
if (i == 0) {
//return if block and command output are both empty
@@ -72,9 +72,9 @@ void getcmd(const Block *block, char *output) {
return;
}
//only chop off newline if one is present at the end
i = output[i-1] == '\n' ? i-1 : i;
i = output[i - 1] == '\n' ? i - 1 : i;
if (delim[0] != '\0') {
strncpy(output+i, delim, delimLen);
strncpy(output + i, delim, delimLen);
} else {
output[i++] = '\0';
}
@@ -83,7 +83,7 @@ void getcmd(const Block *block, char *output) {
void getcmds(int time) {
const Block* current;
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
for (unsigned int i = 0; i < LENGTH(blocks); ++i) {
current = blocks + i;
if ((current->interval != 0 && time % current->interval == 0) || time == -1) {
getcmd(current,statusbar[i]);
@@ -93,7 +93,7 @@ void getcmds(int time) {
void getsigcmds(unsigned int signal) {
const Block *current;
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
for (unsigned int i = 0; i < LENGTH(blocks); ++i) {
current = blocks + i;
if (current->signal == signal) {
getcmd(current,statusbar[i]);
@@ -116,14 +116,14 @@ void sighandler(int signum) {
void setupsignals() {
#ifndef __OpenBSD__
/* initialize all real time signals with dummy handler */
for (int i = SIGRTMIN; i <= SIGRTMAX; i++) {
for (int i = SIGRTMIN; i <= SIGRTMAX; ++i) {
signal(i, dummysighandler);
}
#endif
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
for (unsigned int i = 0; i < LENGTH(blocks); ++i) {
if (blocks[i].signal > 0) {
signal(SIGMINUS+blocks[i].signal, sighandler);
signal(SIGMINUS + blocks[i].signal, sighandler);
}
}
@@ -132,7 +132,7 @@ void setupsignals() {
int getstatus(char *str, char *last) {
strcpy(last, str);
str[0] = '\0';
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
for (unsigned int i = 0; i < LENGTH(blocks); ++i) {
strcat(str, statusbar[i]);
}
str[strlen(str)-strlen(delim)] = '\0';
@@ -160,7 +160,7 @@ int gcd(int n1, int n2) {
void statusloop() {
setupsignals();
unsigned int interval = -1;
for (int i = 0; i < LENGTH(blocks); i++){
for (int i = 0; i < LENGTH(blocks); ++i){
if (blocks[i].interval){
interval = gcd(blocks[i].interval, interval);
}