From 693081eb1e028368cc32d3dd2d1f46af341f121e Mon Sep 17 00:00:00 2001 From: Malfurious Date: Mon, 22 Jun 2020 00:49:08 -0400 Subject: patch: scratchpad The scratchpad patch allows you to spawn or restore a floating terminal window. It is usually useful to have one to do some short typing. A tool like detach (http://detach.sourceforge.net) turns it into a launchpad for X applications. By default your terminal (st) is used, and the default key binding is MODKEY+XK_grave. A config.def.h change is included in the patch. --- dwm.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index f4965e8..37373da 100644 --- a/dwm.c +++ b/dwm.c @@ -219,6 +219,7 @@ static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); static void togglefloating(const Arg *arg); +static void togglescratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -296,6 +297,8 @@ struct Pertag { const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */ }; +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]; }; @@ -1124,6 +1127,14 @@ manage(Window w, XWindowAttributes *wa) c->y = MAX(c->y, c->mon->wy); 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); @@ -1769,6 +1780,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)); @@ -1868,6 +1880,28 @@ togglefloating(const Arg *arg) arrange(selmon); } +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) { -- cgit v1.2.3