2021-04-14 10:42:52 +02:00
|
|
|
static int statussig;
|
|
|
|
pid_t statuspid = -1;
|
2020-05-02 14:43:44 +02:00
|
|
|
|
2021-04-14 10:42:52 +02:00
|
|
|
pid_t
|
|
|
|
getstatusbarpid()
|
2020-05-02 14:43:44 +02:00
|
|
|
{
|
2021-04-14 10:42:52 +02:00
|
|
|
char buf[32], *str = buf, *c;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (statuspid > 0) {
|
|
|
|
snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
|
|
|
|
if ((fp = fopen(buf, "r"))) {
|
|
|
|
fgets(buf, sizeof(buf), fp);
|
|
|
|
while ((c = strchr(str, '/')))
|
|
|
|
str = c + 1;
|
|
|
|
fclose(fp);
|
|
|
|
if (!strcmp(str, STATUSBAR))
|
|
|
|
return statuspid;
|
|
|
|
}
|
|
|
|
}
|
2021-10-15 06:41:50 +02:00
|
|
|
if (!(fp = popen("pgrep -o "STATUSBAR, "r")))
|
2021-04-14 10:42:52 +02:00
|
|
|
return -1;
|
|
|
|
fgets(buf, sizeof(buf), fp);
|
2020-05-02 14:43:44 +02:00
|
|
|
pclose(fp);
|
2021-04-14 10:42:52 +02:00
|
|
|
return strtol(buf, NULL, 10);
|
2020-05-02 14:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-14 10:42:52 +02:00
|
|
|
sigstatusbar(const Arg *arg)
|
2020-05-02 14:43:44 +02:00
|
|
|
{
|
|
|
|
union sigval sv;
|
|
|
|
|
2021-04-14 10:42:52 +02:00
|
|
|
if (!statussig)
|
|
|
|
return;
|
|
|
|
if ((statuspid = getstatusbarpid()) <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if BAR_DWMBLOCKS_SIGUSR1_PATCH
|
|
|
|
sv.sival_int = (statussig << 8) | arg->i;
|
|
|
|
if (sigqueue(statuspid, SIGUSR1, sv) == -1) {
|
2020-05-02 14:43:44 +02:00
|
|
|
if (errno == ESRCH) {
|
2021-04-14 10:42:52 +02:00
|
|
|
if (!getstatusbarpid())
|
|
|
|
sigqueue(statuspid, SIGUSR1, sv);
|
2020-05-02 14:43:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 10:42:52 +02:00
|
|
|
#else
|
|
|
|
sv.sival_int = arg->i;
|
|
|
|
sigqueue(statuspid, SIGRTMIN+statussig, sv);
|
|
|
|
#endif // BAR_DWMBLOCKS_SIGUSR1_PATCH
|
2021-06-14 07:16:17 +02:00
|
|
|
}
|
|
|
|
|