sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-scratchpad-20221102-ba56fe9.diff (3284B)


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