sites

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

dwm-scratchpad-20170207-bb3bd6f.diff (3057B)


      1 diff --git a/config.def.h b/config.def.h
      2 index ba9a240..eaaca3e 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -58,11 +58,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 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 d27cb67..3fa7274 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 *);
     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 @@ -1051,6 +1054,13 @@ manage(Window w, XWindowAttributes *wa)
     42  	           && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
     43  	c->bw = borderpx;
     44  
     45 +	if (!strcmp(c->name, scratchpadname)) {
     46 +		c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
     47 +		c->isfloating = True;
     48 +		c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
     49 +		c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
     50 +	}
     51 +
     52  	wc.border_width = c->bw;
     53  	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
     54  	XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
     55 @@ -1724,6 +1734,28 @@ togglefloating(const Arg *arg)
     56  }
     57  
     58  void
     59 +togglescratch(const Arg *arg)
     60 +{
     61 +	Client *c;
     62 +	unsigned int found = 0;
     63 +
     64 +	for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
     65 +	if (found) {
     66 +		unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
     67 +		if (newtagset) {
     68 +			selmon->tagset[selmon->seltags] = newtagset;
     69 +			focus(NULL);
     70 +			arrange(selmon);
     71 +		}
     72 +		if (ISVISIBLE(c)) {
     73 +			focus(c);
     74 +			restack(selmon);
     75 +		}
     76 +	} else
     77 +		spawn(arg);
     78 +}
     79 +
     80 +void
     81  toggletag(const Arg *arg)
     82  {
     83  	unsigned int newtags;