sites

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

dwm-6.1-pertag_without_bar.diff (5270B)


      1 diff --git a/dwm.c b/dwm.c
      2 index 0362114..e44bb24 100644
      3 --- a/dwm.c
      4 +++ b/dwm.c
      5 @@ -111,6 +111,7 @@ typedef struct {
      6  	void (*arrange)(Monitor *);
      7  } Layout;
      8  
      9 +typedef struct Pertag Pertag;
     10  struct Monitor {
     11  	char ltsymbol[16];
     12  	float mfact;
     13 @@ -130,6 +131,7 @@ struct Monitor {
     14  	Monitor *next;
     15  	Window barwin;
     16  	const Layout *lt[2];
     17 +	Pertag *pertag;
     18  };
     19  
     20  typedef struct {
     21 @@ -270,6 +272,14 @@ static Window root;
     22  /* configuration, allows nested code to access above variables */
     23  #include "config.h"
     24  
     25 +struct Pertag {
     26 +	unsigned int curtag, prevtag; /* current and previous tag */
     27 +	int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
     28 +	float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
     29 +	unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
     30 +	const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
     31 +};
     32 +
     33  /* compile-time check if all tags fit into an unsigned int bit array. */
     34  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     35  
     36 @@ -640,6 +650,7 @@ Monitor *
     37  createmon(void)
     38  {
     39  	Monitor *m;
     40 +	int i;
     41  
     42  	m = ecalloc(1, sizeof(Monitor));
     43  	m->tagset[0] = m->tagset[1] = 1;
     44 @@ -650,6 +661,21 @@ createmon(void)
     45  	m->lt[0] = &layouts[0];
     46  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
     47  	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
     48 +	if (!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
     49 +		die("fatal: could not malloc() %u bytes\n", sizeof(Pertag));
     50 +	m->pertag->curtag = m->pertag->prevtag = 1;
     51 +	for (i=0; i <= LENGTH(tags); i++) {
     52 +		/* init nmaster */
     53 +		m->pertag->nmasters[i] = m->nmaster;
     54 +
     55 +		/* init mfacts */
     56 +		m->pertag->mfacts[i] = m->mfact;
     57 +
     58 +		/* init layouts */
     59 +		m->pertag->ltidxs[i][0] = m->lt[0];
     60 +		m->pertag->ltidxs[i][1] = m->lt[1];
     61 +		m->pertag->sellts[i] = m->sellt;
     62 +	}
     63  	return m;
     64  }
     65  
     66 @@ -981,7 +1007,7 @@ grabkeys(void)
     67  void
     68  incnmaster(const Arg *arg)
     69  {
     70 -	selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
     71 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
     72  	arrange(selmon);
     73  }
     74  
     75 @@ -1517,10 +1543,13 @@ setfullscreen(Client *c, int fullscreen)
     76  void
     77  setlayout(const Arg *arg)
     78  {
     79 -	if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
     80 -		selmon->sellt ^= 1;
     81 +	if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
     82 +		selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
     83 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
     84 +	}
     85  	if (arg && arg->v)
     86 -		selmon->lt[selmon->sellt] = (Layout *)arg->v;
     87 +		selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
     88 +	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
     89  	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
     90  	if (selmon->sel)
     91  		arrange(selmon);
     92 @@ -1539,7 +1568,7 @@ setmfact(const Arg *arg)
     93  	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
     94  	if (f < 0.1 || f > 0.9)
     95  		return;
     96 -	selmon->mfact = f;
     97 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
     98  	arrange(selmon);
     99  }
    100  
    101 @@ -1731,9 +1760,27 @@ void
    102  toggleview(const Arg *arg)
    103  {
    104  	unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
    105 +	int i;
    106  
    107  	if (newtagset) {
    108 +		if (newtagset == ~0) {
    109 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    110 +			selmon->pertag->curtag = 0;
    111 +		}
    112 +		/* test if the user did not select the same tag */
    113 +		if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
    114 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    115 +			for (i=0; !(newtagset & 1 << i); i++) ;
    116 +			selmon->pertag->curtag = i + 1;
    117 +		}
    118  		selmon->tagset[selmon->seltags] = newtagset;
    119 +
    120 +		/* apply settings for this view */
    121 +		selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    122 +		selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    123 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    124 +		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    125 +		selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    126  		focus(NULL);
    127  		arrange(selmon);
    128  	}
    129 @@ -2031,11 +2078,31 @@ updatewmhints(Client *c)
    130  void
    131  view(const Arg *arg)
    132  {
    133 +	int i;
    134 +	unsigned int tmptag;
    135 +
    136  	if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    137  		return;
    138  	selmon->seltags ^= 1; /* toggle sel tagset */
    139 -	if (arg->ui & TAGMASK)
    140 +	if (arg->ui & TAGMASK) {
    141 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    142  		selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    143 +		if (arg->ui == ~0)
    144 +			selmon->pertag->curtag = 0;
    145 +		else {
    146 +			for (i=0; !(arg->ui & 1 << i); i++) ;
    147 +			selmon->pertag->curtag = i + 1;
    148 +		}
    149 +	} else {
    150 +		tmptag = selmon->pertag->prevtag;
    151 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    152 +		selmon->pertag->curtag = tmptag;
    153 +	}
    154 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    155 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    156 +	selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    157 +	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    158 +	selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    159  	focus(NULL);
    160  	arrange(selmon);
    161  }