dwm

personal fork of dwm (rnpnr branch)
git clone anongit@rnpnr.xyz:dwm.git
Log | Files | Refs | Feed | README | LICENSE

layouts.c (8086B)


      1 /*
      2  * Bottomstack layout + gaps
      3  * https://dwm.suckless.org/patches/bottomstack/
      4  */
      5 static void
      6 bstack(Monitor *m)
      7 {
      8 	unsigned int i, n;
      9 	int oh, ov, ih, iv;
     10 	int mx = 0, my = 0, mh = 0, mw = 0;
     11 	int sx = 0, sy = 0, sh = 0, sw = 0;
     12 	float mfacts, sfacts;
     13 	int mrest, srest;
     14 	Client *c;
     15 
     16 	getgaps(m, &oh, &ov, &ih, &iv, &n);
     17 	if (n == 0)
     18 		return;
     19 
     20 	sx = mx = m->wx + ov;
     21 	sy = my = m->wy + oh;
     22 	sh = mh = m->wh - 2*oh;
     23 	mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
     24 	sw = m->ww - 2*ov - iv * (n - m->nmaster - 1);
     25 
     26 	if (m->nmaster && n > m->nmaster) {
     27 		sh = (mh - ih) * (1 - m->mfact);
     28 		mh = mh - ih - sh;
     29 		sx = mx;
     30 		sy = my + mh + ih;
     31 	}
     32 
     33 	getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
     34 
     35 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
     36 		if (i < m->nmaster) {
     37 			resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 :
     38 			0) - (2*c->bw),
     39 			       mh - (2*c->bw), 0);
     40 			mx += WIDTH(c) + iv;
     41 		} else {
     42 			resize(c, sx, sy,
     43 			       (sw / sfacts) + ((i - m->nmaster) < srest
     44 			       ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
     45 			sx += WIDTH(c) + iv;
     46 		}
     47 	}
     48 }
     49 
     50 static void
     51 bstackhoriz(Monitor *m)
     52 {
     53 	unsigned int i, n;
     54 	int oh, ov, ih, iv;
     55 	int mx = 0, my = 0, mh = 0, mw = 0;
     56 	int sx = 0, sy = 0, sh = 0, sw = 0;
     57 	float mfacts, sfacts;
     58 	int mrest, srest;
     59 	Client *c;
     60 
     61 	getgaps(m, &oh, &ov, &ih, &iv, &n);
     62 	if (n == 0)
     63 		return;
     64 
     65 	sx = mx = m->wx + ov;
     66 	sy = my = m->wy + oh;
     67 	mh = m->wh - 2*oh;
     68 	sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
     69 	mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
     70 	sw = m->ww - 2*ov;
     71 
     72 	if (m->nmaster && n > m->nmaster) {
     73 		sh = (mh - ih) * (1 - m->mfact);
     74 		mh = mh - ih - sh;
     75 		sy = my + mh + ih;
     76 		sh = m->wh - mh - 2*oh - ih * (n - m->nmaster);
     77 	}
     78 
     79 	getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
     80 
     81 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
     82 		if (i < m->nmaster) {
     83 			resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw),
     84 			       mh - (2*c->bw), 0);
     85 			mx += WIDTH(c) + iv;
     86 		} else {
     87 			resize(c, sx, sy, sw - (2*c->bw),
     88 			       (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
     89 			sy += HEIGHT(c) + ih;
     90 		}
     91 	}
     92 }
     93 
     94 /*
     95  * Centred master layout + gaps
     96  * https://dwm.suckless.org/patches/centeredmaster/
     97  */
     98 static void
     99 centeredmaster(Monitor *m)
    100 {
    101 	unsigned int i, n;
    102 	int oh, ov, ih, iv;
    103 	int mx = 0, my = 0, mh = 0, mw = 0;
    104 	int lx = 0, ly = 0, lw = 0, lh = 0;
    105 	int rx = 0, ry = 0, rw = 0, rh = 0;
    106 	float mfacts = 0, lfacts = 0, rfacts = 0;
    107 	int mtotal = 0, ltotal = 0, rtotal = 0;
    108 	int mrest = 0, lrest = 0, rrest = 0;
    109 	Client *c;
    110 
    111 	getgaps(m, &oh, &ov, &ih, &iv, &n);
    112 	if (n == 0)
    113 		return;
    114 
    115 	/* initialize areas */
    116 	mx = m->wx + ov;
    117 	my = m->wy + oh;
    118 	mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
    119 	mw = m->ww - 2*ov;
    120 	lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
    121 	rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
    122 
    123 	if (m->nmaster && n > m->nmaster) {
    124 		/* go mfact box in the center if more than nmaster clients */
    125 		if (n - m->nmaster > 1) {
    126 			/* ||<-S->|<---M--->|<-S->|| */
    127 			mw = (m->ww - 2*ov - 2*iv) * m->mfact;
    128 			lw = (m->ww - mw - 2*ov - 2*iv) / 2;
    129 			rw = (m->ww - mw - 2*ov - 2*iv) - lw;
    130 			mx += lw + iv;
    131 		} else {
    132 			/* ||<---M--->|<-S->|| */
    133 			mw = (mw - iv) * m->mfact;
    134 			lw = 0;
    135 			rw = m->ww - mw - iv - 2*ov;
    136 		}
    137 		lx = m->wx + ov;
    138 		ly = m->wy + oh;
    139 		rx = mx + mw + iv;
    140 		ry = m->wy + oh;
    141 	}
    142 
    143 	/* calculate facts */
    144 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
    145 		if (!m->nmaster || n < m->nmaster)
    146 			mfacts += 1;
    147 		else if ((n - m->nmaster) % 2)
    148 			lfacts += 1; /* total factor of left hand stack area */
    149 		else
    150 			rfacts += 1; /* total factor of right hand stack area */
    151 	}
    152 
    153 	for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
    154 		if (!m->nmaster || n < m->nmaster)
    155 			mtotal += mh / mfacts;
    156 		else if ((n - m->nmaster) % 2)
    157 			ltotal += lh / lfacts;
    158 		else
    159 			rtotal += rh / rfacts;
    160 
    161 	mrest = mh - mtotal;
    162 	lrest = lh - ltotal;
    163 	rrest = rh - rtotal;
    164 
    165 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
    166 		if (!m->nmaster || i < m->nmaster) {
    167 			/* nmaster clients are stacked vertically, in the center of the screen */
    168 			resize(c, mx, my, mw - (2*c->bw),
    169 			       (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
    170 			my += HEIGHT(c) + ih;
    171 		} else {
    172 			/* stack clients are stacked vertically */
    173 			if ((i - m->nmaster) % 2 ) {
    174 				resize(c, lx, ly, lw - (2*c->bw),
    175 				       (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw),
    176 				       0);
    177 				ly += HEIGHT(c) + ih;
    178 			} else {
    179 				resize(c, rx, ry, rw - (2*c->bw),
    180 				       (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw),
    181 				       0);
    182 				ry += HEIGHT(c) + ih;
    183 			}
    184 		}
    185 	}
    186 }
    187 
    188 /*
    189  * Deck layout + gaps
    190  * https://dwm.suckless.org/patches/deck/
    191  */
    192 void
    193 deck(Monitor *m)
    194 {
    195 	unsigned int i, n;
    196 	int oh, ov, ih, iv;
    197 	int mx = 0, my = 0, mh = 0, mw = 0;
    198 	int sx = 0, sy = 0, sh = 0, sw = 0;
    199 	float mfacts, sfacts;
    200 	int mrest, srest;
    201 	Client *c;
    202 
    203 	getgaps(m, &oh, &ov, &ih, &iv, &n);
    204 	if (n == 0)
    205 		return;
    206 
    207 	sx = mx = m->wx + ov;
    208 	sy = my = m->wy + oh;
    209 	sh = mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
    210 	sw = mw = m->ww - 2*ov;
    211 
    212 	if (m->nmaster && n > m->nmaster) {
    213 		sw = (mw - iv) * (1 - m->mfact);
    214 		mw = mw - iv - sw;
    215 		sx = mx + mw + iv;
    216 		sh = m->wh - 2*oh;
    217 	}
    218 
    219 	getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
    220 
    221 	if (n - m->nmaster > 0) /* override layout symbol */
    222 		snprintf(m->ltsymbol, sizeof(m->ltsymbol), "M[%d]", n - m->nmaster);
    223 
    224 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    225 		if (i < m->nmaster) {
    226 			resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
    227 			my += HEIGHT(c) + ih;
    228 		} else {
    229 			resize(c, sx, sy, sw - (2*c->bw), sh - (2*c->bw), 0);
    230 		}
    231 }
    232 
    233 /*
    234  * Horizontal grid layout + gaps
    235  * https://dwm.suckless.org/patches/horizgrid/
    236  */
    237 static void
    238 horizgrid(Monitor *m)
    239 {
    240 	Client *c;
    241 	unsigned int n, i;
    242 	int oh, ov, ih, iv;
    243 	int mx = 0, my = 0, mh = 0, mw = 0;
    244 	int sx = 0, sy = 0, sh = 0, sw = 0;
    245 	int ntop, nbottom = 1;
    246 	float mfacts, sfacts;
    247 	int mrest, srest;
    248 
    249 	/* Count windows */
    250 	getgaps(m, &oh, &ov, &ih, &iv, &n);
    251 	if (n == 0)
    252 		return;
    253 
    254 	if (n <= 2)
    255 		ntop = n;
    256 	else {
    257 		ntop = n / 2;
    258 		nbottom = n - ntop;
    259 	}
    260 	sx = mx = m->wx + ov;
    261 	sw = mw = m->ww - 2*ov - iv * (ntop - 1);
    262 	sy = my = m->wy + oh;
    263 	sh = mh = m->wh - 2*oh;
    264 
    265 	if (n > ntop) {
    266 		sh = (mh - ih) / 2;
    267 		mh = mh - ih - sh;
    268 		sy = my + mh + ih;
    269 		sw = m->ww - 2*ov - iv * (nbottom - 1);
    270 	}
    271 
    272 	mfacts = ntop;
    273 	sfacts = nbottom;
    274 	mrest = mw - (mw / ntop) * ntop;
    275 	srest = sw - (sw / nbottom) * nbottom;
    276 
    277 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    278 		if (i < ntop) {
    279 			resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw),
    280 			       mh - (2*c->bw), 0);
    281 			mx += WIDTH(c) + iv;
    282 		} else {
    283 			resize(c, sx, sy,
    284 			       (sw / sfacts) + ((i - ntop) < srest ? 1 : 0) - (2*c->bw),
    285 			       sh - (2*c->bw), 0);
    286 			sx += WIDTH(c) + iv;
    287 		}
    288 }
    289 
    290 /*
    291  * Default tile layout + gaps
    292  */
    293 static void
    294 tile(Monitor *m)
    295 {
    296 	unsigned int i, n;
    297 	int oh, ov, ih, iv;
    298 	int mx = 0, my = 0, mh = 0, mw = 0;
    299 	int sx = 0, sy = 0, sh = 0, sw = 0;
    300 	float mfacts, sfacts;
    301 	int mrest, srest;
    302 	Client *c;
    303 
    304 	getgaps(m, &oh, &ov, &ih, &iv, &n);
    305 	if (n == 0)
    306 		return;
    307 
    308 	sx = mx = m->wx + ov;
    309 	sy = my = m->wy + oh;
    310 	mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
    311 	sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
    312 	sw = mw = m->ww - 2*ov;
    313 
    314 	if (m->nmaster && n > m->nmaster) {
    315 		sw = (mw - iv) * (1 - m->mfact);
    316 		mw = mw - iv - sw;
    317 		sx = mx + mw + iv;
    318 	}
    319 
    320 	getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
    321 
    322 	for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
    323 		if (i < m->nmaster) {
    324 			resize(c, mx, my, mw - (2*c->bw),
    325 			       (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
    326 			my += HEIGHT(c) + ih;
    327 		} else {
    328 			resize(c, sx, sy, sw - (2*c->bw),
    329 			       (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
    330 			sy += HEIGHT(c) + ih;
    331 		}
    332 }