diff --git a/README.md b/README.md index 0011188..34c31b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.def.h b/config.def.h index 683df6f..77a4ae0 100644 --- a/config.def.h +++ b/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} }, diff --git a/dwm.c b/dwm.c index 39385ad..c29f8d9 100644 --- a/dwm.c +++ b/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); diff --git a/patch/include.c b/patch/include.c index c30b794..72a840c 100644 --- a/patch/include.c +++ b/patch/include.c @@ -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 diff --git a/patch/include.h b/patch/include.h index e683a5b..51b51da 100644 --- a/patch/include.h +++ b/patch/include.h @@ -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 diff --git a/patch/statuscmd.c b/patch/statuscmd.c new file mode 100644 index 0000000..2264451 --- /dev/null +++ b/patch/statuscmd.c @@ -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'; +} \ No newline at end of file diff --git a/patch/statuscmd.h b/patch/statuscmd.h new file mode 100644 index 0000000..77391b6 --- /dev/null +++ b/patch/statuscmd.h @@ -0,0 +1 @@ +static void copyvalidchars(char *text, char *rawtext); \ No newline at end of file diff --git a/patches.def.h b/patches.def.h index d2b5edc..261603a 100644 --- a/patches.def.h +++ b/patches.def.h @@ -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/ */