diff --git a/README.md b/README.md index aecd4bf..a92ecf7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-10-10 - Added mdpcontrol patch +2019-10-10 - Added mdpcontrol and scratchpad patches 2019-10-08 - Added columns layout and fakefullscreen patch @@ -202,6 +202,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - saves size and position of every floating window before it is forced into tiled mode - if the window is made floating again then the old dimensions will be restored + - [scratchpad](https://dwm.suckless.org/patches/scratchpad/) + - the scratchpad patch allows you to spawn or restore a floating terminal window + - [selfrestart](https://dwm.suckless.org/patches/selfrestart/) - restart dwm without the unnecessary dependency of an external script diff --git a/config.def.h b/config.def.h index 8217e30..8c887c5 100644 --- a/config.def.h +++ b/config.def.h @@ -393,10 +393,18 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; +#if SCRATCHPAD_PATCH +static const char scratchpadname[] = "scratchpad"; +static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; +#endif // SCRATCHPAD_PATCH + static Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + #if SCRATCHPAD_PATCH + { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, + #endif // SCRATCHPAD_PATCH { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, diff --git a/dwm.c b/dwm.c index 95129b5..5cf3675 100644 --- a/dwm.c +++ b/dwm.c @@ -1882,6 +1882,16 @@ manage(Window w, XWindowAttributes *wa) c->bw = borderpx; #endif // SETBORDERPX_PATCH + #if SCRATCHPAD_PATCH + selmon->tagset[selmon->seltags] &= ~scratchtag; + if (!strcmp(c->name, scratchpadname)) { + c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; + c->isfloating = True; + c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); + c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); + } + #endif // SCRATCHPAD_PATCH + wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); #if FLOAT_BORDER_COLOR_PATCH @@ -2799,6 +2809,9 @@ spawn(const Arg *arg) { if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; + #if SCRATCHPAD_PATCH + selmon->tagset[selmon->seltags] &= ~scratchtag; + #endif // SCRATCHPAD_PATCH if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); diff --git a/patch/include.c b/patch/include.c index e86b053..7d99f76 100644 --- a/patch/include.c +++ b/patch/include.c @@ -94,6 +94,10 @@ #include "rotatestack.c" #endif +#if SCRATCHPAD_PATCH +#include "scratchpad.c" +#endif + #if SELFRESTART_PATCH #include "selfrestart.c" #endif diff --git a/patch/include.h b/patch/include.h index c38f849..c2586b4 100644 --- a/patch/include.h +++ b/patch/include.h @@ -94,6 +94,10 @@ #include "rotatestack.h" #endif +#if SCRATCHPAD_PATCH +#include "scratchpad.h" +#endif + #if SELFRESTART_PATCH #include "selfrestart.h" #endif diff --git a/patch/scratchpad.c b/patch/scratchpad.c new file mode 100644 index 0000000..7ba6366 --- /dev/null +++ b/patch/scratchpad.c @@ -0,0 +1,23 @@ +static unsigned int scratchtag = 1 << LENGTH(tags); + +void +togglescratch(const Arg *arg) +{ + Client *c; + unsigned int found = 0; + + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); + if (found) { + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; + if (newtagset) { + selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); + arrange(selmon); + } + if (ISVISIBLE(c)) { + focus(c); + restack(selmon); + } + } else + spawn(arg); +} \ No newline at end of file diff --git a/patch/scratchpad.h b/patch/scratchpad.h new file mode 100644 index 0000000..be5c3a4 --- /dev/null +++ b/patch/scratchpad.h @@ -0,0 +1 @@ +static void togglescratch(const Arg *arg); \ No newline at end of file diff --git a/patches.h b/patches.h index 62269e6..52ac273 100644 --- a/patches.h +++ b/patches.h @@ -310,6 +310,12 @@ */ #define SAVEFLOATS_PATCH 0 +/* The scratchpad patch allows you to spawn or restore a floating terminal window. + * It is typically useful when one need to do some short typing. + * https://dwm.suckless.org/patches/scratchpad/ + */ +#define SCRATCHPAD_PATCH 0 + /* Allows restarting dwm without the dependency of an external script. * https://dwm.suckless.org/patches/selfrestart/ */