dwm

My fork of dwm.
git clone git://git.alex.balgavy.eu/dwm.git
Log | Files | Refs | README | LICENSE

commit ab3832fc98c88a51e1e024e7010097adc59a8ca0
parent 4d91401f903c46057c477069dd23280673015cf1
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Fri,  8 Oct 2021 12:31:19 +0200

Patch - scratchpad

Diffstat:
Mconfig.h | 3+++
Mdwm.c | 34++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/config.h b/config.h @@ -93,6 +93,8 @@ static const Layout layouts[] = { 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", selbordercolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { TERM, NULL }; +static const char scratchpadname[] = "scratchpad"; +static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; /* * Xresources preferences to load at startup @@ -126,6 +128,7 @@ static Key keys[] = { { MODKEY, XK_r, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_r, livereload_xresources, {.v = NULL } }, { MODKEY, XK_Return, spawn, {.v = termcmd } }, + { MODKEY|ShiftMask, XK_minus, togglescratch, {.v = scratchpadcmd } }, { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, diff --git a/dwm.c b/dwm.c @@ -251,6 +251,7 @@ static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglescratch(const Arg *arg); static void togglefullscr(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -335,6 +336,8 @@ struct Pertag { int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ }; +static unsigned int scratchtag = 1 << LENGTH(tags); + /* compile-time check if all tags fit into an unsigned int bit array. */ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; @@ -1229,6 +1232,14 @@ manage(Window w, XWindowAttributes *wa) && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); c->bw = borderpx; + 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); + } + wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); @@ -1860,6 +1871,7 @@ spawn(const Arg *arg) { if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; + selmon->tagset[selmon->seltags] &= ~scratchtag; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); @@ -1950,6 +1962,28 @@ togglefullscr(const Arg *arg) } 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); +} + +void toggletag(const Arg *arg) { unsigned int newtags;