dwmblocks

status bar for dwm
git clone https://git.beauhilton.com/dwmblocks.git
Log | Files | Refs | README | LICENSE

dwmblocks-statuscmd-signal.diff (2193B)


      1 diff --git a/dwmblocks.c b/dwmblocks.c
      2 index 88bdfb0..7bd14df 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 replace(char *str, char old, char new);
     11  void getcmds(int time);
     12  #ifndef __OpenBSD__
     13 @@ -34,6 +35,8 @@ static int screen;
     14  static Window root;
     15  static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
     16  static char statusstr[2][256];
     17 +static char exportstring[CMDLENGTH + 16] = "export BUTTON=-;";
     18 +static int button = 0;
     19  static int statusContinue = 1;
     20  static void (*writestatus) () = setroot;
     21 
     22 @@ -48,16 +51,34 @@ void replace(char *str, char old, char new)
     23  //opens process *cmd and stores output in *output
     24  void getcmd(const Block *block, char *output)
     25  {
     26 +	if (block->signal)
     27 +	{
     28 +		output[0] = block->signal;
     29 +		output++;
     30 +	}
     31  	strcpy(output, block->icon);
     32 -	char *cmd = block->command;
     33 -	FILE *cmdf = popen(cmd,"r");
     34 +	char* cmd;
     35 +	FILE *cmdf;
     36 +	if (button)
     37 +	{
     38 +		cmd = strcat(exportstring, block->command);
     39 +		cmd[14] = '0' + button;
     40 +		button = 0;
     41 +		cmdf = popen(cmd,"r");
     42 +		cmd[16] = '\0';
     43 +	}
     44 +	else
     45 +	{
     46 +		cmd = block->command;
     47 +		cmdf = popen(cmd,"r");
     48 +	}
     49  	if (!cmdf)
     50  		return;
     51  	char c;
     52  	int i = strlen(block->icon);
     53  	fgets(output+i, CMDLENGTH-i, cmdf);
     54  	i = strlen(output);
     55 -	if (delim != '\0' && --i)
     56 +	if (delim != '\0' && i)
     57  		output[i++] = delim;
     58  	output[i++] = '\0';
     59  	pclose(cmdf);
     60 @@ -88,11 +106,18 @@ void getsigcmds(int signal)
     61 
     62  void setupsignals()
     63  {
     64 +	struct sigaction sa;
     65  	for(int i = 0; i < LENGTH(blocks); i++)
     66  	{
     67  		if (blocks[i].signal > 0)
     68 +		{
     69  			signal(SIGRTMIN+blocks[i].signal, sighandler);
     70 +			sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal);
     71 +		}
     72  	}
     73 +	sa.sa_sigaction = buttonhandler;
     74 +	sa.sa_flags = SA_SIGINFO;
     75 +	sigaction(SIGUSR1, &sa, NULL);
     76 
     77  }
     78  #endif
     79 @@ -152,6 +177,14 @@ void sighandler(int signum)
     80  	getsigcmds(signum-SIGRTMIN);
     81  	writestatus();
     82  }
     83 +
     84 +void buttonhandler(int sig, siginfo_t *si, void *ucontext)
     85 +{
     86 +	button = si->si_value.sival_int & 0xff;
     87 +	getsigcmds(si->si_value.sival_int >> 8);
     88 +	writestatus();
     89 +}
     90 +
     91  #endif
     92 
     93  void termhandler(int signum)