dwmblocks-statuscmd.diff (1831B)
1 diff --git a/dwmblocks.c b/dwmblocks.c 2 index 2f3b774..ba7dbb5 100644 3 --- a/dwmblocks.c 4 +++ b/dwmblocks.c 5 @@ -14,6 +14,7 @@ typedef struct { 6 unsigned int signal; 7 } Block; 8 void sighandler(int num); 9 +void buttonhandler(int sig, siginfo_t *si, void *ucontext); 10 void getcmds(int time); 11 #ifndef __OpenBSD__ 12 void getsigcmds(int signal); 13 @@ -33,15 +34,32 @@ static int screen; 14 static Window root; 15 static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; 16 static char statusstr[2][256]; 17 +static char button[] = "\0"; 18 static int statusContinue = 1; 19 static void (*writestatus) () = setroot; 20 21 //opens process *cmd and stores output in *output 22 void getcmd(const Block *block, char *output) 23 { 24 + if (block->signal) 25 + { 26 + output[0] = block->signal; 27 + output++; 28 + } 29 strcpy(output, block->icon); 30 char *cmd = block->command; 31 - FILE *cmdf = popen(cmd,"r"); 32 + FILE *cmdf; 33 + if (*button) 34 + { 35 + setenv("BUTTON", button, 1); 36 + cmdf = popen(cmd,"r"); 37 + *button = '\0'; 38 + unsetenv("BUTTON"); 39 + } 40 + else 41 + { 42 + cmdf = popen(cmd,"r"); 43 + } 44 if (!cmdf) 45 return; 46 char c; 47 @@ -79,12 +97,18 @@ void getsigcmds(int signal) 48 49 void setupsignals() 50 { 51 + struct sigaction sa; 52 for(int i = 0; i < LENGTH(blocks); i++) 53 { 54 if (blocks[i].signal > 0) 55 + { 56 signal(SIGRTMIN+blocks[i].signal, sighandler); 57 + sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); // ignore signal when handling SIGUSR1 58 + } 59 } 60 - 61 + sa.sa_sigaction = buttonhandler; 62 + sa.sa_flags = SA_SIGINFO; 63 + sigaction(SIGUSR1, &sa, NULL); 64 } 65 #endif 66 67 @@ -143,6 +167,13 @@ void sighandler(int signum) 68 getsigcmds(signum-SIGRTMIN); 69 writestatus(); 70 } 71 + 72 +void buttonhandler(int sig, siginfo_t *si, void *ucontext) 73 +{ 74 + *button = '0' + si->si_value.sival_int & 0xff; 75 + getsigcmds(si->si_value.sival_int >> 8); 76 + writestatus(); 77 +} 78 #endif 79 80 void termhandler(int signum)