summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--client.c61
-rw-r--r--dwm.h22
-rw-r--r--tag.c186
-rw-r--r--view.c253
5 files changed, 266 insertions, 258 deletions
diff --git a/Makefile b/Makefile
index 066643e..ad8ec08 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = client.c draw.c event.c main.c tag.c util.c 6SRC = client.c draw.c event.c main.c tag.c util.c view.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/client.c b/client.c
index eb23452..af0190f 100644
--- a/client.c
+++ b/client.c
@@ -89,40 +89,6 @@ focus(Client *c)
89 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 89 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
90} 90}
91 91
92void
93focusnext(Arg *arg)
94{
95 Client *c;
96
97 if(!sel)
98 return;
99
100 if(!(c = getnext(sel->next)))
101 c = getnext(clients);
102 if(c) {
103 focus(c);
104 restack();
105 }
106}
107
108void
109focusprev(Arg *arg)
110{
111 Client *c;
112
113 if(!sel)
114 return;
115
116 if(!(c = getprev(sel->prev))) {
117 for(c = clients; c && c->next; c = c->next);
118 c = getprev(c);
119 }
120 if(c) {
121 focus(c);
122 restack();
123 }
124}
125
126Client * 92Client *
127getclient(Window w) 93getclient(Window w)
128{ 94{
@@ -446,30 +412,3 @@ unmanage(Client *c)
446 focus(sel); 412 focus(sel);
447 arrange(NULL); 413 arrange(NULL);
448} 414}
449
450void
451zoom(Arg *arg)
452{
453 Client *c;
454
455 if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
456 return;
457
458 if(sel == getnext(clients)) {
459 if((c = getnext(sel->next)))
460 sel = c;
461 else
462 return;
463 }
464
465 /* pop */
466 sel->prev->next = sel->next;
467 if(sel->next)
468 sel->next->prev = sel->prev;
469 sel->prev = NULL;
470 clients->prev = sel;
471 sel->next = clients;
472 clients = sel;
473 focus(sel);
474 arrange(NULL);
475}
diff --git a/dwm.h b/dwm.h
index c4594fc..b96facd 100644
--- a/dwm.h
+++ b/dwm.h
@@ -84,8 +84,6 @@ extern Window root, barwin;
84/* client.c */ 84/* client.c */
85extern void ban(Client *c); 85extern void ban(Client *c);
86extern void focus(Client *c); 86extern void focus(Client *c);
87extern void focusnext(Arg *arg);
88extern void focusprev(Arg *arg);
89extern Client *getclient(Window w); 87extern Client *getclient(Window w);
90extern Client *getctitle(Window w); 88extern Client *getctitle(Window w);
91extern void gravitate(Client *c, Bool invert); 89extern void gravitate(Client *c, Bool invert);
@@ -96,7 +94,6 @@ extern void setsize(Client *c);
96extern void settitle(Client *c); 94extern void settitle(Client *c);
97extern void togglemax(Arg *arg); 95extern void togglemax(Arg *arg);
98extern void unmanage(Client *c); 96extern void unmanage(Client *c);
99extern void zoom(Arg *arg);
100 97
101/* draw.c */ 98/* draw.c */
102extern void drawall(); 99extern void drawall();
@@ -117,22 +114,27 @@ extern void sendevent(Window w, Atom a, long value);
117extern int xerror(Display *dsply, XErrorEvent *ee); 114extern int xerror(Display *dsply, XErrorEvent *ee);
118 115
119/* tag.c */ 116/* tag.c */
120extern void dofloat(Arg *arg);
121extern void dotile(Arg *arg);
122extern void initrregs(); 117extern void initrregs();
123extern Bool isvisible(Client *c);
124extern Client *getnext(Client *c); 118extern Client *getnext(Client *c);
125extern Client *getprev(Client *c); 119extern Client *getprev(Client *c);
126extern void restack();
127extern void settags(Client *c); 120extern void settags(Client *c);
128extern void tag(Arg *arg); 121extern void tag(Arg *arg);
129extern void togglemode(Arg *arg);
130extern void toggletag(Arg *arg); 122extern void toggletag(Arg *arg);
131extern void toggleview(Arg *arg);
132extern void view(Arg *arg);
133 123
134/* util.c */ 124/* util.c */
135extern void *emallocz(unsigned int size); 125extern void *emallocz(unsigned int size);
136extern void eprint(const char *errstr, ...); 126extern void eprint(const char *errstr, ...);
137extern void *erealloc(void *ptr, unsigned int size); 127extern void *erealloc(void *ptr, unsigned int size);
138extern void spawn(Arg *arg); 128extern void spawn(Arg *arg);
129
130/* view.c */
131extern void dofloat(Arg *arg);
132extern void dotile(Arg *arg);
133extern void focusnext(Arg *arg);
134extern void focusprev(Arg *arg);
135extern Bool isvisible(Client *c);
136extern void restack();
137extern void togglemode(Arg *arg);
138extern void toggleview(Arg *arg);
139extern void view(Arg *arg);
140extern void zoom(Arg *arg);
diff --git a/tag.c b/tag.c
index cdb0f52..bc36f08 100644
--- a/tag.c
+++ b/tag.c
@@ -30,97 +30,8 @@ RULES
30static RReg *rreg = NULL; 30static RReg *rreg = NULL;
31static unsigned int len = 0; 31static unsigned int len = 0;
32 32
33void (*arrange)(Arg *) = DEFMODE;
34
35/* extern */ 33/* extern */
36 34
37void
38dofloat(Arg *arg)
39{
40 Client *c;
41
42 for(c = clients; c; c = c->next) {
43 c->ismax = False;
44 if(isvisible(c)) {
45 resize(c, True, TopLeft);
46 }
47 else
48 ban(c);
49 }
50 if(!sel || !isvisible(sel))
51 sel = getnext(clients);
52 if(sel)
53 focus(sel);
54 else
55 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
56 restack();
57}
58
59void
60dotile(Arg *arg)
61{
62 int h, i, n, w;
63 Client *c;
64
65 w = sw - mw;
66 for(n = 0, c = clients; c; c = c->next)
67 if(isvisible(c) && !c->isfloat)
68 n++;
69
70 if(n > 1)
71 h = (sh - bh) / (n - 1);
72 else
73 h = sh - bh;
74
75 for(i = 0, c = clients; c; c = c->next) {
76 c->ismax = False;
77 if(isvisible(c)) {
78 if(c->isfloat) {
79 resize(c, True, TopLeft);
80 continue;
81 }
82 if(n == 1) {
83 c->x = sx;
84 c->y = sy + bh;
85 c->w = sw - 2;
86 c->h = sh - 2 - bh;
87 }
88 else if(i == 0) {
89 c->x = sx;
90 c->y = sy + bh;
91 c->w = mw - 2;
92 c->h = sh - 2 - bh;
93 }
94 else if(h > bh) {
95 c->x = sx + mw;
96 c->y = sy + (i - 1) * h + bh;
97 c->w = w - 2;
98 if(i + 1 == n)
99 c->h = sh - c->y - 2;
100 else
101 c->h = h - 2;
102 }
103 else { /* fallback if h < bh */
104 c->x = sx + mw;
105 c->y = sy + bh;
106 c->w = w - 2;
107 c->h = sh - 2 - bh;
108 }
109 resize(c, False, TopLeft);
110 i++;
111 }
112 else
113 ban(c);
114 }
115 if(!sel || !isvisible(sel))
116 sel = getnext(clients);
117 if(sel)
118 focus(sel);
119 else
120 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
121 restack();
122}
123
124Client * 35Client *
125getnext(Client *c) 36getnext(Client *c)
126{ 37{
@@ -164,69 +75,6 @@ initrregs()
164 } 75 }
165} 76}
166 77
167Bool
168isvisible(Client *c)
169{
170 unsigned int i;
171
172 for(i = 0; i < ntags; i++)
173 if(c->tags[i] && seltag[i])
174 return True;
175 return False;
176}
177
178void
179restack()
180{
181 static unsigned int nwins = 0;
182 static Window *wins = NULL;
183 unsigned int f, fi, m, mi, n;
184 Client *c;
185 XEvent ev;
186
187 for(f = 0, m = 0, c = clients; c; c = c->next)
188 if(isvisible(c)) {
189 if(c->isfloat || arrange == dofloat)
190 f++;
191 else
192 m++;
193 }
194 if(!(n = 2 * (f + m))) {
195 drawstatus();
196 return;
197 }
198 if(nwins < n) {
199 nwins = n;
200 wins = erealloc(wins, nwins * sizeof(Window));
201 }
202
203 fi = 0;
204 mi = 2 * f;
205 if(sel->isfloat || arrange == dofloat) {
206 wins[fi++] = sel->title;
207 wins[fi++] = sel->win;
208 }
209 else {
210 wins[mi++] = sel->title;
211 wins[mi++] = sel->win;
212 }
213 for(c = clients; c; c = c->next)
214 if(isvisible(c) && c != sel) {
215 if(c->isfloat || arrange == dofloat) {
216 wins[fi++] = c->title;
217 wins[fi++] = c->win;
218 }
219 else {
220 wins[mi++] = c->title;
221 wins[mi++] = c->win;
222 }
223 }
224 XRestackWindows(dpy, wins, n);
225 drawall();
226 XSync(dpy, False);
227 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
228}
229
230void 78void
231settags(Client *c) 79settags(Client *c)
232{ 80{
@@ -277,16 +125,6 @@ tag(Arg *arg)
277} 125}
278 126
279void 127void
280togglemode(Arg *arg)
281{
282 arrange = arrange == dofloat ? dotile : dofloat;
283 if(sel)
284 arrange(NULL);
285 else
286 drawstatus();
287}
288
289void
290toggletag(Arg *arg) 128toggletag(Arg *arg)
291{ 129{
292 unsigned int i; 130 unsigned int i;
@@ -302,27 +140,3 @@ toggletag(Arg *arg)
302 if(!isvisible(sel)) 140 if(!isvisible(sel))
303 arrange(NULL); 141 arrange(NULL);
304} 142}
305
306
307void
308toggleview(Arg *arg)
309{
310 unsigned int i;
311
312 seltag[arg->i] = !seltag[arg->i];
313 for(i = 0; i < ntags && !seltag[i]; i++);
314 if(i == ntags)
315 seltag[arg->i] = True; /* cannot toggle last view */
316 arrange(NULL);
317}
318
319void
320view(Arg *arg)
321{
322 unsigned int i;
323
324 for(i = 0; i < ntags; i++)
325 seltag[i] = False;
326 seltag[arg->i] = True;
327 arrange(NULL);
328}
diff --git a/view.c b/view.c
new file mode 100644
index 0000000..d9aa6e4
--- /dev/null
+++ b/view.c
@@ -0,0 +1,253 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5#include "dwm.h"
6
7/* extern */
8
9void (*arrange)(Arg *) = DEFMODE;
10
11void
12dofloat(Arg *arg)
13{
14 Client *c;
15
16 for(c = clients; c; c = c->next) {
17 c->ismax = False;
18 if(isvisible(c)) {
19 resize(c, True, TopLeft);
20 }
21 else
22 ban(c);
23 }
24 if(!sel || !isvisible(sel))
25 sel = getnext(clients);
26 if(sel)
27 focus(sel);
28 else
29 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
30 restack();
31}
32
33void
34dotile(Arg *arg)
35{
36 int h, i, n, w;
37 Client *c;
38
39 w = sw - mw;
40 for(n = 0, c = clients; c; c = c->next)
41 if(isvisible(c) && !c->isfloat)
42 n++;
43
44 if(n > 1)
45 h = (sh - bh) / (n - 1);
46 else
47 h = sh - bh;
48
49 for(i = 0, c = clients; c; c = c->next) {
50 c->ismax = False;
51 if(isvisible(c)) {
52 if(c->isfloat) {
53 resize(c, True, TopLeft);
54 continue;
55 }
56 if(n == 1) {
57 c->x = sx;
58 c->y = sy + bh;
59 c->w = sw - 2;
60 c->h = sh - 2 - bh;
61 }
62 else if(i == 0) {
63 c->x = sx;
64 c->y = sy + bh;
65 c->w = mw - 2;
66 c->h = sh - 2 - bh;
67 }
68 else if(h > bh) {
69 c->x = sx + mw;
70 c->y = sy + (i - 1) * h + bh;
71 c->w = w - 2;
72 if(i + 1 == n)
73 c->h = sh - c->y - 2;
74 else
75 c->h = h - 2;
76 }
77 else { /* fallback if h < bh */
78 c->x = sx + mw;
79 c->y = sy + bh;
80 c->w = w - 2;
81 c->h = sh - 2 - bh;
82 }
83 resize(c, False, TopLeft);
84 i++;
85 }
86 else
87 ban(c);
88 }
89 if(!sel || !isvisible(sel))
90 sel = getnext(clients);
91 if(sel)
92 focus(sel);
93 else
94 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
95 restack();
96}
97
98void
99focusnext(Arg *arg)
100{
101 Client *c;
102
103 if(!sel)
104 return;
105
106 if(!(c = getnext(sel->next)))
107 c = getnext(clients);
108 if(c) {
109 focus(c);
110 restack();
111 }
112}
113
114void
115focusprev(Arg *arg)
116{
117 Client *c;
118
119 if(!sel)
120 return;
121
122 if(!(c = getprev(sel->prev))) {
123 for(c = clients; c && c->next; c = c->next);
124 c = getprev(c);
125 }
126 if(c) {
127 focus(c);
128 restack();
129 }
130}
131
132Bool
133isvisible(Client *c)
134{
135 unsigned int i;
136
137 for(i = 0; i < ntags; i++)
138 if(c->tags[i] && seltag[i])
139 return True;
140 return False;
141}
142
143void
144restack()
145{
146 static unsigned int nwins = 0;
147 static Window *wins = NULL;
148 unsigned int f, fi, m, mi, n;
149 Client *c;
150 XEvent ev;
151
152 for(f = 0, m = 0, c = clients; c; c = c->next)
153 if(isvisible(c)) {
154 if(c->isfloat || arrange == dofloat)
155 f++;
156 else
157 m++;
158 }
159 if(!(n = 2 * (f + m))) {
160 drawstatus();
161 return;
162 }
163 if(nwins < n) {
164 nwins = n;
165 wins = erealloc(wins, nwins * sizeof(Window));
166 }
167
168 fi = 0;
169 mi = 2 * f;
170 if(sel->isfloat || arrange == dofloat) {
171 wins[fi++] = sel->title;
172 wins[fi++] = sel->win;
173 }
174 else {
175 wins[mi++] = sel->title;
176 wins[mi++] = sel->win;
177 }
178 for(c = clients; c; c = c->next)
179 if(isvisible(c) && c != sel) {
180 if(c->isfloat || arrange == dofloat) {
181 wins[fi++] = c->title;
182 wins[fi++] = c->win;
183 }
184 else {
185 wins[mi++] = c->title;
186 wins[mi++] = c->win;
187 }
188 }
189 XRestackWindows(dpy, wins, n);
190 drawall();
191 XSync(dpy, False);
192 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
193}
194
195void
196togglemode(Arg *arg)
197{
198 arrange = arrange == dofloat ? dotile : dofloat;
199 if(sel)
200 arrange(NULL);
201 else
202 drawstatus();
203}
204
205void
206toggleview(Arg *arg)
207{
208 unsigned int i;
209
210 seltag[arg->i] = !seltag[arg->i];
211 for(i = 0; i < ntags && !seltag[i]; i++);
212 if(i == ntags)
213 seltag[arg->i] = True; /* cannot toggle last view */
214 arrange(NULL);
215}
216
217void
218view(Arg *arg)
219{
220 unsigned int i;
221
222 for(i = 0; i < ntags; i++)
223 seltag[i] = False;
224 seltag[arg->i] = True;
225 arrange(NULL);
226}
227
228void
229zoom(Arg *arg)
230{
231 Client *c;
232
233 if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
234 return;
235
236 if(sel == getnext(clients)) {
237 if((c = getnext(sel->next)))
238 sel = c;
239 else
240 return;
241 }
242
243 /* pop */
244 sel->prev->next = sel->next;
245 if(sel->next)
246 sel->next->prev = sel->prev;
247 sel->prev = NULL;
248 clients->prev = sel;
249 sel->next = clients;
250 clients = sel;
251 focus(sel);
252 arrange(NULL);
253}