summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c26
-rw-r--r--dwm.14
-rw-r--r--dwm.h3
-rw-r--r--event.c9
-rw-r--r--tag.c64
-rw-r--r--util.c9
6 files changed, 81 insertions, 34 deletions
diff --git a/client.c b/client.c
index 5be438e..ecfd8f0 100644
--- a/client.c
+++ b/client.c
@@ -59,8 +59,6 @@ focus(Client *c)
59 drawtitle(old); 59 drawtitle(old);
60 drawtitle(c); 60 drawtitle(c);
61 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 61 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
62 XSync(dpy, False);
63 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
64} 62}
65 63
66void 64void
@@ -77,8 +75,8 @@ focusnext(Arg *arg)
77 if(!(c = getnext(sel->next))) 75 if(!(c = getnext(sel->next)))
78 c = getnext(clients); 76 c = getnext(clients);
79 if(c) { 77 if(c) {
80 higher(c);
81 focus(c); 78 focus(c);
79 restack();
82 } 80 }
83} 81}
84 82
@@ -98,8 +96,8 @@ focusprev(Arg *arg)
98 c = getprev(c); 96 c = getprev(c);
99 } 97 }
100 if(c) { 98 if(c) {
101 higher(c);
102 focus(c); 99 focus(c);
100 restack();
103 } 101 }
104} 102}
105 103
@@ -181,13 +179,6 @@ gravitate(Client *c, Bool invert)
181} 179}
182 180
183void 181void
184higher(Client *c)
185{
186 XRaiseWindow(dpy, c->win);
187 XRaiseWindow(dpy, c->title);
188}
189
190void
191killclient(Arg *arg) 182killclient(Arg *arg)
192{ 183{
193 if(!sel) 184 if(!sel)
@@ -271,13 +262,12 @@ manage(Window w, XWindowAttributes *wa)
271 || (c->maxw && c->minw && 262 || (c->maxw && c->minw &&
272 c->maxw == c->minw && c->maxh == c->minh); 263 c->maxw == c->minw && c->maxh == c->minh);
273 settitle(c); 264 settitle(c);
274 arrange(NULL);
275 265
276 /* mapping the window now prevents flicker */ 266 XMapWindow(dpy, c->win);
277 XMapRaised(dpy, c->win); 267 XMapWindow(dpy, c->title);
278 XMapRaised(dpy, c->title);
279 if(isvisible(c)) 268 if(isvisible(c))
280 focus(c); 269 focus(c);
270 arrange(NULL);
281} 271}
282 272
283void 273void
@@ -410,7 +400,7 @@ togglemax(Arg *arg)
410 sel->w = sw - 2; 400 sel->w = sw - 2;
411 sel->h = sh - 2 - bh; 401 sel->h = sh - 2 - bh;
412 402
413 higher(sel); 403 restack();
414 resize(sel, arrange == dofloat, TopLeft); 404 resize(sel, arrange == dofloat, TopLeft);
415 405
416 sel->x = ox; 406 sel->x = ox;
@@ -446,9 +436,9 @@ unmanage(Client *c)
446 XSync(dpy, False); 436 XSync(dpy, False);
447 XSetErrorHandler(xerror); 437 XSetErrorHandler(xerror);
448 XUngrabServer(dpy); 438 XUngrabServer(dpy);
449 arrange(NULL);
450 if(sel) 439 if(sel)
451 focus(sel); 440 focus(sel);
441 arrange(NULL);
452} 442}
453 443
454void 444void
@@ -474,6 +464,6 @@ zoom(Arg *arg)
474 clients->prev = sel; 464 clients->prev = sel;
475 sel->next = clients; 465 sel->next = clients;
476 clients = sel; 466 clients = sel;
477 arrange(NULL);
478 focus(sel); 467 focus(sel);
468 arrange(NULL);
479} 469}
diff --git a/dwm.1 b/dwm.1
index 38c50b5..9f0705b 100644
--- a/dwm.1
+++ b/dwm.1
@@ -36,11 +36,11 @@ prints version information to standard output, then exits.
36.B Standard input 36.B Standard input
37is read and displayed in the status text area. 37is read and displayed in the status text area.
38.TP 38.TP
39.B Button[1,3] 39.B Button[1,2]
40click on a tag label focuses that 40click on a tag label focuses that
41.B tag. 41.B tag.
42.TP 42.TP
43.B Button2 43.B Button3
44click on a tag label toggles that 44click on a tag label toggles that
45.B tag. 45.B tag.
46.SS Keyboard commands 46.SS Keyboard commands
diff --git a/dwm.h b/dwm.h
index f9b06d2..c13179f 100644
--- a/dwm.h
+++ b/dwm.h
@@ -89,7 +89,6 @@ extern void focusprev(Arg *arg);
89extern Client *getclient(Window w); 89extern Client *getclient(Window w);
90extern Client *getctitle(Window w); 90extern Client *getctitle(Window w);
91extern void gravitate(Client *c, Bool invert); 91extern void gravitate(Client *c, Bool invert);
92extern void higher(Client *c);
93extern void killclient(Arg *arg); 92extern void killclient(Arg *arg);
94extern void manage(Window w, XWindowAttributes *wa); 93extern void manage(Window w, XWindowAttributes *wa);
95extern void resize(Client *c, Bool sizehints, Corner sticky); 94extern void resize(Client *c, Bool sizehints, Corner sticky);
@@ -125,6 +124,7 @@ extern Bool isvisible(Client *c);
125extern Client *getnext(Client *c); 124extern Client *getnext(Client *c);
126extern Client *getprev(Client *c); 125extern Client *getprev(Client *c);
127extern void replacetag(Arg *arg); 126extern void replacetag(Arg *arg);
127extern void restack();
128extern void settags(Client *c); 128extern void settags(Client *c);
129extern void togglemode(Arg *arg); 129extern void togglemode(Arg *arg);
130extern void view(Arg *arg); 130extern void view(Arg *arg);
@@ -133,4 +133,5 @@ extern void toggleview(Arg *arg);
133/* util.c */ 133/* util.c */
134extern void *emallocz(unsigned int size); 134extern void *emallocz(unsigned int size);
135extern void eprint(const char *errstr, ...); 135extern void eprint(const char *errstr, ...);
136extern void *erealloc(void *ptr, unsigned int size);
136extern void spawn(Arg *arg); 137extern void spawn(Arg *arg);
diff --git a/event.c b/event.c
index 1a8de56..e5ca166 100644
--- a/event.c
+++ b/event.c
@@ -118,21 +118,24 @@ buttonpress(XEvent *e)
118 } 118 }
119 } 119 }
120 else if((c = getclient(ev->window))) { 120 else if((c = getclient(ev->window))) {
121 higher(c);
122 focus(c); 121 focus(c);
123 switch(ev->button) { 122 switch(ev->button) {
124 default: 123 default:
125 break; 124 break;
126 case Button1: 125 case Button1:
127 if(!c->ismax && (arrange == dofloat || c->isfloat)) 126 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
127 restack(c);
128 movemouse(c); 128 movemouse(c);
129 }
129 break; 130 break;
130 case Button2: 131 case Button2:
131 zoom(NULL); 132 zoom(NULL);
132 break; 133 break;
133 case Button3: 134 case Button3:
134 if(!c->ismax && (arrange == dofloat || c->isfloat)) 135 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
136 restack(c);
135 resizemouse(c); 137 resizemouse(c);
138 }
136 break; 139 break;
137 } 140 }
138 } 141 }
diff --git a/tag.c b/tag.c
index d27d91a..01979d5 100644
--- a/tag.c
+++ b/tag.c
@@ -58,18 +58,17 @@ dofloat(Arg *arg)
58 ban(c); 58 ban(c);
59 } 59 }
60 if((sel = getnext(clients))) { 60 if((sel = getnext(clients))) {
61 higher(sel);
62 focus(sel); 61 focus(sel);
62 restack();
63 } 63 }
64 else 64 else
65 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 65 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
66 drawall();
67} 66}
68 67
69void 68void
70dotile(Arg *arg) 69dotile(Arg *arg)
71{ 70{
72 int n, i, w, h; 71 int h, i, n, w;
73 Client *c; 72 Client *c;
74 73
75 w = sw - mw; 74 w = sw - mw;
@@ -86,7 +85,6 @@ dotile(Arg *arg)
86 c->ismax = False; 85 c->ismax = False;
87 if(isvisible(c)) { 86 if(isvisible(c)) {
88 if(c->isfloat) { 87 if(c->isfloat) {
89 higher(c);
90 resize(c, True, TopLeft); 88 resize(c, True, TopLeft);
91 continue; 89 continue;
92 } 90 }
@@ -123,13 +121,11 @@ dotile(Arg *arg)
123 else 121 else
124 ban(c); 122 ban(c);
125 } 123 }
126 if((sel = getnext(clients))) { 124 if((sel = getnext(clients)))
127 higher(sel);
128 focus(sel); 125 focus(sel);
129 }
130 else 126 else
131 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 127 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
132 drawall(); 128 restack();
133} 129}
134 130
135Client * 131Client *
@@ -200,6 +196,56 @@ replacetag(Arg *arg)
200} 196}
201 197
202void 198void
199restack()
200{
201 static unsigned int nwins = 0;
202 static Window *wins = NULL;
203 unsigned int f, fi, m, mi, n;
204 Client *c;
205 XEvent ev;
206
207 for(f = 0, m = 0, c = clients; c; c = c->next)
208 if(isvisible(c)) {
209 if(c->isfloat || arrange == dofloat)
210 f++;
211 else
212 m++;
213 }
214
215 n = 2 * (f + m);
216 if(nwins < n) {
217 nwins = n;
218 wins = erealloc(wins, nwins * sizeof(Window));
219 }
220
221 fi = 0;
222 mi = 2 * f;
223 if(sel->isfloat || arrange == dofloat) {
224 wins[fi++] = sel->title;
225 wins[fi++] = sel->win;
226 }
227 else {
228 wins[mi++] = sel->title;
229 wins[mi++] = sel->win;
230 }
231 for(c = clients; c; c = c->next)
232 if(isvisible(c) && c != sel) {
233 if(c->isfloat || arrange == dofloat) {
234 wins[fi++] = c->title;
235 wins[fi++] = c->win;
236 }
237 else {
238 wins[mi++] = c->title;
239 wins[mi++] = c->win;
240 }
241 }
242 XRestackWindows(dpy, wins, n);
243 drawall();
244 XSync(dpy, False);
245 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
246}
247
248void
203settags(Client *c) 249settags(Client *c)
204{ 250{
205 char classinst[256]; 251 char classinst[256];
@@ -248,7 +294,6 @@ view(Arg *arg)
248 seltag[i] = False; 294 seltag[i] = False;
249 seltag[arg->i] = True; 295 seltag[arg->i] = True;
250 arrange(NULL); 296 arrange(NULL);
251 drawall();
252} 297}
253 298
254void 299void
@@ -261,5 +306,4 @@ toggleview(Arg *arg)
261 if(i == ntags) 306 if(i == ntags)
262 seltag[arg->i] = True; /* cannot toggle last view */ 307 seltag[arg->i] = True; /* cannot toggle last view */
263 arrange(NULL); 308 arrange(NULL);
264 drawall();
265} 309}
diff --git a/util.c b/util.c
index 4cc748f..2414b39 100644
--- a/util.c
+++ b/util.c
@@ -40,6 +40,15 @@ eprint(const char *errstr, ...)
40 exit(EXIT_FAILURE); 40 exit(EXIT_FAILURE);
41} 41}
42 42
43void *
44erealloc(void *ptr, unsigned int size)
45{
46 void *res = realloc(ptr, size);
47 if(!res)
48 bad_malloc(size);
49 return res;
50}
51
43void 52void
44spawn(Arg *arg) 53spawn(Arg *arg)
45{ 54{