nmaster-sym.c (2786B)
1 enum {MaxMon = 8}; 2 static int nmasters[MaxMon]; 3 static int initnm = 0; 4 5 static void 6 initnmaster(void) { 7 int i; 8 9 if(initnm) 10 return; 11 for(i = 0; i < MaxMon; i++) 12 nmasters[i] = nmaster; 13 initnm = 1; 14 } 15 16 static void 17 incnmaster(const Arg *arg) { 18 if(!arg || !selmon->lt[selmon->sellt]->arrange || selmon->num >= MaxMon) 19 return; 20 nmasters[selmon->num] += arg->i; 21 if(nmasters[selmon->num] < 0) 22 nmasters[selmon->num] = 0; 23 arrange(selmon); 24 } 25 26 static void 27 setnmaster(const Arg *arg) { 28 if(!arg || !selmon->lt[selmon->sellt]->arrange || selmon->num >= MaxMon) 29 return; 30 nmasters[selmon->num] = arg->i > 0 ? arg->i : 0; 31 arrange(selmon); 32 } 33 34 static void 35 ntile(Monitor *m) { 36 int x, y, h, w, mw, nm; 37 unsigned int i, n; 38 Client *c; 39 40 initnmaster(); 41 /* override layout symbol */ 42 snprintf(m->ltsymbol, sizeof m->ltsymbol, "%d]=", nmasters[m->num]); 43 for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 44 c = nexttiled(m->clients); 45 nm = m->num < MaxMon ? nmasters[m->num] : nmaster; 46 if(nm > n) 47 nm = n; 48 /* master */ 49 if(nm > 0) { 50 mw = m->mfact * m->ww; 51 h = m->wh / nm; 52 if(h < bh) 53 h = m->wh; 54 y = m->wy; 55 for(i = 0; i < nm; i++, c = nexttiled(c->next)) { 56 resize(c, m->wx, y, (n == nm ? m->ww : mw) - 2 * c->bw, 57 ((i + 1 == nm) ? m->wy + m->wh - y : h) - 2 * c->bw, False); 58 if(h != m->wh) 59 y = c->y + HEIGHT(c); 60 } 61 n -= nm; 62 } else 63 mw = 0; 64 if(n == 0) 65 return; 66 /* tile stack */ 67 x = m->wx + mw; 68 y = m->wy; 69 w = m->ww - mw; 70 h = m->wh / n; 71 if(h < bh) 72 h = m->wh; 73 for(i = 0; c; c = nexttiled(c->next), i++) { 74 resize(c, x, y, w - 2 * c->bw, 75 ((i + 1 == n) ? m->wy + m->wh - y : h) - 2 * c->bw, False); 76 if(h != m->wh) 77 y = c->y + HEIGHT(c); 78 } 79 } 80 81 static void 82 nbstack(Monitor *m) { 83 int x, y, h, w, mh, nm; 84 unsigned int i, n; 85 Client *c; 86 87 initnmaster(); 88 /* override layout symbol */ 89 snprintf(m->ltsymbol, sizeof m->ltsymbol, "T%dT", nmasters[m->num]); 90 for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 91 c = nexttiled(m->clients); 92 nm = m->num < MaxMon ? nmasters[m->num] : nmaster; 93 if(nm > n) 94 nm = n; 95 /* master */ 96 if(nm > 0) { 97 mh = m->mfact * m->wh; 98 w = m->ww / nm; 99 if(w < bh) 100 w = m->ww; 101 x = m->wx; 102 for(i = 0; i < nm; i++, c = nexttiled(c->next)) { 103 resize(c, x, m->wy, ((i + 1 == nm) ? m->wx + m->ww - x : w) - 2 * c->bw, 104 (n == nm ? m->wh : mh) - 2 * c->bw, False); 105 if(w != m->ww) 106 x = c->x + WIDTH(c); 107 } 108 n -= nm; 109 } else 110 mh = 0; 111 if(n == 0) 112 return; 113 /* tile stack */ 114 x = m->wx; 115 y = m->wy + mh; 116 w = m->ww / n; 117 h = m->wh - mh; 118 if(w < bh) 119 w = m->ww; 120 for(i = 0; c; c = nexttiled(c->next), i++) { 121 resize(c, x, y, ((i + 1 == n) ? m->wx + m->ww - x : w) - 2 * c->bw, 122 h - 2 * c->bw, False); 123 if(w != m->ww) 124 x = c->x + WIDTH(c); 125 } 126 }