From 73fd031a1d8743bae3b8988a3597aa613cc86a92 Mon Sep 17 00:00:00 2001 From: dfuehrer Date: Sat, 13 Mar 2021 22:49:34 -0700 Subject: [PATCH] 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. --- dwmblocks.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index d135a7d..1d31a65 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #define LENGTH(X) (sizeof(X) / sizeof (X[0])) @@ -91,8 +92,9 @@ void getcmds(int time) for(int i = 0; i < LENGTH(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]); + } } } @@ -103,8 +105,9 @@ void getsigcmds(int signal) for (int i = 0; i < LENGTH(blocks); i++) { current = blocks + i; - if (current->signal == signal) + if (current->signal == signal){ getcmd(current,statusbar[i]); + } } } @@ -173,13 +176,27 @@ void statusloop() setupsignals(); #endif int i = 0; + int previ = -1; + int gotscrewed = 0; + struct timespec sleeptime = {1, 0}; + struct timespec left; getcmds(-1); while(statusContinue) { - getcmds(i); - writestatus(); - sleep(1.0); - i++; + if(i != previ){ + getcmds(i); + writestatus(); + } + gotscrewed = nanosleep(&sleeptime, &left); + previ = i; + /* long diff = (left.tv_sec + (left.tv_nsec + 500000000l) / 1000000000l); */ + /* i += 1 - diff; */ + if(gotscrewed != -1){ + i++; + /* }else{ */ + /* printf("sec and nanosec left: %d, %d", left.tv_sec, left.tv_nsec); */ + } + } }