summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c17
-rw-r--r--dwm.h3
-rw-r--r--event.c4
-rw-r--r--layout.c41
4 files changed, 31 insertions, 34 deletions
diff --git a/client.c b/client.c
index f3d31cb..90399ae 100644
--- a/client.c
+++ b/client.c
@@ -129,8 +129,8 @@ detach(Client *c) {
129 129
130void 130void
131focus(Client *c) { 131focus(Client *c) {
132 if(c && !isvisible(c)) 132 if( !c && selscreen || c && !isvisible(c))
133 return; 133 for(c = stack; c && !isvisible(c); c = c->snext);
134 if(sel && sel != c) { 134 if(sel && sel != c) {
135 grabbuttons(sel, False); 135 grabbuttons(sel, False);
136 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); 136 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
@@ -153,14 +153,6 @@ focus(Client *c) {
153} 153}
154 154
155void 155void
156focustopvisible(void) {
157 Client *c;
158
159 for(c = stack; c && !isvisible(c); c = c->snext);
160 focus(c);
161}
162
163void
164killclient(const char *arg) { 156killclient(const char *arg) {
165 XEvent ev; 157 XEvent ev;
166 158
@@ -230,8 +222,7 @@ manage(Window w, XWindowAttributes *wa) {
230 XMoveWindow(dpy, w, c->x + 2 * sw, c->y); 222 XMoveWindow(dpy, w, c->x + 2 * sw, c->y);
231 XMapWindow(dpy, w); 223 XMapWindow(dpy, w);
232 setclientstate(c, NormalState); 224 setclientstate(c, NormalState);
233 if(isvisible(c)) 225 focus(c);
234 focus(c);
235 lt->arrange(); 226 lt->arrange();
236} 227}
237 228
@@ -401,7 +392,7 @@ unmanage(Client *c) {
401 detach(c); 392 detach(c);
402 detachstack(c); 393 detachstack(c);
403 if(sel == c) 394 if(sel == c)
404 focustopvisible(); 395 focus(NULL);
405 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 396 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
406 setclientstate(c, WithdrawnState); 397 setclientstate(c, WithdrawnState);
407 free(c->tags); 398 free(c->tags);
diff --git a/dwm.h b/dwm.h
index 769d1b1..2c1d41b 100644
--- a/dwm.h
+++ b/dwm.h
@@ -100,8 +100,7 @@ Window root, barwin;
100void attach(Client *c); /* attaches c to global client list */ 100void attach(Client *c); /* attaches c to global client list */
101void configure(Client *c); /* send synthetic configure event */ 101void configure(Client *c); /* send synthetic configure event */
102void detach(Client *c); /* detaches c from global client list */ 102void detach(Client *c); /* detaches c from global client list */
103void focus(Client *c); /* focus c, c may be NULL */ 103void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
104void focustopvisible(void); /* focus top visible window on stack */
105void killclient(const char *arg); /* kill sel nicely */ 104void killclient(const char *arg); /* kill sel nicely */
106void manage(Window w, XWindowAttributes *wa); /* manage new client */ 105void manage(Window w, XWindowAttributes *wa); /* manage new client */
107void resize(Client *c, int x, int y, 106void resize(Client *c, int x, int y,
diff --git a/event.c b/event.c
index 2773c6f..f9d2e0c 100644
--- a/event.c
+++ b/event.c
@@ -242,11 +242,11 @@ enternotify(XEvent *e) {
242 242
243 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) 243 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
244 return; 244 return;
245 if((c = getclient(ev->window)) && isvisible(c)) 245 if(c = getclient(ev->window))
246 focus(c); 246 focus(c);
247 else if(ev->window == root) { 247 else if(ev->window == root) {
248 selscreen = True; 248 selscreen = True;
249 focustopvisible(); 249 focus(NULL);
250 } 250 }
251} 251}
252 252
diff --git a/layout.c b/layout.c
index 4b4e908..de6aef6 100644
--- a/layout.c
+++ b/layout.c
@@ -14,6 +14,22 @@ static unsigned int masterw = MASTERWIDTH;
14static unsigned int nmaster = NMASTER; 14static unsigned int nmaster = NMASTER;
15 15
16static void 16static void
17ban(Client *c) {
18 if (c->isbanned)
19 return;
20 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
21 c->isbanned = True;
22}
23
24static void
25unban(Client *c) {
26 if (!c->isbanned)
27 return;
28 XMoveWindow(dpy, c->win, c->x, c->y);
29 c->isbanned = False;
30}
31
32static void
17tile(void) { 33tile(void) {
18 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; 34 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
19 Client *c; 35 Client *c;
@@ -28,9 +44,7 @@ tile(void) {
28 44
29 for(i = 0, c = clients; c; c = c->next) 45 for(i = 0, c = clients; c; c = c->next)
30 if(isvisible(c)) { 46 if(isvisible(c)) {
31 if(c->isbanned) 47 unban(c);
32 XMoveWindow(dpy, c->win, c->x, c->y);
33 c->isbanned = False;
34 if(c->isfloating) 48 if(c->isfloating)
35 continue; 49 continue;
36 c->ismax = False; 50 c->ismax = False;
@@ -60,12 +74,9 @@ tile(void) {
60 resize(c, nx, ny, nw, nh, False); 74 resize(c, nx, ny, nw, nh, False);
61 i++; 75 i++;
62 } 76 }
63 else { 77 else
64 c->isbanned = True; 78 ban(c);
65 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); 79 focus(NULL);
66 }
67 if(!sel || !isvisible(sel))
68 focustopvisible();
69 restack(); 80 restack();
70} 81}
71 82
@@ -77,20 +88,16 @@ void
77floating(void) { 88floating(void) {
78 Client *c; 89 Client *c;
79 90
80 for(c = clients; c; c = c->next) { 91 for(c = clients; c; c = c->next)
81 if(isvisible(c)) { 92 if(isvisible(c)) {
82 if(c->isbanned) 93 if(c->isbanned)
83 XMoveWindow(dpy, c->win, c->x, c->y); 94 XMoveWindow(dpy, c->win, c->x, c->y);
84 c->isbanned = False; 95 c->isbanned = False;
85 resize(c, c->x, c->y, c->w, c->h, True); 96 resize(c, c->x, c->y, c->w, c->h, True);
86 } 97 }
87 else { 98 else
88 c->isbanned = True; 99 ban(c);
89 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); 100 focus(NULL);
90 }
91 }
92 if(!sel || !isvisible(sel))
93 focustopvisible();
94 restack(); 101 restack();
95} 102}
96 103