From 3da92ebccb863394a3501ce2d9cbe60ad9aafc8c Mon Sep 17 00:00:00 2001 From: Aidan Date: Mon, 4 Nov 2019 15:34:34 -0700 Subject: Changed delimeter to accept multiple characters. --- dwmblocks.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 2db3489..76e7377 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -56,13 +56,20 @@ void getcmd(const Block *block, char *output) return; //int N = strlen(output); char c; - int i = strlen(block->icon); + int sl; + int i = sl = strlen(block->icon); while((c = fgetc(cmdf)) != EOF) output[i++] = c; - if (delim != '\0' && --i) - output[i++] = delim; - output[i++] = '\0'; pclose(cmdf); + if (i == sl) { //return empty string if command has no output + output[0] = '\0'; + return; + } + if (delim[0] != '\0' && --i) + for (int j = 0; delim[j]; j++) + output[i++] = delim[j]; + else + output[--i] = '\0'; } void getcmds(int time) @@ -104,7 +111,8 @@ void getstatus(char *str) { strcpy(str + j, statusbar[i]); } - str[--j] = '\0'; + for (int i = 0; delim[i]; i++) + str[--j] = '\0'; } @@ -159,7 +167,7 @@ int main(int argc, char** argv) for(int i = 0; i < argc; i++) { if (!strcmp("-d",argv[i])) - delim = argv[++i][0]; + delim = argv[++i]; } signal(SIGTERM, termhandler); signal(SIGINT, termhandler); -- cgit v1.2.3-13-gbd6f From 72dc44f963bfdfbef141cbba9cf23f1358a335a3 Mon Sep 17 00:00:00 2001 From: Aidan Date: Thu, 7 Nov 2019 13:07:19 -0700 Subject: Revert "Changed delimeter to accept multiple characters." Bug was found where certain modules caused dwm to lag horribly. Reverting until a fix can be found. This reverts commit 3da92ebccb863394a3501ce2d9cbe60ad9aafc8c. --- dwmblocks.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 76e7377..2db3489 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -56,20 +56,13 @@ void getcmd(const Block *block, char *output) return; //int N = strlen(output); char c; - int sl; - int i = sl = strlen(block->icon); + int i = strlen(block->icon); while((c = fgetc(cmdf)) != EOF) output[i++] = c; + if (delim != '\0' && --i) + output[i++] = delim; + output[i++] = '\0'; pclose(cmdf); - if (i == sl) { //return empty string if command has no output - output[0] = '\0'; - return; - } - if (delim[0] != '\0' && --i) - for (int j = 0; delim[j]; j++) - output[i++] = delim[j]; - else - output[--i] = '\0'; } void getcmds(int time) @@ -111,8 +104,7 @@ void getstatus(char *str) { strcpy(str + j, statusbar[i]); } - for (int i = 0; delim[i]; i++) - str[--j] = '\0'; + str[--j] = '\0'; } @@ -167,7 +159,7 @@ int main(int argc, char** argv) for(int i = 0; i < argc; i++) { if (!strcmp("-d",argv[i])) - delim = argv[++i]; + delim = argv[++i][0]; } signal(SIGTERM, termhandler); signal(SIGINT, termhandler); -- cgit v1.2.3-13-gbd6f From 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 Mon Sep 17 00:00:00 2001 From: Aidan Date: Wed, 13 Nov 2019 13:58:20 -0700 Subject: Made dwmblocks way more efficient by only setting the name of the root window when something has changed. --- dwmblocks.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 2db3489..71760aa 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -17,7 +17,7 @@ void replace(char *str, char old, char new); void getcmds(int time); void getsigcmds(int signal); void setupsignals(); -void getstatus(char *str); +int getstatus(char *str, char *last); void setroot(); void statusloop(); void statusinit(); @@ -31,12 +31,8 @@ static Display *dpy; static int screen; static Window root; static char statusbar[LENGTH(blocks)][50] = {0}; -static char statusstr[256]; -static char *statuscat; -static const char *volupcmd[] = { "volup", NULL }; -static const char *voldowncmd[] = { "voldown", NULL }; -static const char *volmutecmd[] = { "volmute", NULL }; -static int statusContinue = 1,volmuted = 0; +static char statusstr[2][256]; +static int statusContinue = 1; void replace(char *str, char old, char new) { @@ -97,27 +93,29 @@ void setupsignals() } -void getstatus(char *str) +int getstatus(char *str, char *last) { + strcpy(last, str); int j = 0; for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++])) { strcpy(str + j, statusbar[i]); } str[--j] = '\0'; - + return strcmp(str, last);//0 if they are the same } void setroot() { + if (!getstatus(statusstr[0], statusstr[1]))//Only set root if text has changed. + return; Display *d = XOpenDisplay(NULL); if (d) { dpy = d; } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); - getstatus(statusstr); - XStoreName(dpy, root, statusstr); + XStoreName(dpy, root, statusstr[0]); XCloseDisplay(dpy); } -- cgit v1.2.3-13-gbd6f From 1766af7d5e0facb911c664584fc703c5f8f89092 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 26 Nov 2019 22:43:16 -0700 Subject: Added -p option for printing to stdout rather then setting the root window for compatibility with other wms. --- dwmblocks.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 71760aa..3071243 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -33,6 +33,10 @@ static Window root; static char statusbar[LENGTH(blocks)][50] = {0}; static char statusstr[2][256]; static int statusContinue = 1; +<<<<<<< HEAD +static void (*writestatus) () = setroot; +======= +>>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 void replace(char *str, char old, char new) { @@ -50,7 +54,6 @@ void getcmd(const Block *block, char *output) FILE *cmdf = popen(cmd,"r"); if (!cmdf) return; - //int N = strlen(output); char c; int i = strlen(block->icon); while((c = fgetc(cmdf)) != EOF) @@ -96,12 +99,21 @@ void setupsignals() int getstatus(char *str, char *last) { strcpy(last, str); +<<<<<<< HEAD + str[0] = '\0'; + for(int i = 0; i < LENGTH(blocks); i++) +======= int j = 0; for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++])) +>>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 { - strcpy(str + j, statusbar[i]); + strcat(str, statusbar[i]); } +<<<<<<< HEAD + str[strlen(str)-1] = '\0'; +======= str[--j] = '\0'; +>>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 return strcmp(str, last);//0 if they are the same } @@ -119,6 +131,14 @@ void setroot() XCloseDisplay(dpy); } +void pstdout() +{ + if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed. + return; + printf("%s\n",statusstr[0]); + fflush(stdout); +} + void statusloop() { @@ -128,7 +148,7 @@ void statusloop() while(statusContinue) { getcmds(i); - setroot(); + writestatus(); sleep(1.0); i++; } @@ -143,7 +163,7 @@ void statusinit() void sighandler(int signum) { getsigcmds(signum-SIGRTMIN); - setroot(); + writestatus(); } void termhandler(int signum) @@ -158,6 +178,8 @@ int main(int argc, char** argv) { if (!strcmp("-d",argv[i])) delim = argv[++i][0]; + else if(!strcmp("-p",argv[i])) + writestatus = pstdout; } signal(SIGTERM, termhandler); signal(SIGINT, termhandler); -- cgit v1.2.3-13-gbd6f From b685f2805f483c2a0df89695ac7a7f472172debe Mon Sep 17 00:00:00 2001 From: Aidan Hubert Date: Wed, 27 Nov 2019 05:50:38 +0000 Subject: Fixed garbled last commit --- dwmblocks.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 3071243..395b565 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -33,10 +33,7 @@ static Window root; static char statusbar[LENGTH(blocks)][50] = {0}; static char statusstr[2][256]; static int statusContinue = 1; -<<<<<<< HEAD static void (*writestatus) () = setroot; -======= ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 void replace(char *str, char old, char new) { @@ -99,21 +96,12 @@ void setupsignals() int getstatus(char *str, char *last) { strcpy(last, str); -<<<<<<< HEAD str[0] = '\0'; for(int i = 0; i < LENGTH(blocks); i++) -======= - int j = 0; - for(int i = 0; i < LENGTH(blocks); j+=strlen(statusbar[i++])) ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 { strcat(str, statusbar[i]); } -<<<<<<< HEAD str[strlen(str)-1] = '\0'; -======= - str[--j] = '\0'; ->>>>>>> 5ff59d4e8ba9c64963d36c8ea51e7a1d644aef48 return strcmp(str, last);//0 if they are the same } -- cgit v1.2.3-13-gbd6f From 09a00ab345f1c1c4bce5496f7c7d054476e35392 Mon Sep 17 00:00:00 2001 From: Aidan Date: Sat, 30 Nov 2019 02:05:10 -0700 Subject: fixed issue causing segfault on ARM systems --- dwmblocks.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index 395b565..f7f23cc 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -54,7 +54,11 @@ void getcmd(const Block *block, char *output) char c; int i = strlen(block->icon); while((c = fgetc(cmdf)) != EOF) + { output[i++] = c; + if(c == '\n') + break; + } if (delim != '\0' && --i) output[i++] = delim; output[i++] = '\0'; -- cgit v1.2.3-13-gbd6f From 377f9903318d89934593348cda91c3c8fef4158c Mon Sep 17 00:00:00 2001 From: Aidan Date: Sat, 30 Nov 2019 14:43:33 -0700 Subject: Switched to fgets instead of using fgetc --- dwmblocks.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index f7f23cc..ad8e91c 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -5,6 +5,7 @@ #include #include #define LENGTH(X) (sizeof(X) / sizeof (X[0])) +#define CMDLENGTH 50 typedef struct { char* icon; @@ -20,7 +21,6 @@ void setupsignals(); int getstatus(char *str, char *last); void setroot(); void statusloop(); -void statusinit(); void sighandler(int signum); void termhandler(int signum); @@ -30,7 +30,7 @@ void termhandler(int signum); static Display *dpy; static int screen; static Window root; -static char statusbar[LENGTH(blocks)][50] = {0}; +static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][256]; static int statusContinue = 1; static void (*writestatus) () = setroot; @@ -53,12 +53,8 @@ void getcmd(const Block *block, char *output) return; char c; int i = strlen(block->icon); - while((c = fgetc(cmdf)) != EOF) - { - output[i++] = c; - if(c == '\n') - break; - } + fgets(output+i, CMDLENGTH-i, cmdf); + i = strlen(output); if (delim != '\0' && --i) output[i++] = delim; output[i++] = '\0'; @@ -102,9 +98,7 @@ int getstatus(char *str, char *last) strcpy(last, str); str[0] = '\0'; for(int i = 0; i < LENGTH(blocks); i++) - { strcat(str, statusbar[i]); - } str[strlen(str)-1] = '\0'; return strcmp(str, last);//0 if they are the same } @@ -146,11 +140,6 @@ void statusloop() } } -void statusinit() -{ - statusloop(); -} - void sighandler(int signum) { @@ -175,5 +164,5 @@ int main(int argc, char** argv) } signal(SIGTERM, termhandler); signal(SIGINT, termhandler); - statusinit(); + statusloop(); } -- cgit v1.2.3-13-gbd6f From fa4eeff38d5c2787938b2defde4390d585ae4887 Mon Sep 17 00:00:00 2001 From: Aidan Date: Mon, 16 Dec 2019 14:35:29 -0700 Subject: Added ifndef for openbsd compatibility. SIGRTMIN is not defined on OpenBSD. --- dwmblocks.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'dwmblocks.c') diff --git a/dwmblocks.c b/dwmblocks.c index ad8e91c..88bdfb0 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -16,12 +16,14 @@ typedef struct { void sighandler(int num); void replace(char *str, char old, char new); void getcmds(int time); +#ifndef __OpenBSD__ void getsigcmds(int signal); void setupsignals(); +void sighandler(int signum); +#endif int getstatus(char *str, char *last); void setroot(); void statusloop(); -void sighandler(int signum); void termhandler(int signum); @@ -72,6 +74,7 @@ void getcmds(int time) } } +#ifndef __OpenBSD__ void getsigcmds(int signal) { const Block *current; @@ -92,6 +95,7 @@ void setupsignals() } } +#endif int getstatus(char *str, char *last) { @@ -128,7 +132,9 @@ void pstdout() void statusloop() { +#ifndef __OpenBSD__ setupsignals(); +#endif int i = 0; getcmds(-1); while(statusContinue) @@ -140,12 +146,13 @@ void statusloop() } } - +#ifndef __OpenBSD__ void sighandler(int signum) { getsigcmds(signum-SIGRTMIN); writestatus(); } +#endif void termhandler(int signum) { -- cgit v1.2.3-13-gbd6f