Upgrading statuscmd patch.

The original statuscmd patch has been renamed to statuscmd-nosignal
to separate the logic from the dwmblocks integration that involves
signals. I assume as the latter has become more popular it has replaced
the statuscmd in name.
This commit is contained in:
bakkeby 2021-04-14 11:23:18 +02:00
parent 7efb64d685
commit 6e80cb5f36
4 changed files with 34 additions and 27 deletions

View File

@ -780,8 +780,13 @@ static const char *termcmd[] = { "st", NULL };
#define STATUSBAR "dwmblocks"
#else
/* commands spawned when clicking statusbar, the mouse button pressed is exported as BUTTON */
static const char *statuscmds[] = { "notify-send Mouse$BUTTON", "notify-send Cat$BUTTON", "notify-send Dog$BUTTON" };
static char *statuscmd[] = { "/bin/sh", "-c", NULL, NULL };
static const StatusCmd statuscmds[] = {
{ "notify-send Volume$BUTTON", 1 },
{ "notify-send CPU$BUTTON", 2 },
{ "notify-send Battery$BUTTON", 3 },
};
/* test the above with: xsetroot -name "$(printf '\x01Volume |\x02 CPU |\x03 Battery')" */
static const char *statuscmd[] = { "/bin/sh", "-c", NULL, NULL };
#endif // BAR_DWMBLOCKS_PATCH
#endif // BAR_STATUSCMD_PATCH

41
dwm.c
View File

@ -1066,6 +1066,11 @@ buttonpress(XEvent *e)
const BarRule *br;
BarArg carg = { 0, 0, 0, 0 };
click = ClkRootWin;
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
*lastbutton = '0' + ev->button;
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
/* focus monitor if necessary */
if ((m = wintomon(ev->window)) && m != selmon
#if FOCUSONCLICK_PATCH
@ -3751,29 +3756,10 @@ spawn(const Arg *arg)
#if RIODRAW_PATCH
pid_t pid;
#endif // RIODRAW_PATCH
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
char *cmd = NULL;
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
#if !NODMENU_PATCH
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
#endif // NODMENU_PATCH
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
#if !NODMENU_PATCH
else if (arg->v == statuscmd)
#else
if (arg->v == statuscmd)
#endif // NODMENU_PATCH
{
int len = strlen(statuscmds[statuscmdn]) + 1;
if (!(cmd = malloc(sizeof(char)*len + sizeof(statusexport))))
die("malloc:");
strcpy(cmd, statusexport);
strcat(cmd, statuscmds[statuscmdn]);
cmd[LENGTH(statusexport)-3] = '0' + lastbutton;
statuscmd[2] = cmd;
}
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
#if RIODRAW_PATCH
if ((pid = fork()) == 0)
@ -3783,6 +3769,20 @@ spawn(const Arg *arg)
{
if (dpy)
close(ConnectionNumber(dpy));
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
if (arg->v == statuscmd) {
for (int i = 0; i < LENGTH(statuscmds); i++) {
if (statuscmdn == statuscmds[i].id) {
statuscmd[2] = statuscmds[i].cmd;
setenv("BUTTON", lastbutton, 1);
break;
}
}
if (!statuscmd[2])
exit(EXIT_SUCCESS);
}
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
#if SPAWNCMD_PATCH
if (selmon->sel) {
const char* const home = getenv("HOME");
@ -3823,9 +3823,6 @@ spawn(const Arg *arg)
perror(" failed");
exit(EXIT_SUCCESS);
}
#if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH
free(cmd);
#endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH
#if RIODRAW_PATCH
return pid;
#endif // RIODRAW_PATCH

View File

@ -1,7 +1,7 @@
#if !BAR_DWMBLOCKS_PATCH
static const char statusexport[] = "export BUTTON=-;";
static int statuscmdn;
static int lastbutton;
static char lastbutton[] = "-";
#endif // BAR_DWMBLOCKS_PATCH
int
@ -49,7 +49,7 @@ click_statuscmd_text(Arg *arg, int rel_x, char *text)
if (x >= rel_x)
break;
if (ch <= LENGTH(statuscmds))
statuscmdn = ch - 1;
statuscmdn = ch;
#endif // BAR_DWMBLOCKS_PATCH
}
}

View File

@ -3,4 +3,9 @@ static int click_statuscmd(Bar *bar, Arg *arg, BarArg *a);
static int click_statuscmd_es(Bar *bar, Arg *arg, BarArg *a);
#endif // BAR_EXTRASTATUS_PATCH
static int click_statuscmd_text(Arg *arg, int rel_x, char *text);
static void copyvalidchars(char *text, char *rawtext);
static void copyvalidchars(char *text, char *rawtext);
typedef struct {
const char *cmd;
int id;
} StatusCmd;