sorta fixed bug with sleep and timing where interrupting

dwmblocks by clicking on the bar would interrupt the sleep causing it to
reload everything sooner than it should, which would cause slower things
to not update and disappear untill they were reloaded. This was
especially a problem with using scrolling on blocks.  Still occasionally
breaks but is much less horrible.
This commit is contained in:
dfuehrer 2021-03-13 22:49:34 -07:00
parent d747fa7bc1
commit 73fd031a1d

View file

@ -2,6 +2,7 @@
#include<stdio.h> #include<stdio.h>
#include<string.h> #include<string.h>
#include<unistd.h> #include<unistd.h>
#include <time.h>
#include<signal.h> #include<signal.h>
#include<X11/Xlib.h> #include<X11/Xlib.h>
#define LENGTH(X) (sizeof(X) / sizeof (X[0])) #define LENGTH(X) (sizeof(X) / sizeof (X[0]))
@ -91,10 +92,11 @@ void getcmds(int time)
for(int i = 0; i < LENGTH(blocks); i++) for(int i = 0; i < LENGTH(blocks); i++)
{ {
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,statusbar[i]);
} }
} }
}
#ifndef __OpenBSD__ #ifndef __OpenBSD__
void getsigcmds(int signal) void getsigcmds(int signal)
@ -103,10 +105,11 @@ void getsigcmds(int signal)
for (int i = 0; i < LENGTH(blocks); i++) for (int i = 0; i < LENGTH(blocks); i++)
{ {
current = blocks + i; current = blocks + i;
if (current->signal == signal) if (current->signal == signal){
getcmd(current,statusbar[i]); getcmd(current,statusbar[i]);
} }
} }
}
void setupsignals() void setupsignals()
{ {
@ -173,13 +176,27 @@ void statusloop()
setupsignals(); setupsignals();
#endif #endif
int i = 0; int i = 0;
int previ = -1;
int gotscrewed = 0;
struct timespec sleeptime = {1, 0};
struct timespec left;
getcmds(-1); getcmds(-1);
while(statusContinue) while(statusContinue)
{ {
if(i != previ){
getcmds(i); getcmds(i);
writestatus(); writestatus();
sleep(1.0); }
gotscrewed = nanosleep(&sleeptime, &left);
previ = i;
/* long diff = (left.tv_sec + (left.tv_nsec + 500000000l) / 1000000000l); */
/* i += 1 - diff; */
if(gotscrewed != -1){
i++; i++;
/* }else{ */
/* printf("sec and nanosec left: %d, %d", left.tv_sec, left.tv_nsec); */
}
} }
} }