Improved consistency in coding style
This commit is contained in:
parent
03d6a25af7
commit
c2ab94a4dc
73
dwmblocks.c
73
dwmblocks.c
|
@ -17,10 +17,10 @@
|
||||||
#define NOTATCMDOUTEND(block, i) (i < CMDLENGTH && block->cmdoutcur[i] != '\n' && block->cmdoutcur[i] != '\0')
|
#define NOTATCMDOUTEND(block, i) (i < CMDLENGTH && block->cmdoutcur[i] != '\n' && block->cmdoutcur[i] != '\0')
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *pathu;
|
char *pathu;
|
||||||
char *pathc;
|
char *pathc;
|
||||||
const int interval;
|
const int interval;
|
||||||
const int signal;
|
const int signal;
|
||||||
char cmdoutcur[CMDLENGTH];
|
char cmdoutcur[CMDLENGTH];
|
||||||
char cmdoutprv[CMDLENGTH];
|
char cmdoutprv[CMDLENGTH];
|
||||||
} Block;
|
} Block;
|
||||||
|
@ -37,7 +37,7 @@ static void termhandler(int signum);
|
||||||
static int updatestatus();
|
static int updatestatus();
|
||||||
static void writepid();
|
static void writepid();
|
||||||
|
|
||||||
static int statusContinue = 1;
|
static int statuscontinue = 1;
|
||||||
static char statusstr[STTLENGTH];
|
static char statusstr[STTLENGTH];
|
||||||
static size_t delimlength;
|
static size_t delimlength;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
|
@ -45,8 +45,8 @@ static Display *dpy;
|
||||||
void
|
void
|
||||||
buttonhandler(int signal, siginfo_t *si, void *ucontext)
|
buttonhandler(int signal, siginfo_t *si, void *ucontext)
|
||||||
{
|
{
|
||||||
signal = si->si_value.sival_int >> 8;
|
signal = si->si_value.sival_int >> 8;
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
perror("buttonhandler - fork");
|
perror("buttonhandler - fork");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -114,9 +114,9 @@ getcmd(Block *block, int sigval)
|
||||||
void
|
void
|
||||||
setroot()
|
setroot()
|
||||||
{
|
{
|
||||||
if (updatestatus()) /* only set root if block outputs have changed */
|
if (updatestatus()) /* only set root if block outputs have changed */
|
||||||
return;
|
return;
|
||||||
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
|
XStoreName(dpy, DefaultRootWindow(dpy), statusstr);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,65 +129,64 @@ setupsignals()
|
||||||
sa.sa_flags = SA_RESTART;
|
sa.sa_flags = SA_RESTART;
|
||||||
/* to handle INT, HUP and TERM */
|
/* to handle INT, HUP and TERM */
|
||||||
sa.sa_handler = termhandler;
|
sa.sa_handler = termhandler;
|
||||||
sigaction(SIGINT, &sa, NULL);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
sigaction(SIGHUP, &sa, NULL);
|
sigaction(SIGHUP, &sa, NULL);
|
||||||
sigaction(SIGTERM, &sa, NULL);
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
/* to ignore unused realtime signals */
|
/* to ignore unused realtime signals */
|
||||||
sa.sa_handler = SIG_IGN;
|
sa.sa_handler = SIG_IGN;
|
||||||
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
||||||
sigaction(i, &sa, NULL);
|
sigaction(i, &sa, NULL);
|
||||||
/* to handle signals generated by dwm on click events */
|
/* to handle signals generated by dwm on click events */
|
||||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||||
sa.sa_sigaction = buttonhandler;
|
sa.sa_sigaction = buttonhandler;
|
||||||
sigaction(SIGRTMIN, &sa, NULL);
|
sigaction(SIGRTMIN, &sa, NULL);
|
||||||
/* to handle update signals for individual blocks */
|
/* to handle update signals for individual blocks */
|
||||||
sa.sa_sigaction = sighandler;
|
sa.sa_sigaction = sighandler;
|
||||||
for (Block *current = blocks; current->pathu; current++)
|
for (Block *current = blocks; current->pathu; current++)
|
||||||
if (current->signal > 0)
|
if (current->signal > 0)
|
||||||
sigaction(SIGRTMIN + current->signal, &sa, NULL);
|
sigaction(SIGRTMIN + current->signal, &sa, NULL);
|
||||||
/* to prevent forked children from becoming zombies */
|
/* to prevent forked children from becoming zombies */
|
||||||
sa.sa_flags = SA_NOCLDWAIT | SA_RESTART;
|
sa.sa_flags = SA_NOCLDWAIT | SA_RESTART;
|
||||||
sa.sa_handler = SIG_DFL;
|
sa.sa_handler = SIG_DFL;
|
||||||
sigaction(SIGCHLD, &sa, NULL);
|
sigaction(SIGCHLD, &sa, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sighandler(int signal, siginfo_t *si, void *ucontext)
|
sighandler(int signal, siginfo_t *si, void *ucontext)
|
||||||
{
|
{
|
||||||
signal -= SIGRTMIN;
|
signal -= SIGRTMIN;
|
||||||
for (Block *current = blocks; current->pathu; current++) {
|
for (Block *current = blocks; current->pathu; current++)
|
||||||
if (current->signal == signal)
|
if (current->signal == signal)
|
||||||
getcmd(current, si->si_value.sival_int);
|
getcmd(current, si->si_value.sival_int);
|
||||||
}
|
setroot();
|
||||||
setroot();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
statusloop()
|
statusloop()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
setupsignals();
|
setupsignals();
|
||||||
for (Block *current = blocks; current->pathu; current++)
|
for (Block *current = blocks; current->pathu; current++)
|
||||||
if (current->interval >= 0)
|
if (current->interval >= 0)
|
||||||
getcmd(current, NILL);
|
getcmd(current, NILL);
|
||||||
setroot();
|
setroot();
|
||||||
sleep(SLEEPINTERVAL);
|
sleep(SLEEPINTERVAL);
|
||||||
i = SLEEPINTERVAL;
|
i = SLEEPINTERVAL;
|
||||||
while (statusContinue) {
|
while (statuscontinue) {
|
||||||
for (Block *current = blocks; current->pathu; current++)
|
for (Block *current = blocks; current->pathu; current++)
|
||||||
if (current->interval > 0 && i % current->interval == 0)
|
if (current->interval > 0 && i % current->interval == 0)
|
||||||
getcmd(current, NILL);
|
getcmd(current, NILL);
|
||||||
setroot();
|
setroot();
|
||||||
sleep(SLEEPINTERVAL);
|
sleep(SLEEPINTERVAL);
|
||||||
i += SLEEPINTERVAL;
|
i += SLEEPINTERVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
termhandler(int signum)
|
termhandler(int signum)
|
||||||
{
|
{
|
||||||
statusContinue = 0;
|
statuscontinue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns whether block outputs have changed and updates statusstr if they have */
|
/* returns whether block outputs have changed and updates statusstr if they have */
|
||||||
|
@ -224,7 +223,7 @@ updatestatus()
|
||||||
goto update2;
|
goto update2;
|
||||||
str += delimlength;
|
str += delimlength;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
update0:
|
update0:
|
||||||
for (; current->pathu; current++) {
|
for (; current->pathu; current++) {
|
||||||
if (EMPTYCMDOUT(current)) {
|
if (EMPTYCMDOUT(current)) {
|
||||||
|
@ -296,7 +295,7 @@ main(int argc, char *argv[])
|
||||||
fputs("Error: could not open display.\n", stderr);
|
fputs("Error: could not open display.\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
statusloop();
|
statusloop();
|
||||||
unlink(LOCKFILE);
|
unlink(LOCKFILE);
|
||||||
XStoreName(dpy, DefaultRootWindow(dpy), "");
|
XStoreName(dpy, DefaultRootWindow(dpy), "");
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
Loading…
Reference in a new issue