dwmblocks

my build of dwmblocks
git clone git://giovanniamaral.com/dwmblocks
Log | Files | Refs | README | LICENSE

commit 5fb7fcd7e1d89a5fad0d5e5144c1eff43d910a4b
parent a933ce0d6109524b393feb3e7156cbf0de88b42c
Author: Mehmet Ümit Özden <ozdenmehmetumit@gmail.com>
Date:   Sat, 25 Feb 2023 01:04:53 +0300

fixed disappearing block issue when signaling

Diffstat:
Mdwmblocks.c | 29+++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/dwmblocks.c b/dwmblocks.c @@ -58,25 +58,26 @@ static int returnStatus = 0; //opens process *cmd and stores output in *output void getcmd(const Block *block, char *output) { - strcpy(output, block->icon); + //make sure status is same until output is ready + char tempstatus[CMDLENGTH] = {0}; + strcpy(tempstatus, block->icon); FILE *cmdf = popen(block->command, "r"); if (!cmdf) return; int i = strlen(block->icon); - fgets(output+i, CMDLENGTH-i-delimLen, cmdf); - i = strlen(output); - if (i == 0) { - //return if block and command output are both empty - pclose(cmdf); - return; - } - //only chop off newline if one is present at the end - i = output[i-1] == '\n' ? i-1 : i; - if (delim[0] != '\0') { - strncpy(output+i, delim, delimLen); + fgets(tempstatus+i, CMDLENGTH-i-delimLen, cmdf); + i = strlen(tempstatus); + //if block and command output are both not empty + if (i != 0) { + //only chop off newline if one is present at the end + i = tempstatus[i-1] == '\n' ? i-1 : i; + if (delim[0] != '\0') { + strncpy(tempstatus+i, delim, delimLen); + } + else + tempstatus[i++] = '\0'; } - else - output[i++] = '\0'; + strcpy(output, tempstatus); pclose(cmdf); }