dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

layout_centeredmaster.c (4438B)


      1 void
      2 centeredmaster(Monitor *m)
      3 {
      4 	unsigned int i, n;
      5 	int mx = 0, my = 0, mh = 0, mw = 0;
      6 	int lx = 0, ly = 0, lw = 0, lh = 0;
      7 	int rx = 0, ry = 0, rw = 0, rh = 0;
      8 	float mfacts = 0, lfacts = 0, rfacts = 0;
      9 	int mtotal = 0, ltotal = 0, rtotal = 0;
     10 	int mrest = 0, lrest = 0, rrest = 0;
     11 	Client *c;
     12 
     13 	#if VANITYGAPS_PATCH
     14 	int oh, ov, ih, iv;
     15 	getgaps(m, &oh, &ov, &ih, &iv, &n);
     16 	#else
     17 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
     18 	#endif // VANITYGAPS_PATCH
     19 
     20 	if (n == 0)
     21 		return;
     22 
     23 	/* initialize areas */
     24 	#if VANITYGAPS_PATCH
     25 	mx = m->wx + ov;
     26 	my = m->wy + oh;
     27 	mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
     28 	mw = m->ww - 2*ov;
     29 	lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
     30 	rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
     31 
     32 	if (m->nmaster && n > m->nmaster) {
     33 		/* go mfact box in the center if more than nmaster clients */
     34 		if (n - m->nmaster > 1) {
     35 			/* ||<-S->|<---M--->|<-S->|| */
     36 			mw = (m->ww - 2*ov - 2*iv) * m->mfact;
     37 			lw = (m->ww - mw - 2*ov - 2*iv) / 2;
     38 			mx += lw + iv;
     39 		} else {
     40 			/* ||<---M--->|<-S->|| */
     41 			mw = (mw - iv) * m->mfact;
     42 			lw = m->ww - mw - iv - 2*ov;
     43 		}
     44 		rw = lw;
     45 		lx = m->wx + ov;
     46 		ly = m->wy + oh;
     47 		rx = mx + mw + iv;
     48 		ry = m->wy + oh;
     49 	}
     50 	#else
     51 	mx = m->wx;
     52 	my = m->wy;
     53 	mh = m->wh;
     54 	mw = m->ww;
     55 	lh = m->wh;
     56 	rh = m->wh;
     57 
     58 	if (m->nmaster && n > m->nmaster) {
     59 		/* go mfact box in the center if more than nmaster clients */
     60 		if (n - m->nmaster > 1) {
     61 			/* ||<-S->|<---M--->|<-S->|| */
     62 			mw = m->ww * m->mfact;
     63 			lw = (m->ww - mw) / 2;
     64 			mx += lw;
     65 		} else {
     66 			/* ||<---M--->|<-S->|| */
     67 			mw = mw * m->mfact;
     68 			lw = m->ww - mw;
     69 		}
     70 		rw = lw;
     71 		lx = m->wx;
     72 		ly = m->wy;
     73 		rx = mx + mw;
     74 		ry = m->wy;
     75 	}
     76 	#endif // VANITYGAPS_PATCH
     77 
     78 	/* calculate facts */
     79 	#if CFACTS_PATCH
     80 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
     81 		if (!m->nmaster || n < m->nmaster)
     82 			mfacts += c->cfact; // total factor of master area
     83 		else if ((n - m->nmaster) % 2)
     84 			lfacts += c->cfact; // total factor of left hand stack area
     85 		else
     86 			rfacts += c->cfact; // total factor of right hand stack area
     87 	}
     88 
     89 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
     90 		if (!m->nmaster || n < m->nmaster)
     91 			mtotal += mh / mfacts;
     92 		else if ((n - m->nmaster) % 2)
     93 			ltotal += lh * (c->cfact / lfacts);
     94 		else
     95 			rtotal += rh * (c->cfact / rfacts);
     96 	#else
     97 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
     98 		if (!m->nmaster || n < m->nmaster)
     99 			mfacts += 1;
    100 		else if ((n - m->nmaster) % 2)
    101 			lfacts += 1; // total factor of left hand stack area
    102 		else
    103 			rfacts += 1; // total factor of right hand stack area
    104 	}
    105 
    106 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
    107 		if (!m->nmaster || n < m->nmaster)
    108 			mtotal += mh / mfacts;
    109 		else if ((n - m->nmaster) % 2)
    110 			ltotal += lh / lfacts;
    111 		else
    112 			rtotal += rh / rfacts;
    113 	#endif // CFACTS_PATCH
    114 
    115 	mrest = mh - mtotal;
    116 	lrest = lh - ltotal;
    117 	rrest = rh - rtotal;
    118 
    119 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
    120 		if (!m->nmaster || i < m->nmaster) {
    121 			/* nmaster clients are stacked vertically, in the center of the screen */
    122 			#if CFACTS_PATCH
    123 			resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) * c->cfact + (i < mrest ? 1 : 0) - (2*c->bw), 0);
    124 			#else
    125 			resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
    126 			#endif // CFACTS_PATCH
    127 			#if VANITYGAPS_PATCH
    128 			my += HEIGHT(c) + ih;
    129 			#else
    130 			my += HEIGHT(c);
    131 			#endif
    132 		} else {
    133 			/* stack clients are stacked vertically */
    134 			if ((i - m->nmaster) % 2 ) {
    135 				#if CFACTS_PATCH
    136 				resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) * c->cfact + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
    137 				#else
    138 				resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
    139 				#endif // CFACTS_PATCH
    140 				#if VANITYGAPS_PATCH
    141 				ly += HEIGHT(c) + ih;
    142 				#else
    143 				ly += HEIGHT(c);
    144 				#endif
    145 			} else {
    146 				#if CFACTS_PATCH
    147 				resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) * c->cfact + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
    148 				#else
    149 				resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
    150 				#endif // CFACTS_PATCH
    151 				#if VANITYGAPS_PATCH
    152 				ry += HEIGHT(c) + ih;
    153 				#else
    154 				ry += HEIGHT(c);
    155 				#endif
    156 			}
    157 		}
    158 	}
    159 }
    160