mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Adding statuscmd patch ref. #23
This commit is contained in:
parent
d258c3bb69
commit
525dc0d107
@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
|
||||
|
||||
### Changelog:
|
||||
|
||||
2020-04-13 - Added statuscmd patch
|
||||
|
||||
2020-03-31 - Added the rounded corners patch
|
||||
|
||||
2020-03-27 - Revamped the dragmfact patch to support both horizontal and vertical layout splits as well as centered master variants
|
||||
@ -315,6 +317,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
|
||||
- [stacker](https://dwm.suckless.org/patches/stacker/)
|
||||
- provides comprehensive utilities for managing the client stack
|
||||
|
||||
- [statuscmd](https://dwm.suckless.org/patches/statuscmd/)
|
||||
- adds the ability to execute shell commands based on the mouse button and position when clicking the status bar
|
||||
|
||||
- [statusallmons](https://dwm.suckless.org/patches/statuspadding/)
|
||||
- this patch draws and updates the statusbar on all monitors
|
||||
|
||||
|
12
config.def.h
12
config.def.h
@ -673,6 +673,12 @@ static const char *dmenucmd[] = {
|
||||
};
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
|
||||
#if STATUSCMD_PATCH
|
||||
/* commands spawned when clicking statusbar, the mouse button pressed is exported as BUTTON */
|
||||
static const char *statuscmds[] = { "notify-send Mouse$BUTTON" };
|
||||
static char *statuscmd[] = { "/bin/sh", "-c", NULL, NULL };
|
||||
#endif // STATUSCMD_PATCH
|
||||
|
||||
#if SCRATCHPAD_PATCH
|
||||
static const char scratchpadname[] = "scratchpad";
|
||||
static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
|
||||
@ -952,7 +958,13 @@ static Button buttons[] = {
|
||||
{ ClkWinTitle, 0, Button3, showhideclient, {0} },
|
||||
#endif // AWESOMEBAR_PATCH
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
#if STATUSCMD_PATCH
|
||||
{ ClkStatusText, 0, Button1, spawn, {.v = statuscmd } },
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = statuscmd } },
|
||||
{ ClkStatusText, 0, Button3, spawn, {.v = statuscmd } },
|
||||
#else
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
#endif // STATUSCMD_PATCH
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
|
123
dwm.c
123
dwm.c
@ -677,6 +677,10 @@ void
|
||||
buttonpress(XEvent *e)
|
||||
{
|
||||
unsigned int i, x, click;
|
||||
int padding = 0;
|
||||
#if STATUSCMD_PATCH
|
||||
unsigned int xc;
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if TAGGRID_PATCH
|
||||
unsigned int columns;
|
||||
#endif // TAGGRID_PATCH
|
||||
@ -687,6 +691,15 @@ buttonpress(XEvent *e)
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
#if STATUSCMD_PATCH
|
||||
lastbutton = ev->button;
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if AWESOMEBAR_PATCH || STATUSCMD_PATCH
|
||||
padding += lrpad - 2;
|
||||
#endif // AWESOMEBAR_PATCH | STATUSCMD_PATCH
|
||||
#if SYSTRAY_PATCH
|
||||
padding -= getsystraywidth();
|
||||
#endif // SYSTRAY_PATCH
|
||||
|
||||
#if TAGGRID_PATCH
|
||||
columns = LENGTH(tags) / tagrows + ((LENGTH(tags) % tagrows > 0) ? 1 : 0);
|
||||
@ -743,16 +756,34 @@ buttonpress(XEvent *e)
|
||||
} else if (ev->x < x + blw)
|
||||
click = ClkLtSymbol;
|
||||
#endif // TAGGRID_PATCH
|
||||
#if AWESOMEBAR_PATCH && SYSTRAY_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2 - getsystraywidth())
|
||||
#elif AWESOMEBAR_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
|
||||
#elif SYSTRAY_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth())
|
||||
#else
|
||||
else if (ev->x > selmon->ww - TEXTW(stext))
|
||||
#endif // SYSTRAY_PATCH / AWESOMEBAR_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + padding)
|
||||
#if !STATUSCMD_PATCH
|
||||
click = ClkStatusText;
|
||||
#else
|
||||
{
|
||||
click = ClkStatusText;
|
||||
|
||||
xc = selmon->ww - TEXTW(stext) + padding;
|
||||
char *text = rawstext;
|
||||
int i = -1;
|
||||
char ch;
|
||||
statuscmdn = 0;
|
||||
while (text[++i]) {
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
xc += TEXTW(text) - lrpad;
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
if (xc >= ev->x)
|
||||
break;
|
||||
if (ch <= LENGTH(statuscmds))
|
||||
statuscmdn = ch - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if AWESOMEBAR_PATCH
|
||||
else {
|
||||
x += blw;
|
||||
@ -771,9 +802,9 @@ buttonpress(XEvent *e)
|
||||
}
|
||||
}
|
||||
#else
|
||||
else
|
||||
click = ClkWinTitle;
|
||||
#endif // AWESOMEBAR_PATCH
|
||||
} else
|
||||
click = ClkWinTitle;
|
||||
#endif // AWESOMEBAR_PATCH
|
||||
}
|
||||
#else // LEFTLAYOUT_PATCH
|
||||
#if HIDEVACANTTAGS_PATCH
|
||||
@ -814,16 +845,34 @@ buttonpress(XEvent *e)
|
||||
} else if (ev->x < x + blw)
|
||||
click = ClkLtSymbol;
|
||||
#endif // TAGGRID_PATCH
|
||||
#if AWESOMEBAR_PATCH && SYSTRAY_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2 - getsystraywidth())
|
||||
#elif AWESOMEBAR_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
|
||||
#elif SYSTRAY_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth())
|
||||
#else
|
||||
else if (ev->x > selmon->ww - TEXTW(stext))
|
||||
#endif // SYSTRAY_PATCH / AWESOMEBAR_PATCH
|
||||
else if (ev->x > selmon->ww - TEXTW(stext) + padding)
|
||||
#if !STATUSCMD_PATCH
|
||||
click = ClkStatusText;
|
||||
#else
|
||||
{
|
||||
click = ClkStatusText;
|
||||
|
||||
xc = selmon->ww - TEXTW(stext) + padding;
|
||||
char *text = rawstext;
|
||||
int i = -1;
|
||||
char ch;
|
||||
statuscmdn = 0;
|
||||
while (text[++i]) {
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
xc += TEXTW(text) - lrpad;
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
if (xc >= ev->x)
|
||||
break;
|
||||
if (ch <= LENGTH(statuscmds))
|
||||
statuscmdn = ch - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if AWESOMEBAR_PATCH
|
||||
else {
|
||||
x += blw;
|
||||
@ -3076,10 +3125,30 @@ sigchld(int unused)
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
#if STATUSCMD_PATCH
|
||||
char *cmd = NULL;
|
||||
#endif // STATUSCMD_PATCH
|
||||
#if !NODMENU_PATCH
|
||||
if (arg->v == dmenucmd)
|
||||
dmenumon[0] = '0' + selmon->num;
|
||||
#endif // NODMENU_PATCH
|
||||
#if STATUSCMD_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 // STATUSCMD_PATCH
|
||||
|
||||
#if SCRATCHPAD_PATCH
|
||||
selmon->tagset[selmon->seltags] &= ~scratchtag;
|
||||
#endif // SCRATCHPAD_PATCH
|
||||
@ -3126,6 +3195,9 @@ spawn(const Arg *arg)
|
||||
perror(" failed");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#if STATUSCMD_PATCH
|
||||
free(cmd);
|
||||
#endif // STATUSCMD_PATCH
|
||||
}
|
||||
|
||||
void
|
||||
@ -3765,8 +3837,17 @@ updatestatus(void)
|
||||
} else {
|
||||
estext[0] = '\0';
|
||||
}
|
||||
#if STATUSCMD_PATCH
|
||||
copyvalidchars(stext, text);
|
||||
#else
|
||||
strncpy(stext, text, sizeof(stext) - 1);
|
||||
#endif // STATUSCMD_PATCH
|
||||
}
|
||||
#elif STATUSCMD_PATCH
|
||||
if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)))
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
else
|
||||
copyvalidchars(stext, rawstext);
|
||||
#else
|
||||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
|
@ -110,6 +110,9 @@
|
||||
#if STACKER_PATCH
|
||||
#include "stacker.c"
|
||||
#endif
|
||||
#if STATUSCMD_PATCH
|
||||
#include "statuscmd.c"
|
||||
#endif
|
||||
#if STICKY_PATCH
|
||||
#include "sticky.c"
|
||||
#endif
|
||||
|
@ -113,6 +113,9 @@
|
||||
#if STACKER_PATCH
|
||||
#include "stacker.h"
|
||||
#endif
|
||||
#if STATUSCMD_PATCH
|
||||
#include "statuscmd.h"
|
||||
#endif
|
||||
#if STICKY_PATCH
|
||||
#include "sticky.h"
|
||||
#endif
|
||||
|
17
patch/statuscmd.c
Normal file
17
patch/statuscmd.c
Normal file
@ -0,0 +1,17 @@
|
||||
static char rawstext[256];
|
||||
static const char statusexport[] = "export BUTTON=-;";
|
||||
static int statuscmdn;
|
||||
static int lastbutton;
|
||||
|
||||
void
|
||||
copyvalidchars(char *text, char *rawtext)
|
||||
{
|
||||
int i = -1, j = 0;
|
||||
|
||||
while (rawtext[++i]) {
|
||||
if ((unsigned char)rawtext[i] >= ' ') {
|
||||
text[j++] = rawtext[i];
|
||||
}
|
||||
}
|
||||
text[j] = '\0';
|
||||
}
|
1
patch/statuscmd.h
Normal file
1
patch/statuscmd.h
Normal file
@ -0,0 +1 @@
|
||||
static void copyvalidchars(char *text, char *rawtext);
|
@ -468,6 +468,12 @@
|
||||
*/
|
||||
#define STICKY_PATCH 0
|
||||
|
||||
/* This patch adds the ability to execute shell commands based on the mouse button and position
|
||||
* when clicking the status bar. Refer to the website for usage.
|
||||
* https://dwm.suckless.org/patches/statuscmd/
|
||||
*/
|
||||
#define STATUSCMD_PATCH 0
|
||||
|
||||
/* The systray patch adds systray for the status bar.
|
||||
* https://dwm.suckless.org/patches/systray/
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user