status patch
This commit is contained in:
36
dwmblocks.c
36
dwmblocks.c
@@ -28,6 +28,7 @@ typedef struct {
|
||||
void dummysighandler(int num);
|
||||
#endif
|
||||
void sighandler(int num);
|
||||
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
||||
void getcmds(int time);
|
||||
void getsigcmds(unsigned int signal);
|
||||
void setupsignals();
|
||||
@@ -52,14 +53,32 @@ static void (*writestatus) () = pstdout;
|
||||
|
||||
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
||||
static char statusstr[2][STATUSLENGTH];
|
||||
static char button[] = "\0";
|
||||
static int statusContinue = 1;
|
||||
static int returnStatus = 0;
|
||||
|
||||
//opens process *cmd and stores output in *output
|
||||
void getcmd(const Block *block, char *output)
|
||||
{
|
||||
if (block->signal)
|
||||
{
|
||||
output[0] = block->signal;
|
||||
output++;
|
||||
}
|
||||
strcpy(output, block->icon);
|
||||
FILE *cmdf = popen(block->command, "r");
|
||||
char *cmd = block->command;
|
||||
FILE *cmdf;
|
||||
if (*button)
|
||||
{
|
||||
setenv("button", button, 1);
|
||||
cmdf = popen(cmd, "r");
|
||||
*button = '\0';
|
||||
unsetenv("BUTTON");
|
||||
}
|
||||
else
|
||||
{
|
||||
cmdf = popen(cmd, "r");
|
||||
}
|
||||
if (!cmdf)
|
||||
return;
|
||||
int i = strlen(block->icon);
|
||||
@@ -108,11 +127,17 @@ void setupsignals()
|
||||
signal(i, dummysighandler);
|
||||
#endif
|
||||
|
||||
struct sigaction sa;
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
if (blocks[i].signal > 0)
|
||||
{
|
||||
signal(SIGMINUS+blocks[i].signal, sighandler);
|
||||
sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); // ignore signal wehn handling SIGUSR1
|
||||
}
|
||||
}
|
||||
|
||||
sa.sa_sigaction = buttonhandler;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGUSR1, &sa, NULL);
|
||||
}
|
||||
|
||||
int getstatus(char *str, char *last)
|
||||
@@ -145,6 +170,13 @@ int setupX()
|
||||
root = RootWindow(dpy, screen);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void buttonhandler(int sig, siginfo_t *si, void *ucontext)
|
||||
{
|
||||
*button = '0' + si->si_value.sival_int & 0xff;
|
||||
getsigcmds(si->si_value.sival_int >> 8);
|
||||
writestatus();
|
||||
}
|
||||
#endif
|
||||
|
||||
void pstdout()
|
||||
|
||||
Reference in New Issue
Block a user