summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Ciuffardi <federico.ciuffardi@outlook.com>2021-02-07 03:57:01 -0300
committerFederico Ciuffardi <federico.ciuffardi@outlook.com>2021-02-07 18:56:42 -0300
commite7b3d9d9d6ca1ac2e8efc7f009bd0ed9ba5f18dc (patch)
treeee0e8e2e43fdb2c1a74c336ba4b827c39391f09f
parent747067e64e64c2723c5a71f518498c2162195d45 (diff)
downloaddwmblocks-e7b3d9d9d6ca1ac2e8efc7f009bd0ed9ba5f18dc.tar.gz
dwmblocks-e7b3d9d9d6ca1ac2e8efc7f009bd0ed9ba5f18dc.tar.bz2
dwmblocks-e7b3d9d9d6ca1ac2e8efc7f009bd0ed9ba5f18dc.zip
Mitigates disapearing blocks on fast mouse interaction
-rw-r--r--dwmblocks.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/dwmblocks.c b/dwmblocks.c
index 68267d7..12648ef 100644
--- a/dwmblocks.c
+++ b/dwmblocks.c
@@ -13,6 +13,7 @@ typedef struct {
unsigned int interval;
unsigned int signal;
} Block;
+char** last_updates;
void sighandler(int num);
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
void replace(char *str, char old, char new);
@@ -61,7 +62,7 @@ void remove_all(char *str, char to_remove) {
}
//opens process *cmd and stores output in *output
-void getcmd(const Block *block, char *output)
+void getcmd(const Block *block, char* last_update , char *output)
{
if (block->signal)
{
@@ -77,10 +78,15 @@ void getcmd(const Block *block, char *output)
int i = strlen(block->icon);
fgets(output+i, CMDLENGTH-(strlen(delim)+1), cmdf);
remove_all(output, '\n');
+ if(i == strlen(output))
+ strcpy(output+i, last_update);
+ else
+ strcpy(last_update, output+i);
+
i = strlen(output);
- if ((i > 0 && block != &blocks[LENGTH(blocks) - 1]))
- strcat(output, delim);
- i+=strlen(delim);
+ if ((i > 0 && block != &blocks[LENGTH(blocks) - 1]))
+ strcat(output, delim);
+ i+=strlen(delim);
output[i++] = '\0';
pclose(cmdf);
}
@@ -92,7 +98,7 @@ void getcmds(int time)
{
current = blocks + i;
if ((current->interval != 0 && time % current->interval == 0) || time == -1)
- getcmd(current,statusbar[i]);
+ getcmd(current,last_updates[i],statusbar[i]);
}
}
@@ -104,7 +110,7 @@ void getsigcmds(int signal)
{
current = blocks + i;
if (current->signal == signal)
- getcmd(current,statusbar[i]);
+ getcmd(current,last_updates[i],statusbar[i]);
}
}
@@ -172,6 +178,11 @@ void statusloop()
#ifndef __OpenBSD__
setupsignals();
#endif
+ last_updates = malloc(sizeof(char*) * LENGTH(blocks));
+ for(int i = 0; i < LENGTH(blocks); i++) {
+ last_updates[i] = malloc(sizeof(char) * CMDLENGTH);
+ strcpy(last_updates[i],"");
+ }
int i = 0;
getcmds(-1);
while(statusContinue)
@@ -218,6 +229,10 @@ void buttonhandler(int sig, siginfo_t *si, void *ucontext)
void termhandler(int signum)
{
+ for(int i = 0; i < LENGTH(blocks); i++) {
+ free(last_updates[i]);
+ }
+ free(last_updates);
statusContinue = 0;
exit(0);
}
Software created with 💖