Apply statuscmd
This commit is contained in:
35
dwmblocks.c
35
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,16 +53,33 @@ 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++;
|
||||
}
|
||||
//make sure status is same until output is ready
|
||||
char tempstatus[CMDLENGTH] = {0};
|
||||
strcpy(tempstatus, block->icon);
|
||||
FILE *cmdf = popen(block->command, "r");
|
||||
FILE *cmdf;
|
||||
if (*button)
|
||||
{
|
||||
setenv("BUTTON", button, 1);
|
||||
cmdf = popen(block->command,"r");
|
||||
*button = '\0';
|
||||
unsetenv("BUTTON");
|
||||
}
|
||||
else
|
||||
{
|
||||
cmdf = popen(block->command,"r");
|
||||
}
|
||||
if (!cmdf)
|
||||
return;
|
||||
int i = strlen(block->icon);
|
||||
@ -109,9 +127,15 @@ void setupsignals()
|
||||
signal(i, dummysighandler);
|
||||
#endif
|
||||
|
||||
struct sigaction sa;
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
if (blocks[i].signal > 0)
|
||||
if (blocks[i].signal > 0) {
|
||||
signal(SIGMINUS+blocks[i].signal, sighandler);
|
||||
sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); // ignore signal when handling SIGUSR1
|
||||
}
|
||||
sa.sa_sigaction = buttonhandler;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGUSR1, &sa, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
@ -177,6 +201,13 @@ void dummysighandler(int signum)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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 sighandler(int signum)
|
||||
|
Reference in New Issue
Block a user