diff options
author | Malfurious <m@lfurio.us> | 2020-06-22 00:49:08 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-03 22:17:38 -0400 |
commit | 693081eb1e028368cc32d3dd2d1f46af341f121e (patch) | |
tree | d752b07fbd9be5e8396ce4fb1001d92d7cd19fff /dwm.c | |
parent | 1a4d4b0f6cd663c3dee2b6167993cd709cfc91cc (diff) | |
download | dwm-693081eb1e028368cc32d3dd2d1f46af341f121e.tar.gz dwm-693081eb1e028368cc32d3dd2d1f46af341f121e.zip |
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.
Diffstat (limited to 'dwm.c')
-rw-r--r-- | dwm.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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)); @@ -1869,6 +1881,28 @@ togglefloating(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; |