sites

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

dwm-scratchpad-20190620-cb3f58a.diff (2469B)


      1 From 5ddd858a6b7cc2dc589d4046c7e9a49593c2d9dc Mon Sep 17 00:00:00 2001
      2 From: Aaron Duxler <aaron.duxler@gmail.com>
      3 Date: Thu, 20 Jun 2019 15:15:46 +0200
      4 Subject: [PATCH] [dwm][patch] scratchpad, reset scratchtag fix
      5 
      6 ---
      7  dwm.c | 34 ++++++++++++++++++++++++++++++++++
      8  1 file changed, 34 insertions(+)
      9 
     10 diff --git a/dwm.c b/dwm.c
     11 index 4465af1..6bfa2ae 100644
     12 --- a/dwm.c
     13 +++ b/dwm.c
     14 @@ -211,6 +211,7 @@ static void tagmon(const Arg *arg);
     15  static void tile(Monitor *);
     16  static void togglebar(const Arg *arg);
     17  static void togglefloating(const Arg *arg);
     18 +static void togglescratch(const Arg *arg);
     19  static void toggletag(const Arg *arg);
     20  static void toggleview(const Arg *arg);
     21  static void unfocus(Client *c, int setfocus);
     22 @@ -271,6 +272,8 @@ static Window root, wmcheckwin;
     23  /* configuration, allows nested code to access above variables */
     24  #include "config.h"
     25  
     26 +static unsigned int scratchtag = 1 << LENGTH(tags);
     27 +
     28  /* compile-time check if all tags fit into an unsigned int bit array. */
     29  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     30  
     31 @@ -1049,6 +1052,14 @@ manage(Window w, XWindowAttributes *wa)
     32  		&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
     33  	c->bw = borderpx;
     34  
     35 +	selmon->tagset[selmon->seltags] &= ~scratchtag;
     36 +	if (!strcmp(c->name, scratchpadname)) {
     37 +		c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
     38 +		c->isfloating = True;
     39 +		c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
     40 +		c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
     41 +	}
     42 +
     43  	wc.border_width = c->bw;
     44  	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
     45  	XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
     46 @@ -1641,6 +1652,7 @@ spawn(const Arg *arg)
     47  {
     48  	if (arg->v == dmenucmd)
     49  		dmenumon[0] = '0' + selmon->num;
     50 +	selmon->tagset[selmon->seltags] &= ~scratchtag;
     51  	if (fork() == 0) {
     52  		if (dpy)
     53  			close(ConnectionNumber(dpy));
     54 @@ -1719,6 +1731,28 @@ togglefloating(const Arg *arg)
     55  	arrange(selmon);
     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 -- 
     84 2.22.0
     85