sites

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

dwm-pertag_with_sel-20231003-9f88553.diff (6558B)


      1 From b47a32da69a1bb6f60b9c81619f3e504278cc780 Mon Sep 17 00:00:00 2001
      2 From: Leonardo-Boss <70913810+Leonardo-Boss@users.noreply.github.com>
      3 Date: Tue, 3 Oct 2023 12:33:58 -0300
      4 Subject: [PATCH] pertag with last selection
      5 
      6 ---
      7  dwm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
      8  1 file changed, 90 insertions(+), 7 deletions(-)
      9 
     10 diff --git a/dwm.c b/dwm.c
     11 index f1d86b2..0e4d444 100644
     12 --- a/dwm.c
     13 +++ b/dwm.c
     14 @@ -111,6 +111,7 @@ typedef struct {
     15  	void (*arrange)(Monitor *);
     16  } Layout;
     17  
     18 +typedef struct Pertag Pertag;
     19  struct Monitor {
     20  	char ltsymbol[16];
     21  	float mfact;
     22 @@ -130,6 +131,7 @@ struct Monitor {
     23  	Monitor *next;
     24  	Window barwin;
     25  	const Layout *lt[2];
     26 +	Pertag *pertag;
     27  };
     28  
     29  typedef struct {
     30 @@ -271,6 +273,16 @@ static Window root, wmcheckwin;
     31  /* configuration, allows nested code to access above variables */
     32  #include "config.h"
     33  
     34 +struct Pertag {
     35 +	unsigned int curtag, prevtag; /* current and previous tag */
     36 +	int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
     37 +	float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
     38 +	unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
     39 +	const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
     40 +	int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
     41 +	Client *sel[LENGTH(tags) + 1]; /* selected client */
     42 +};
     43 +
     44  /* compile-time check if all tags fit into an unsigned int bit array. */
     45  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     46  
     47 @@ -634,6 +646,7 @@ Monitor *
     48  createmon(void)
     49  {
     50  	Monitor *m;
     51 +	unsigned int i;
     52  
     53  	m = ecalloc(1, sizeof(Monitor));
     54  	m->tagset[0] = m->tagset[1] = 1;
     55 @@ -644,6 +657,20 @@ createmon(void)
     56  	m->lt[0] = &layouts[0];
     57  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
     58  	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
     59 +	m->pertag = ecalloc(1, sizeof(Pertag));
     60 +	m->pertag->curtag = m->pertag->prevtag = 1;
     61 +
     62 +	for (i = 0; i <= LENGTH(tags); i++) {
     63 +		m->pertag->nmasters[i] = m->nmaster;
     64 +		m->pertag->mfacts[i] = m->mfact;
     65 +
     66 +		m->pertag->ltidxs[i][0] = m->lt[0];
     67 +		m->pertag->ltidxs[i][1] = m->lt[1];
     68 +		m->pertag->sellts[i] = m->sellt;
     69 +
     70 +		m->pertag->showbars[i] = m->showbar;
     71 +	}
     72 +
     73  	return m;
     74  }
     75  
     76 @@ -808,6 +835,7 @@ focus(Client *c)
     77  		XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
     78  	}
     79  	selmon->sel = c;
     80 +	selmon->pertag->sel[selmon->pertag->curtag] = c;
     81  	drawbars();
     82  }
     83  
     84 @@ -980,7 +1008,7 @@ grabkeys(void)
     85  void
     86  incnmaster(const Arg *arg)
     87  {
     88 -	selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
     89 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
     90  	arrange(selmon);
     91  }
     92  
     93 @@ -1511,9 +1539,9 @@ void
     94  setlayout(const Arg *arg)
     95  {
     96  	if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
     97 -		selmon->sellt ^= 1;
     98 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
     99  	if (arg && arg->v)
    100 -		selmon->lt[selmon->sellt] = (Layout *)arg->v;
    101 +		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
    102  	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
    103  	if (selmon->sel)
    104  		arrange(selmon);
    105 @@ -1532,7 +1560,7 @@ setmfact(const Arg *arg)
    106  	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
    107  	if (f < 0.05 || f > 0.95)
    108  		return;
    109 -	selmon->mfact = f;
    110 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
    111  	arrange(selmon);
    112  }
    113  
    114 @@ -1715,7 +1743,7 @@ tile(Monitor *m)
    115  void
    116  togglebar(const Arg *arg)
    117  {
    118 -	selmon->showbar = !selmon->showbar;
    119 +	selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
    120  	updatebarpos(selmon);
    121  	XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
    122  	arrange(selmon);
    123 @@ -1754,9 +1782,33 @@ void
    124  toggleview(const Arg *arg)
    125  {
    126  	unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
    127 +	int i;
    128  
    129  	if (newtagset) {
    130  		selmon->tagset[selmon->seltags] = newtagset;
    131 +
    132 +		if (newtagset == ~0) {
    133 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    134 +			selmon->pertag->curtag = 0;
    135 +		}
    136 +
    137 +		/* test if the user did not select the same tag */
    138 +		if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
    139 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    140 +			for (i = 0; !(newtagset & 1 << i); i++) ;
    141 +			selmon->pertag->curtag = i + 1;
    142 +		}
    143 +
    144 +		/* apply settings for this view */
    145 +		selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    146 +		selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    147 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    148 +		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    149 +		selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    150 +
    151 +		if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
    152 +			togglebar(NULL);
    153 +
    154  		focus(NULL);
    155  		arrange(selmon);
    156  	}
    157 @@ -1778,9 +1830,14 @@ unfocus(Client *c, int setfocus)
    158  void
    159  unmanage(Client *c, int destroyed)
    160  {
    161 +	int i;
    162  	Monitor *m = c->mon;
    163  	XWindowChanges wc;
    164  
    165 +	for (i = 0; i < LENGTH(tags) + 1; i++)
    166 +		if (c->mon->pertag->sel[i] == c)
    167 +			c->mon->pertag->sel[i] = NULL;
    168 +
    169  	detach(c);
    170  	detachstack(c);
    171  	if (!destroyed) {
    172 @@ -2053,12 +2110,38 @@ updatewmhints(Client *c)
    173  void
    174  view(const Arg *arg)
    175  {
    176 +	int i;
    177 +	unsigned int tmptag;
    178 +
    179  	if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    180  		return;
    181  	selmon->seltags ^= 1; /* toggle sel tagset */
    182 -	if (arg->ui & TAGMASK)
    183 +	if (arg->ui & TAGMASK) {
    184  		selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    185 -	focus(NULL);
    186 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    187 +
    188 +		if (arg->ui == ~0)
    189 +			selmon->pertag->curtag = 0;
    190 +		else {
    191 +			for (i = 0; !(arg->ui & 1 << i); i++) ;
    192 +			selmon->pertag->curtag = i + 1;
    193 +		}
    194 +	} else {
    195 +		tmptag = selmon->pertag->prevtag;
    196 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    197 +		selmon->pertag->curtag = tmptag;
    198 +	}
    199 +
    200 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    201 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    202 +	selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    203 +	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    204 +	selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    205 +
    206 +	if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
    207 +		togglebar(NULL);
    208 +
    209 +	focus(selmon->pertag->sel[selmon->pertag->curtag]);
    210  	arrange(selmon);
    211  }
    212  
    213 -- 
    214 2.41.0
    215