Mitigates disapearing blocks on fast mouse interaction
This commit is contained in:
parent
747067e64e
commit
e7b3d9d9d6
1 changed files with 21 additions and 6 deletions
27
dwmblocks.c
27
dwmblocks.c
|
@ -13,6 +13,7 @@ typedef struct {
|
||||||
unsigned int interval;
|
unsigned int interval;
|
||||||
unsigned int signal;
|
unsigned int signal;
|
||||||
} Block;
|
} Block;
|
||||||
|
char** last_updates;
|
||||||
void sighandler(int num);
|
void sighandler(int num);
|
||||||
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
||||||
void replace(char *str, char old, char new);
|
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
|
//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)
|
if (block->signal)
|
||||||
{
|
{
|
||||||
|
@ -77,10 +78,15 @@ void getcmd(const Block *block, char *output)
|
||||||
int i = strlen(block->icon);
|
int i = strlen(block->icon);
|
||||||
fgets(output+i, CMDLENGTH-(strlen(delim)+1), cmdf);
|
fgets(output+i, CMDLENGTH-(strlen(delim)+1), cmdf);
|
||||||
remove_all(output, '\n');
|
remove_all(output, '\n');
|
||||||
|
if(i == strlen(output))
|
||||||
|
strcpy(output+i, last_update);
|
||||||
|
else
|
||||||
|
strcpy(last_update, output+i);
|
||||||
|
|
||||||
i = strlen(output);
|
i = strlen(output);
|
||||||
if ((i > 0 && block != &blocks[LENGTH(blocks) - 1]))
|
if ((i > 0 && block != &blocks[LENGTH(blocks) - 1]))
|
||||||
strcat(output, delim);
|
strcat(output, delim);
|
||||||
i+=strlen(delim);
|
i+=strlen(delim);
|
||||||
output[i++] = '\0';
|
output[i++] = '\0';
|
||||||
pclose(cmdf);
|
pclose(cmdf);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +98,7 @@ void getcmds(int time)
|
||||||
{
|
{
|
||||||
current = blocks + i;
|
current = blocks + i;
|
||||||
if ((current->interval != 0 && time % current->interval == 0) || time == -1)
|
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;
|
current = blocks + i;
|
||||||
if (current->signal == signal)
|
if (current->signal == signal)
|
||||||
getcmd(current,statusbar[i]);
|
getcmd(current,last_updates[i],statusbar[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +178,11 @@ void statusloop()
|
||||||
#ifndef __OpenBSD__
|
#ifndef __OpenBSD__
|
||||||
setupsignals();
|
setupsignals();
|
||||||
#endif
|
#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;
|
int i = 0;
|
||||||
getcmds(-1);
|
getcmds(-1);
|
||||||
while(statusContinue)
|
while(statusContinue)
|
||||||
|
@ -218,6 +229,10 @@ void buttonhandler(int sig, siginfo_t *si, void *ucontext)
|
||||||
|
|
||||||
void termhandler(int signum)
|
void termhandler(int signum)
|
||||||
{
|
{
|
||||||
|
for(int i = 0; i < LENGTH(blocks); i++) {
|
||||||
|
free(last_updates[i]);
|
||||||
|
}
|
||||||
|
free(last_updates);
|
||||||
statusContinue = 0;
|
statusContinue = 0;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue