dwmblocks

I use polybar now
Log | Files | Refs | README | LICENSE

dwmblocks-statuscmd-fork.diff (1887B)


      1 diff --git a/dwmblocks.c b/dwmblocks.c
      2 index 7d7a564..e2c5dd0 100644
      3 --- a/dwmblocks.c
      4 +++ b/dwmblocks.c
      5 @@ -34,8 +34,6 @@ static int screen;
      6  static Window root;
      7  static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
      8  static char statusstr[2][256];
      9 -static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
     10 -static int button = 0;
     11  static int statusContinue = 1;
     12  static void (*writestatus) () = setroot;
     13  
     14 @@ -55,21 +53,8 @@ void getcmd(const Block *block, char *output)
     15  		output[0] = block->signal;
     16  		output++;
     17  	}
     18 -	char* cmd;
     19 -	FILE *cmdf;
     20 -	if (button)
     21 -	{
     22 -		cmd = strcat(exportstring, block->command);
     23 -		cmd[20] = '0' + button;
     24 -		button = 0;
     25 -		cmdf = popen(cmd,"r");
     26 -		cmd[22] = '\0';
     27 -	}
     28 -	else
     29 -	{
     30 -		cmd = block->command;
     31 -		cmdf = popen(cmd,"r");
     32 -	}
     33 +	char *cmd = block->command;
     34 +	FILE *cmdf = popen(cmd,"r");
     35  	if (!cmdf)
     36  		return;
     37  	fgets(output, CMDLENGTH, cmdf);
     38 @@ -117,6 +102,7 @@ void setupsignals()
     39  	sa.sa_sigaction = buttonhandler;
     40  	sa.sa_flags = SA_SIGINFO;
     41  	sigaction(SIGUSR1, &sa, NULL);
     42 +	signal(SIGCHLD, SIG_IGN);
     43  
     44  }
     45  #endif
     46 @@ -179,9 +165,29 @@ void sighandler(int signum)
     47  
     48  void buttonhandler(int sig, siginfo_t *si, void *ucontext)
     49  {
     50 -	button = si->si_value.sival_int & 0xff;
     51 -	getsigcmds(si->si_value.sival_int >> 8);
     52 +	int button = si->si_value.sival_int & 0xff;
     53 +	sig = si->si_value.sival_int >> 8;
     54 +	getsigcmds(sig);
     55  	writestatus();
     56 +	if (fork() == 0)
     57 +	{
     58 +		static char exportstring[CMDLENGTH + 22] = "export BLOCK_BUTTON=-;";
     59 +		const Block *current;
     60 +		int i;
     61 +		for (i = 0; i < LENGTH(blocks); i++)
     62 +		{
     63 +			current = blocks + i;
     64 +			if (current->signal == sig)
     65 +				break;
     66 +		}
     67 +		char *cmd = strcat(exportstring, blocks[i].command);
     68 +		cmd[20] = '0' + button;
     69 +		char *command[] = { "/bin/sh", "-c", cmd, NULL };
     70 +		setsid();
     71 +		execvp(command[0], command);
     72 +		exit(EXIT_SUCCESS);
     73 +		cmd[22] = '\0';
     74 +	}
     75  }
     76  
     77  #endif