dwm-scratchpad-20190601-cb3f58a.diff (3590B)
1 From 9a521a40264575c977403218aa0f66f6f3e9a26f Mon Sep 17 00:00:00 2001 2 From: Aaron Duxler <aaron.duxler@gmail.com> 3 Date: Sat, 1 Jun 2019 10:19:19 +0200 4 Subject: [PATCH] patch scratchpad bugfix 5 6 --- 7 config.def.h | 3 +++ 8 dwm.c | 33 +++++++++++++++++++++++++++++++++ 9 2 files changed, 36 insertions(+) 10 11 diff --git a/config.def.h b/config.def.h 12 index 1c0b587..8a5b9d6 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -58,11 +58,14 @@ static const Layout layouts[] = { 16 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ 17 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; 18 static const char *termcmd[] = { "st", NULL }; 19 +static const char scratchpadname[] = "scratchpad"; 20 +static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; 21 22 static Key keys[] = { 23 /* modifier key function argument */ 24 { MODKEY, XK_p, spawn, {.v = dmenucmd } }, 25 { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, 26 + { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, 27 { MODKEY, XK_b, togglebar, {0} }, 28 { MODKEY, XK_j, focusstack, {.i = +1 } }, 29 { MODKEY, XK_k, focusstack, {.i = -1 } }, 30 diff --git a/dwm.c b/dwm.c 31 index 4465af1..610625f 100644 32 --- a/dwm.c 33 +++ b/dwm.c 34 @@ -211,6 +211,7 @@ static void tagmon(const Arg *arg); 35 static void tile(Monitor *); 36 static void togglebar(const Arg *arg); 37 static void togglefloating(const Arg *arg); 38 +static void togglescratch(const Arg *arg); 39 static void toggletag(const Arg *arg); 40 static void toggleview(const Arg *arg); 41 static void unfocus(Client *c, int setfocus); 42 @@ -271,6 +272,8 @@ static Window root, wmcheckwin; 43 /* configuration, allows nested code to access above variables */ 44 #include "config.h" 45 46 +static unsigned int scratchtag = 1 << LENGTH(tags); 47 + 48 /* compile-time check if all tags fit into an unsigned int bit array. */ 49 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 50 51 @@ -1049,6 +1052,13 @@ manage(Window w, XWindowAttributes *wa) 52 && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); 53 c->bw = borderpx; 54 55 + if (!strcmp(c->name, scratchpadname)) { 56 + c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; 57 + c->isfloating = True; 58 + c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); 59 + c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); 60 + } 61 + 62 wc.border_width = c->bw; 63 XConfigureWindow(dpy, w, CWBorderWidth, &wc); 64 XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); 65 @@ -1641,6 +1651,7 @@ spawn(const Arg *arg) 66 { 67 if (arg->v == dmenucmd) 68 dmenumon[0] = '0' + selmon->num; 69 + selmon->tagset[selmon->seltags] &= ~scratchtag; 70 if (fork() == 0) { 71 if (dpy) 72 close(ConnectionNumber(dpy)); 73 @@ -1719,6 +1730,28 @@ togglefloating(const Arg *arg) 74 arrange(selmon); 75 } 76 77 +void 78 +togglescratch(const Arg *arg) 79 +{ 80 + Client *c; 81 + unsigned int found = 0; 82 + 83 + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); 84 + if (found) { 85 + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; 86 + if (newtagset) { 87 + selmon->tagset[selmon->seltags] = newtagset; 88 + focus(NULL); 89 + arrange(selmon); 90 + } 91 + if (ISVISIBLE(c)) { 92 + focus(c); 93 + restack(selmon); 94 + } 95 + } else 96 + spawn(arg); 97 +} 98 + 99 void 100 toggletag(const Arg *arg) 101 { 102 -- 103 2.21.0 104