sites

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

dwm-pertag-6.1.diff (6458B)


      1 diff --git a/dwm.c b/dwm.c
      2 index 0362114..9ba4ec5 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,16 @@ 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 +	Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
     32 +	Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */
     33 +};
     34 +
     35  /* compile-time check if all tags fit into an unsigned int bit array. */
     36  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
     37  
     38 @@ -526,6 +538,7 @@ clientmessage(XEvent *e)
     39  {
     40  	XClientMessageEvent *cme = &e->xclient;
     41  	Client *c = wintoclient(cme->window);
     42 +	int i;
     43  
     44  	if (!c)
     45  		return;
     46 @@ -537,6 +550,8 @@ clientmessage(XEvent *e)
     47  		if (!ISVISIBLE(c)) {
     48  			c->mon->seltags ^= 1;
     49  			c->mon->tagset[c->mon->seltags] = c->tags;
     50 +			for(i=0; !(c->tags & 1 << i); i++);
     51 +			view(&(Arg){.ui = 1 << i});
     52  		}
     53  		pop(c);
     54  	}
     55 @@ -640,6 +655,7 @@ Monitor *
     56  createmon(void)
     57  {
     58  	Monitor *m;
     59 +	int i;
     60  
     61  	m = ecalloc(1, sizeof(Monitor));
     62  	m->tagset[0] = m->tagset[1] = 1;
     63 @@ -650,6 +666,27 @@ createmon(void)
     64  	m->lt[0] = &layouts[0];
     65  	m->lt[1] = &layouts[1 % LENGTH(layouts)];
     66  	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
     67 +	if (!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
     68 +		die("fatal: could not malloc() %u bytes\n", sizeof(Pertag));
     69 +	m->pertag->curtag = m->pertag->prevtag = 1;
     70 +	for(i=0; i <= LENGTH(tags); i++) {
     71 +		/* init nmaster */
     72 +		m->pertag->nmasters[i] = m->nmaster;
     73 +
     74 +		/* init mfacts */
     75 +		m->pertag->mfacts[i] = m->mfact;
     76 +
     77 +		/* init layouts */
     78 +		m->pertag->ltidxs[i][0] = m->lt[0];
     79 +		m->pertag->ltidxs[i][1] = m->lt[1];
     80 +		m->pertag->sellts[i] = m->sellt;
     81 +
     82 +		/* init showbar */
     83 +		m->pertag->showbars[i] = m->showbar;
     84 +
     85 +		/* swap focus and zoomswap*/
     86 +		m->pertag->prevzooms[i] = NULL;
     87 +	}
     88  	return m;
     89  }
     90  
     91 @@ -981,7 +1018,7 @@ grabkeys(void)
     92  void
     93  incnmaster(const Arg *arg)
     94  {
     95 -	selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
     96 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
     97  	arrange(selmon);
     98  }
     99  
    100 @@ -1517,10 +1554,13 @@ setfullscreen(Client *c, int fullscreen)
    101  void
    102  setlayout(const Arg *arg)
    103  {
    104 -	if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
    105 -		selmon->sellt ^= 1;
    106 +	if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
    107 +		selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
    108 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    109 +	}
    110  	if (arg && arg->v)
    111 -		selmon->lt[selmon->sellt] = (Layout *)arg->v;
    112 +		selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
    113 +	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    114  	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
    115  	if (selmon->sel)
    116  		arrange(selmon);
    117 @@ -1539,7 +1579,7 @@ setmfact(const Arg *arg)
    118  	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
    119  	if (f < 0.1 || f > 0.9)
    120  		return;
    121 -	selmon->mfact = f;
    122 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
    123  	arrange(selmon);
    124  }
    125  
    126 @@ -1692,7 +1732,7 @@ tile(Monitor *m)
    127  void
    128  togglebar(const Arg *arg)
    129  {
    130 -	selmon->showbar = !selmon->showbar;
    131 +	selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
    132  	updatebarpos(selmon);
    133  	XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
    134  	arrange(selmon);
    135 @@ -1731,9 +1771,29 @@ void
    136  toggleview(const Arg *arg)
    137  {
    138  	unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
    139 +	int i;
    140  
    141  	if (newtagset) {
    142 +		if (newtagset == ~0) {
    143 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    144 +			selmon->pertag->curtag = 0;
    145 +		}
    146 +		/* test if the user did not select the same tag */
    147 +		if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
    148 +			selmon->pertag->prevtag = selmon->pertag->curtag;
    149 +			for (i=0; !(newtagset & 1 << i); i++) ;
    150 +			selmon->pertag->curtag = i + 1;
    151 +		}
    152  		selmon->tagset[selmon->seltags] = newtagset;
    153 +
    154 +		/* apply settings for this view */
    155 +		selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    156 +		selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    157 +		selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    158 +		selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    159 +		selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    160 +		if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
    161 +			togglebar(NULL);
    162  		focus(NULL);
    163  		arrange(selmon);
    164  	}
    165 @@ -2031,11 +2091,33 @@ updatewmhints(Client *c)
    166  void
    167  view(const Arg *arg)
    168  {
    169 +	int i;
    170 +	unsigned int tmptag;
    171 +
    172  	if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
    173  		return;
    174  	selmon->seltags ^= 1; /* toggle sel tagset */
    175 -	if (arg->ui & TAGMASK)
    176 +	if (arg->ui & TAGMASK) {
    177 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    178  		selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
    179 +		if (arg->ui == ~0)
    180 +			selmon->pertag->curtag = 0;
    181 +		else {
    182 +			for (i=0; !(arg->ui & 1 << i); i++) ;
    183 +			selmon->pertag->curtag = i + 1;
    184 +		}
    185 +	} else {
    186 +		tmptag = selmon->pertag->prevtag;
    187 +		selmon->pertag->prevtag = selmon->pertag->curtag;
    188 +		selmon->pertag->curtag = tmptag;
    189 +	}
    190 +	selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
    191 +	selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
    192 +	selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
    193 +	selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
    194 +	selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
    195 +	if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
    196 +		togglebar(NULL);
    197  	focus(NULL);
    198  	arrange(selmon);
    199  }