From 5fb7fcd7e1d89a5fad0d5e5144c1eff43d910a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=9Cmit=20=C3=96zden?= Date: Sat, 25 Feb 2023 01:04:53 +0300 Subject: [PATCH] fixed disappearing block issue when signaling --- dwmblocks.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index befd252..c8f77b7 100644 --- 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); }