Improved sleep handling in statusloop
This commit is contained in:
parent
d9ccaac2d1
commit
c8fc778841
8
blocks.h
8
blocks.h
|
@ -1,6 +1,3 @@
|
||||||
/* time interval in seconds to sleep before looking for updates in the main loop */
|
|
||||||
#define SLEEPINTERVAL 1
|
|
||||||
|
|
||||||
#define PATH(name) "/home/ashish/.local/projects/dwmblocks/blocks/"name
|
#define PATH(name) "/home/ashish/.local/projects/dwmblocks/blocks/"name
|
||||||
|
|
||||||
/* If interval of a block is set to 0, the block will only be updated once at startup.
|
/* If interval of a block is set to 0, the block will only be updated once at startup.
|
||||||
|
@ -13,6 +10,11 @@
|
||||||
/* pathu - path of the program whose output is to be used for status text
|
/* pathu - path of the program whose output is to be used for status text
|
||||||
* output of the program should have a null or newline character at the end
|
* output of the program should have a null or newline character at the end
|
||||||
* pathc - path of the program to be executed on clicks */
|
* pathc - path of the program to be executed on clicks */
|
||||||
|
|
||||||
|
/* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */
|
||||||
|
#define INTERVALs 1
|
||||||
|
#define INTERVALn 0
|
||||||
|
|
||||||
static Block blocks[] = {
|
static Block blocks[] = {
|
||||||
/* pathu pathc interval signal */
|
/* pathu pathc interval signal */
|
||||||
{ PATH("time.sh"), NULL, 30, 10},
|
{ PATH("time.sh"), NULL, 30, 10},
|
||||||
|
|
12
dwmblocks.c
12
dwmblocks.c
|
@ -5,6 +5,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
@ -192,6 +193,7 @@ void
|
||||||
statusloop()
|
statusloop()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
struct timespec t;
|
||||||
|
|
||||||
/* first run */
|
/* first run */
|
||||||
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
||||||
|
@ -200,17 +202,19 @@ statusloop()
|
||||||
getcmd(block, NILL);
|
getcmd(block, NILL);
|
||||||
setroot();
|
setroot();
|
||||||
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
||||||
sleep(SLEEPINTERVAL);
|
|
||||||
i = SLEEPINTERVAL;
|
|
||||||
/* main loop */
|
/* main loop */
|
||||||
for (;; i += SLEEPINTERVAL) {
|
for (i = 1;; t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn, i += 1) {
|
||||||
|
while (nanosleep(&t, &t) == -1)
|
||||||
|
if (errno != EINTR) {
|
||||||
|
perror("statusloop - nanosleep");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
|
||||||
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)
|
||||||
getcmd(block, NILL);
|
getcmd(block, NILL);
|
||||||
setroot();
|
setroot();
|
||||||
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
|
||||||
sleep(SLEEPINTERVAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue