status patch
This commit is contained in:
36
dwmblocks.c
36
dwmblocks.c
@@ -28,6 +28,7 @@ typedef struct {
|
|||||||
void dummysighandler(int num);
|
void dummysighandler(int num);
|
||||||
#endif
|
#endif
|
||||||
void sighandler(int num);
|
void sighandler(int num);
|
||||||
|
void buttonhandler(int sig, siginfo_t *si, void *ucontext);
|
||||||
void getcmds(int time);
|
void getcmds(int time);
|
||||||
void getsigcmds(unsigned int signal);
|
void getsigcmds(unsigned int signal);
|
||||||
void setupsignals();
|
void setupsignals();
|
||||||
@@ -52,14 +53,32 @@ static void (*writestatus) () = pstdout;
|
|||||||
|
|
||||||
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
|
||||||
static char statusstr[2][STATUSLENGTH];
|
static char statusstr[2][STATUSLENGTH];
|
||||||
|
static char button[] = "\0";
|
||||||
static int statusContinue = 1;
|
static int statusContinue = 1;
|
||||||
static int returnStatus = 0;
|
static int returnStatus = 0;
|
||||||
|
|
||||||
//opens process *cmd and stores output in *output
|
//opens process *cmd and stores output in *output
|
||||||
void getcmd(const Block *block, char *output)
|
void getcmd(const Block *block, char *output)
|
||||||
{
|
{
|
||||||
|
if (block->signal)
|
||||||
|
{
|
||||||
|
output[0] = block->signal;
|
||||||
|
output++;
|
||||||
|
}
|
||||||
strcpy(output, block->icon);
|
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)
|
if (!cmdf)
|
||||||
return;
|
return;
|
||||||
int i = strlen(block->icon);
|
int i = strlen(block->icon);
|
||||||
@@ -108,11 +127,17 @@ void setupsignals()
|
|||||||
signal(i, dummysighandler);
|
signal(i, dummysighandler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct sigaction sa;
|
||||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
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);
|
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)
|
int getstatus(char *str, char *last)
|
||||||
@@ -145,6 +170,13 @@ int setupX()
|
|||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
return 1;
|
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
|
#endif
|
||||||
|
|
||||||
void pstdout()
|
void pstdout()
|
||||||
|
|||||||
Reference in New Issue
Block a user