summaryrefslogtreecommitdiffstats
path: root/view.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
commit5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63 (patch)
tree2025c7842831bd512df4816717e5e47160f99f7c /view.c
parentsimplified configurerequest to a bare minimum, removed wrong ban() calls (diff)
downloaddwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.tar.gz
dwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.zip
introduced tile.c, some refactoring of functions
Diffstat (limited to 'view.c')
-rw-r--r--view.c136
1 files changed, 5 insertions, 131 deletions
diff --git a/view.c b/view.c
index 66f550c..72aa04e 100644
--- a/view.c
+++ b/view.c
@@ -2,34 +2,6 @@
2 * See LICENSE file for license details. 2 * See LICENSE file for license details.
3 */ 3 */
4#include "dwm.h" 4#include "dwm.h"
5#include <stdio.h>
6
7/* static */
8
9static Client *
10nexttiled(Client *c) {
11 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
12 return c;
13}
14
15static void
16togglemax(Client *c) {
17 XEvent ev;
18
19 if(c->isfixed)
20 return;
21
22 if((c->ismax = !c->ismax)) {
23 c->rx = c->x;
24 c->ry = c->y;
25 c->rw = c->w;
26 c->rh = c->h;
27 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
28 }
29 else
30 resize(c, c->rx, c->ry, c->rw, c->rh, True);
31 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
32}
33 5
34/* extern */ 6/* extern */
35 7
@@ -70,58 +42,6 @@ dofloat(void) {
70} 42}
71 43
72void 44void
73dotile(void) {
74 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
75 Client *c;
76
77 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
78 n++;
79 /* window geoms */
80 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
81 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
82 th = (n > nmaster) ? wah / (n - nmaster) : 0;
83 tw = waw - mw;
84
85 for(i = 0, c = clients; c; c = c->next)
86 if(isvisible(c)) {
87 if(c->isbanned)
88 XMoveWindow(dpy, c->win, c->x, c->y);
89 c->isbanned = False;
90 if(c->isfloat)
91 continue;
92 c->ismax = False;
93 nx = wax;
94 ny = way;
95 if(i < nmaster) {
96 ny += i * mh;
97 nw = mw - 2 * BORDERPX;
98 nh = mh - 2 * BORDERPX;
99 }
100 else { /* tile window */
101 nx += mw;
102 nw = tw - 2 * BORDERPX;
103 if(th > 2 * BORDERPX) {
104 ny += (i - nmaster) * th;
105 nh = th - 2 * BORDERPX;
106 }
107 else /* fallback if th <= 2 * BORDERPX */
108 nh = wah - 2 * BORDERPX;
109 }
110 resize(c, nx, ny, nw, nh, False);
111 i++;
112 }
113 else {
114 c->isbanned = True;
115 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
116 }
117 if(!sel || !isvisible(sel)) {
118 for(c = stack; c && !isvisible(c); c = c->snext);
119 focus(c);
120 }
121 restack();
122}
123
124void
125focusnext(Arg *arg) { 45focusnext(Arg *arg) {
126 Client *c; 46 Client *c;
127 47
@@ -153,18 +73,6 @@ focusprev(Arg *arg) {
153 } 73 }
154} 74}
155 75
156void
157incnmaster(Arg *arg) {
158 if((arrange == dofloat) || (nmaster + arg->i < 1)
159 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
160 return;
161 nmaster += arg->i;
162 if(sel)
163 arrange();
164 else
165 drawstatus();
166}
167
168Bool 76Bool
169isvisible(Client *c) { 77isvisible(Client *c) {
170 unsigned int i; 78 unsigned int i;
@@ -175,19 +83,10 @@ isvisible(Client *c) {
175 return False; 83 return False;
176} 84}
177 85
178void 86Client *
179resizemaster(Arg *arg) { 87nextmanaged(Client *c) {
180 if(arrange != dotile) 88 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
181 return; 89 return c;
182 if(arg->i == 0)
183 master = MASTER;
184 else {
185 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
186 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
187 return;
188 master += arg->i;
189 }
190 arrange();
191} 90}
192 91
193void 92void
@@ -203,7 +102,7 @@ restack(void) {
203 if(arrange != dofloat) { 102 if(arrange != dofloat) {
204 if(!sel->isfloat) 103 if(!sel->isfloat)
205 XLowerWindow(dpy, sel->win); 104 XLowerWindow(dpy, sel->win);
206 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { 105 for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
207 if(c == sel) 106 if(c == sel)
208 continue; 107 continue;
209 XLowerWindow(dpy, c->win); 108 XLowerWindow(dpy, c->win);
@@ -252,28 +151,3 @@ view(Arg *arg) {
252 arrange(); 151 arrange();
253} 152}
254 153
255void
256zoom(Arg *arg) {
257 unsigned int n;
258 Client *c;
259
260 if(!sel)
261 return;
262 if(sel->isfloat || (arrange == dofloat)) {
263 togglemax(sel);
264 return;
265 }
266 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
267 n++;
268
269 if((c = sel) == nexttiled(clients))
270 if(!(c = nexttiled(c->next)))
271 return;
272 detach(c);
273 if(clients)
274 clients->prev = c;
275 c->next = clients;
276 clients = c;
277 focus(c);
278 arrange();
279}