dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

bar_dwmblocks.c (999B)


      1 static int statussig;
      2 pid_t statuspid = -1;
      3 
      4 pid_t
      5 getstatusbarpid()
      6 {
      7 	char buf[32], *str = buf, *c;
      8 	FILE *fp;
      9 
     10 	if (statuspid > 0) {
     11 		snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
     12 		if ((fp = fopen(buf, "r"))) {
     13 			fgets(buf, sizeof(buf), fp);
     14 			while ((c = strchr(str, '/')))
     15 				str = c + 1;
     16 			fclose(fp);
     17 			if (!strcmp(str, STATUSBAR))
     18 				return statuspid;
     19 		}
     20 	}
     21 	if (!(fp = popen("pgrep -o "STATUSBAR, "r")))
     22 		return -1;
     23 	fgets(buf, sizeof(buf), fp);
     24 	pclose(fp);
     25 	return strtol(buf, NULL, 10);
     26 }
     27 
     28 void
     29 sigstatusbar(const Arg *arg)
     30 {
     31 	union sigval sv;
     32 
     33 	if (!statussig)
     34 		return;
     35 	if ((statuspid = getstatusbarpid()) <= 0)
     36 		return;
     37 
     38 	#if BAR_DWMBLOCKS_SIGUSR1_PATCH
     39 	sv.sival_int = (statussig << 8) | arg->i;
     40 	if (sigqueue(statuspid, SIGUSR1, sv) == -1) {
     41 		if (errno == ESRCH) {
     42 			if (!getstatusbarpid())
     43 				sigqueue(statuspid, SIGUSR1, sv);
     44 		}
     45 	}
     46 	#else
     47 	sv.sival_int = arg->i;
     48 	sigqueue(statuspid, SIGRTMIN+statussig, sv);
     49 	#endif // BAR_DWMBLOCKS_SIGUSR1_PATCH
     50 }
     51