This commit is contained in:
Ashish Kumar Yadav 2021-02-11 00:10:26 +05:30
parent ea40011a5f
commit 9ac5b1f37b

View file

@ -18,7 +18,6 @@
static void buttonhandler(int sig, siginfo_t *info, void *ucontext); static void buttonhandler(int sig, siginfo_t *info, void *ucontext);
static void cleanup(); static void cleanup();
static void setroot();
static void setupsignals(); static void setupsignals();
static void sighandler(int sig, siginfo_t *si, void *ucontext); static void sighandler(int sig, siginfo_t *si, void *ucontext);
static void statusloop(); static void statusloop();
@ -27,7 +26,6 @@ static void updateblock(Block *block, int sigval);
static void updatestatus(); static void updatestatus();
static void writepid(); static void writepid();
static char statustext[STATUSLENGTH + DELIMITERLENGTH];
static Block *dirtyblock; static Block *dirtyblock;
static Display *dpy; static Display *dpy;
static sigset_t blocksigmask; static sigset_t blocksigmask;
@ -64,17 +62,6 @@ cleanup()
XCloseDisplay(dpy); XCloseDisplay(dpy);
} }
void
setroot()
{
if (dirtyblock) {
updatestatus();
dirtyblock = NULL;
XStoreName(dpy, DefaultRootWindow(dpy), statustext);
XSync(dpy, False);
}
}
void void
setupsignals() setupsignals()
{ {
@ -133,7 +120,7 @@ sighandler(int sig, siginfo_t *info, void *ucontext)
for (Block *block = blocks; block->pathu; block++) for (Block *block = blocks; block->pathu; block++)
if (block->signal == sig) if (block->signal == sig)
updateblock(block, info->si_value.sival_int); updateblock(block, info->si_value.sival_int);
setroot(); updatestatus();
} }
void void
@ -147,7 +134,7 @@ statusloop()
for (Block *block = blocks; block->pathu; block++) for (Block *block = blocks; block->pathu; block++)
if (block->interval >= 0) if (block->interval >= 0)
updateblock(block, NILL); updateblock(block, NILL);
setroot(); updatestatus();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn; t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
while (nanosleep(&t, &t) == -1) while (nanosleep(&t, &t) == -1)
@ -161,7 +148,7 @@ statusloop()
for (Block *block = blocks; block->pathu; block++) for (Block *block = blocks; block->pathu; block++)
if (block->interval > 0 && i % block->interval == 0) if (block->interval > 0 && i % block->interval == 0)
updateblock(block, NILL); updateblock(block, NILL);
setroot(); updatestatus();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn; t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
while (nanosleep(&t, &t) == -1); while (nanosleep(&t, &t) == -1);
@ -253,8 +240,11 @@ updateblock(Block *block, int sigval)
void void
updatestatus() updatestatus()
{ {
static char statustext[STATUSLENGTH + DELIMITERLENGTH];
char *s = statustext; char *s = statustext;
if (!dirtyblock)
return;
for (Block *block = blocks; block < dirtyblock; block++) for (Block *block = blocks; block < dirtyblock; block++)
s += block->length; s += block->length;
for (Block *block = dirtyblock; block->pathu; block++) { for (Block *block = dirtyblock; block->pathu; block++) {
@ -262,6 +252,10 @@ updatestatus()
s += block->length; s += block->length;
} }
s[s == statustext ? 0 : -DELIMITERLENGTH] = '\0'; s[s == statustext ? 0 : -DELIMITERLENGTH] = '\0';
dirtyblock = NULL;
XStoreName(dpy, DefaultRootWindow(dpy), statustext);
XSync(dpy, False);
} }
void void