diff --git a/config.def.h b/config.def.h index 8e53261..0eb2264 100644 --- a/config.def.h +++ b/config.def.h @@ -37,8 +37,9 @@ static const char delimiter[] = { ' ', ' ', ' ', DELIMITERENDCHAR }; one newline character at the end) * pathc - path of the program used for handling clicks on the block */ -/* 1 interval = seconds, nanoseconds */ -static const struct timespec interval = { 1, 0 }; +/* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */ +#define INTERVALs 1 +#define INTERVALn 0 static Block blocks[] = { /* pathu pathc interval signal */ diff --git a/dwmblocks.c b/dwmblocks.c index 98089c5..d3ae92b 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -19,6 +19,9 @@ #include "config.h" +_Static_assert(INTERVALs >= 0, "INTERVALs must be greater than or equal to 0"); +_Static_assert(INTERVALn >= 0 && INTERVALn <= 999999999, "INTERVALn must be between 0 and 999999999"); + static void buttonhandler(int sig, siginfo_t *info, void *ucontext); static void cleanup(); static void setupsignals(); @@ -132,29 +135,19 @@ statusloop() int i; struct timespec t; - /* first run */ sigprocmask(SIG_BLOCK, &blocksigmask, NULL); for (Block *block = blocks; block->pathu; block++) if (block->interval >= 0) updateblock(block, NILL); - updatestatus(); - sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); - t = interval; - while (nanosleep(&t, &t) == -1) - if (errno != EINTR) { - perror("statusloop - nanosleep"); - exit(1); - } - /* main loop */ for (i = 1; ; i++) { + updatestatus(); + sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); + t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn; + while (nanosleep(&t, &t) == -1); sigprocmask(SIG_BLOCK, &blocksigmask, NULL); for (Block *block = blocks; block->pathu; block++) if (block->interval > 0 && i % block->interval == 0) updateblock(block, NILL); - updatestatus(); - sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); - t = interval; - while (nanosleep(&t, &t) == -1); } }