dwm

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

layouts.c (8291B)


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