nmaster.c - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
nmaster.c (2574B)
---
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();
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();
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 for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
42 c = nexttiled(m->clients);
43 nm = m->num < MaxMon ? nmasters[m->num] : nmaster;
44 if(nm > n)
45 nm = n;
46 /* master */
47 if(nm > 0) {
48 mw = m->mfact * m->ww;
49 h = m->wh / nm;
50 if(h < bh)
51 h = m->wh;
52 y = m->wy;
53 for(i = 0; i < nm; i++, c = nexttiled(c->next)) {
54 resize(c, m->wx, y, (n == nm ? m->ww : mw) - 2 * c->bw,
55 ((i + 1 == nm) ? m->wy + m->wh - y : h) - 2 * c->bw, False);
56 if(h != m->wh)
57 y = c->y + HEIGHT(c);
58 }
59 n -= nm;
60 } else
61 mw = 0;
62 if(n == 0)
63 return;
64 /* tile stack */
65 x = m->wx + mw;
66 y = m->wy;
67 w = m->ww - mw;
68 h = m->wh / n;
69 if(h < bh)
70 h = m->wh;
71 for(i = 0; c; c = nexttiled(c->next), i++) {
72 resize(c, x, y, w - 2 * c->bw,
73 ((i + 1 == n) ? m->wy + m->wh - y : h) - 2 * c->bw, False);
74 if(h != m->wh)
75 y = c->y + HEIGHT(c);
76 }
77 }
78
79 static void
80 nbstack(Monitor *m) {
81 int x, y, h, w, mh, nm;
82 unsigned int i, n;
83 Client *c;
84
85 initnmaster();
86 for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
87 c = nexttiled(m->clients);
88 nm = m->num < MaxMon ? nmasters[m->num] : nmaster;
89 if(nm > n)
90 nm = n;
91 /* master */
92 if(nm > 0) {
93 mh = m->mfact * m->wh;
94 w = m->ww / nm;
95 if(w < bh)
96 w = m->ww;
97 x = m->wx;
98 for(i = 0; i < nm; i++, c = nexttiled(c->next)) {
99 resize(c, x, m->wy, ((i + 1 == nm) ? m->wx + m->ww - x : w) - 2 * c->bw,
100 (n == nm ? m->wh : mh) - 2 * c->bw, False);
101 if(w != m->ww)
102 x = c->x + WIDTH(c);
103 }
104 n -= nm;
105 } else
106 mh = 0;
107 if(n == 0)
108 return;
109 /* tile stack */
110 x = m->wx;
111 y = m->wy + mh;
112 w = m->ww / n;
113 h = m->wh - mh;
114 if(w < bh)
115 w = m->ww;
116 for(i = 0; c; c = nexttiled(c->next), i++) {
117 resize(c, x, y, ((i + 1 == n) ? m->wx + m->ww - x : w) - 2 * c->bw,
118 h - 2 * c->bw, False);
119 if(w != m->ww)
120 x = c->x + WIDTH(c);
121 }
122 }