nmaster.c (7346B)
1 #if 0 2 3 TITLE 4 5 subject: ntile/nmaster/tilecols layouts with cpt patch included for dwm-4.6 6 author: pancake <youterm.com> * 7 8 9 NOTES 10 11 Remember to append a ISTILE line like that one in your config.h: 12 13 #define ISTILE isarrange(tile) || isarrange(ntile) || isarrange(dntile) || isarrange(tilecols) 14 15 16 INSTALLATION 17 18 Copy this file into the dwm root directory (the one) and follow the instructions 19 related into the configuration section. 20 21 22 CONFIGURATION 23 24 You should modify your config.h to include "nmaster.c" from it after 25 setting the NMASTER, NCOLS and NROWS macro definitions. 26 27 28 *** NMASTER *** 29 30 #define NMASTER 1 31 #include "nmaster.c" 32 33 Layout layouts[] = { 34 { "-|=", ntile }, /* first entry is default */ 35 .. 36 { MODKEY|ShiftMask, XK_j, setnmaster, "+1"}, \ 37 { MODKEY|ShiftMask, XK_k, setnmaster, "-1"}, \ 38 39 40 41 *** TILECOLS *** 42 43 #define NCOLS 2 44 #define NROWS 1 45 #include "nmaster.c" 46 47 Layout layouts[] = { 48 { "E|]", tilecols }, /* first entry is default */ 49 .. 50 { MODKEY|ShiftMask, XK_j, setnrows, "+1" }, \ 51 { MODKEY|ShiftMask, XK_k, setnrows, "-1" }, \ 52 { MODKEY|ShiftMask, XK_l, setncols, "+1" }, \ 53 { MODKEY|ShiftMask, XK_h, setncols, "-1" }, \ 54 55 56 *** CLIENTS PER TAG *** 57 58 Valid values are: 59 -1 - show all clients 60 0 - show no clients 61 >0 - show N clients 62 63 Example configuration: 64 { MODKEY|ShiftMask, XK_q, clientspertag, "0" }, \ 65 { MODKEY, XK_q, clientspertag, "^1" }, \ 66 { MODKEY, XK_w, clientspertag, "^2" }, \ 67 { MODKEY, XK_e, clientspertag, "^3" }, \ 68 69 #endif 70 71 int cpt = -1; 72 void clientspertag(const char *arg) { 73 if (arg[0]=='^') { 74 if (cpt==-1) cpt = atoi(arg+1); 75 else cpt = -1; 76 } else cpt = atoi(arg); 77 arrange(); 78 } 79 80 #ifdef NMASTER 81 int nmaster = NMASTER; 82 void 83 ntile(void) { 84 unsigned int i, n, nx, ny, nw, nh, mw, mh, th; 85 Client *c; 86 87 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 88 n++; 89 90 if (cpt!=-1 && n>cpt) n = cpt; 91 92 /* window geoms */ 93 mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster; 94 mw = (n <= nmaster) ? waw : mwfact * waw; 95 th = (n > nmaster) ? wah / (n - nmaster) : 0; 96 if(n > nmaster && th < bh) 97 th = wah; 98 99 nx = wax; 100 ny = way; 101 for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) { 102 if (cpt!=-1 && i>=cpt) { 103 ban(c); 104 continue; 105 } 106 c->ismax = False; 107 if(i < nmaster) { /* master */ 108 ny = way + i * mh; 109 nw = mw - 2 * c->border; 110 nh = mh; 111 if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ 112 nh = wah - mh * i; 113 nh -= 2 * c->border; 114 } 115 else { /* tile window */ 116 if(i == nmaster) { 117 ny = way; 118 nx += mw; 119 } 120 nw = waw - mw - 2 * c->border; 121 if(i + 1 == n) /* remainder */ 122 nh = (way + wah) - ny - 2 * c->border; 123 else 124 nh = th - 2 * c->border; 125 } 126 resize(c, nx, ny, nw, nh, False); 127 if(n > nmaster && th != wah) 128 ny += nh + 2 * c->border; 129 } 130 } 131 132 void 133 dntile(void) { 134 unsigned int i, n, nx, ny, nw, nh, mw, mh, th, inc; 135 Client *c; 136 137 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 138 n++; 139 if (cpt!=-1 && n>cpt) n = cpt; 140 141 /* dynamic nmaster */ 142 if (n<5) inc = 0; 143 else if (n<7) inc = 1; 144 else inc = 2; 145 nmaster+=inc; 146 147 /* window geoms */ 148 mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster; 149 mw = (n <= nmaster) ? waw : mwfact * waw; 150 th = (n > nmaster) ? wah / (n - nmaster) : 0; 151 if(n > nmaster && th < bh) 152 th = wah; 153 154 nx = wax; 155 ny = way; 156 for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) { 157 if (cpt!=-1 && i>=cpt) { 158 ban(c); 159 continue; 160 } 161 c->ismax = False; 162 if(i < nmaster) { /* master */ 163 ny = way + i * mh; 164 nw = mw - 2 * c->border; 165 nh = mh; 166 if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ 167 nh = wah - mh * i; 168 nh -= 2 * c->border; 169 } 170 else { /* tile window */ 171 if(i == nmaster) { 172 ny = way; 173 nx += mw; 174 } 175 nw = waw - mw - 2 * c->border; 176 if(i + 1 == n) /* remainder */ 177 nh = (way + wah) - ny - 2 * c->border; 178 else 179 nh = th - 2 * c->border; 180 } 181 resize(c, nx, ny, nw, nh, False); 182 if(n > nmaster && th != wah) 183 ny += nh + 2 * c->border; 184 } 185 nmaster-=inc; 186 } 187 188 void 189 setnmaster(const char *arg) { 190 int i; 191 192 if(!isarrange(ntile)&&!isarrange(dntile)) 193 return; 194 if(!arg) 195 nmaster = NMASTER; 196 else { 197 i = atoi(arg); 198 if((nmaster + i) < 1 || wah / (nmaster + i) <= 2 * BORDERPX) 199 return; 200 nmaster += i; 201 } 202 if(sel) 203 arrange(); 204 } 205 #endif 206 207 #ifdef NCOLS 208 #ifdef NROWS 209 unsigned int ncols = NCOLS; 210 unsigned int nrows = NROWS; 211 212 void 213 setncols(const char *arg) { 214 int i; 215 216 if(!isarrange(tile)) 217 return; 218 if(!arg) 219 i = NCOLS; 220 else if(arg[0] != '+' && arg[0] != '-') 221 i = atoi(arg); 222 else 223 i = ncols + atoi(arg); 224 225 if((i < 1) || (i >= 1 && waw / i <= 2 * BORDERPX)) 226 return; 227 ncols = i; 228 229 if(sel) 230 arrange(); 231 } 232 233 void 234 setnrows(const char *arg) { 235 int i; 236 237 if(!isarrange(tile)) 238 return; 239 if(!arg) 240 i = NROWS; 241 else if(arg[0] != '+' && arg[0] != '-') 242 i = atoi(arg); 243 else 244 i = nrows + atoi(arg); 245 246 if(i < 1 || wah <= 2 * BORDERPX * i) 247 return; 248 nrows = i; 249 250 if(sel) 251 arrange(); 252 } 253 254 void 255 tilecols(void) { 256 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th, tw1, cols, rows, rows1; 257 Client *c; 258 259 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 260 n++; 261 /* calculate correct number of rows */ 262 if(ncols > 0 && n - nmaster > nrows * ncols) 263 rows = (n - nmaster) / ncols + ((n - nmaster) % ncols ? 1 : 0); 264 else 265 rows = nrows; 266 267 if (cpt!=-1 && n>cpt) n = cpt; 268 269 /* window geoms */ 270 mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster; 271 272 if (nmaster == 0) { 273 mh = mw = 0; 274 } 275 else if (n <= nmaster) { 276 mh = wah / (n > 0 ? n : 1); 277 mw = waw; 278 } 279 else { 280 mh = wah / nmaster; 281 mw = mwfact * waw; 282 } 283 284 if(rows == 0 || n <= nmaster + rows) { 285 rows1 = n > nmaster ? n - nmaster : 1; 286 tw = tw1 = waw - mw; 287 th = wah / rows1; 288 } 289 else { 290 rows1 = 1 + (n - nmaster - 1) % rows; 291 cols = (n - nmaster) / rows + ((n - nmaster) % rows ? 1 : 0); 292 tw = (waw - mw) / cols; 293 tw1 = waw - mw - (cols - 1) * tw; 294 th = wah / rows; 295 } 296 297 nx = wax; 298 ny = way; 299 300 for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) { 301 if (cpt!=-1 && i>=cpt) { 302 ban(c); 303 continue; 304 } 305 c->ismax = False; 306 if(i < nmaster) { /* master column */ 307 ny = way + i * mh; 308 nw = mw - 2 * c->border; 309 nh = mh - 2 * c->border; 310 if(i == 0) 311 nh += wah - mh * (n < nmaster ? n : nmaster); 312 //nh = mh; 313 if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ 314 nh = wah - mh * i; 315 nh -= 2 * c->border; 316 } 317 else if(i < nmaster + rows1) { /* first stack column */ 318 if(i == nmaster) { /* initialise */ 319 ny = way; 320 nx += mw; 321 nh = wah - 2*c->border - (rows1 - 1) * th; 322 } else 323 nh = th - 2 * c->border; 324 nw = tw1 - 2 * c->border; 325 } 326 else { /* successive stack columns - rows > 0 if we reach here */ 327 if((i - nmaster - rows1) % rows == 0) { /* reinitialise */ 328 ny = way; 329 nx += nw + 2 * c-> border; 330 nh = wah - 2*c->border - (rows - 1) * th; 331 } 332 else { 333 nh = th - 2 * c->border; 334 } 335 nw = tw - 2 * c->border; 336 } 337 resize(c, nx, ny, nw, nh, False); 338 ny += nh + 2 * c->border; 339 } 340 } 341 #endif 342 #endif 343