dwm-scratchpad-6.4.diff (3059B)
1 diff -ruN a/config.def.h b/config.def.h 2 --- a/config.def.h 2023-01-10 18:37:07.292111676 +0100 3 +++ b/config.def.h 2023-01-10 18:37:21.026031671 +0100 4 @@ -58,11 +58,14 @@ 5 /* commands */ 6 static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; 7 static const char *termcmd[] = { "st", NULL }; 8 +static const char scratchpadname[] = "scratchpad"; 9 +static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; 10 11 static const Key keys[] = { 12 /* modifier key function argument */ 13 { MODKEY, XK_p, spawn, {.v = dmenucmd } }, 14 { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, 15 + { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } }, 16 { MODKEY, XK_b, togglebar, {0} }, 17 { MODKEY, XK_j, focusstack, {.i = +1 } }, 18 { MODKEY, XK_k, focusstack, {.i = -1 } }, 19 diff -ruN a/dwm.c b/dwm.c 20 --- a/dwm.c 2022-10-04 19:38:18.000000000 +0200 21 +++ b/dwm.c 2023-01-10 18:21:31.922802546 +0100 22 @@ -212,6 +212,7 @@ 23 static void tile(Monitor *m); 24 static void togglebar(const Arg *arg); 25 static void togglefloating(const Arg *arg); 26 +static void togglescratch(const Arg *arg); 27 static void toggletag(const Arg *arg); 28 static void toggleview(const Arg *arg); 29 static void unfocus(Client *c, int setfocus); 30 @@ -272,6 +273,8 @@ 31 /* configuration, allows nested code to access above variables */ 32 #include "config.h" 33 34 +static unsigned int scratchtag = 1 << LENGTH(tags); 35 + 36 /* compile-time check if all tags fit into an unsigned int bit array. */ 37 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 38 39 @@ -1052,6 +1055,14 @@ 40 c->y = MAX(c->y, c->mon->wy); 41 c->bw = borderpx; 42 43 + selmon->tagset[selmon->seltags] &= ~scratchtag; 44 + if (!strcmp(c->name, scratchpadname)) { 45 + c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; 46 + c->isfloating = True; 47 + c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); 48 + c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); 49 + } 50 + 51 wc.border_width = c->bw; 52 XConfigureWindow(dpy, w, CWBorderWidth, &wc); 53 XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); 54 @@ -1639,6 +1650,7 @@ 55 void 56 spawn(const Arg *arg) 57 { 58 + selmon->tagset[selmon->seltags] &= ~scratchtag; 59 if (fork() == 0) { 60 if (dpy) 61 close(ConnectionNumber(dpy)); 62 @@ -1718,6 +1730,28 @@ 63 } 64 65 void 66 +togglescratch(const Arg *arg) 67 +{ 68 + Client *c; 69 + unsigned int found = 0; 70 + 71 + for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next); 72 + if (found) { 73 + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag; 74 + if (newtagset) { 75 + selmon->tagset[selmon->seltags] = newtagset; 76 + focus(NULL); 77 + arrange(selmon); 78 + } 79 + if (ISVISIBLE(c)) { 80 + focus(c); 81 + restack(selmon); 82 + } 83 + } else 84 + spawn(arg); 85 +} 86 + 87 +void 88 toggletag(const Arg *arg) 89 { 90 unsigned int newtags;