diff --git a/dwmblocks.c b/dwmblocks.c index 0342970..b88eb5a 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -29,6 +29,7 @@ typedef struct { static void buttonhandler(int signal, siginfo_t *si, void *ucontext); static void getcmd(Block *block, int sigval); +static void setroot(); static void setupsignals(); static void sighandler(int signal, siginfo_t *si, void *ucontext); static void statusloop(); @@ -111,6 +112,17 @@ getcmd(Block *block, int sigval) } } +void +setroot() +{ + if (updatestatus()) { + sigprocmask(SIG_BLOCK, &blocksigmask, NULL); + XStoreName(dpy, DefaultRootWindow(dpy), statusstr); + XSync(dpy, False); + sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); + } +} + void setupsignals() { @@ -145,7 +157,7 @@ setupsignals() /* to handle update signals for individual blocks */ sa.sa_flags |= SA_NODEFER; - sa.sa_mask = blocksigmask; + // sigemptyset(&sa.sa_mask); sa.sa_sigaction = sighandler; for (Block *current = blocks; current->pathu; current++) if (current->signal > 0) @@ -157,18 +169,18 @@ sighandler(int signal, siginfo_t *si, void *ucontext) { signal -= SIGRTMIN; for (Block *current = blocks; current->pathu; current++) - if (current->signal == signal) + if (current->signal == signal) { + sigprocmask(SIG_BLOCK, &blocksigmask, NULL); getcmd(current, si->si_value.sival_int); - if (updatestatus()) { - XStoreName(dpy, DefaultRootWindow(dpy), statusstr); - XSync(dpy, False); - } + sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); + } + setroot(); } void statusloop() { - int i = 0; + int i; /* first run */ for (Block *current = blocks; current->pathu; current++) @@ -177,7 +189,9 @@ statusloop() getcmd(current, NILL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); } - goto enterloop; + setroot(); + sleep(SLEEPINTERVAL); + i = SLEEPINTERVAL; /* main loop */ while (statuscontinue) { for (Block *current = blocks; current->pathu; current++) @@ -186,13 +200,7 @@ statusloop() getcmd(current, NILL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); } -enterloop: - if (updatestatus()) { - sigprocmask(SIG_BLOCK, &blocksigmask, NULL); - XStoreName(dpy, DefaultRootWindow(dpy), statusstr); - XSync(dpy, False); - sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); - } + setroot(); sleep(SLEEPINTERVAL); i += SLEEPINTERVAL; }