applied anydot's 3 minor patches, thank you anydot
authorAnselm R. Garbe <arg@suckless.org>
Tue, 29 May 2007 11:35:20 +0200
changeset 904 2dfd50e4cfde
parent 903 467c754b607d
child 905 ca352bd2f8f7
applied anydot's 3 minor patches, thank you anydot
client.c
dwm.h
event.c
layout.c
--- a/client.c	Mon May 28 15:05:47 2007 +0200
+++ b/client.c	Tue May 29 11:35:20 2007 +0200
@@ -129,8 +129,8 @@
 
 void
 focus(Client *c) {
-	if(c && !isvisible(c))
-		return;
+	if( !c && selscreen || c && !isvisible(c))
+		for(c = stack; c && !isvisible(c); c = c->snext);
 	if(sel && sel != c) {
 		grabbuttons(sel, False);
 		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
@@ -153,14 +153,6 @@
 }
 
 void
-focustopvisible(void) {
-	Client *c;
-
-	for(c = stack; c && !isvisible(c); c = c->snext);
-	focus(c);
-}
-
-void
 killclient(const char *arg) {
 	XEvent ev;
 
@@ -230,8 +222,7 @@
 	XMoveWindow(dpy, w, c->x + 2 * sw, c->y);
 	XMapWindow(dpy, w);
 	setclientstate(c, NormalState);
-	if(isvisible(c))
-		focus(c);
+	focus(c);
 	lt->arrange();
 }
 
@@ -401,7 +392,7 @@
 	detach(c);
 	detachstack(c);
 	if(sel == c)
-		focustopvisible();
+		focus(NULL);
 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
 	setclientstate(c, WithdrawnState);
 	free(c->tags);
--- a/dwm.h	Mon May 28 15:05:47 2007 +0200
+++ b/dwm.h	Tue May 29 11:35:20 2007 +0200
@@ -100,8 +100,7 @@
 void attach(Client *c);			/* attaches c to global client list */
 void configure(Client *c);		/* send synthetic configure event */
 void detach(Client *c);			/* detaches c from global client list */
-void focus(Client *c);			/* focus c, c may be NULL */
-void focustopvisible(void);		/* focus top visible window on stack */
+void focus(Client *c);			/* focus c if visible && !NULL, or focus top visible */
 void killclient(const char *arg);	/* kill sel  nicely */
 void manage(Window w, XWindowAttributes *wa);	/* manage new client */
 void resize(Client *c, int x, int y,
--- a/event.c	Mon May 28 15:05:47 2007 +0200
+++ b/event.c	Tue May 29 11:35:20 2007 +0200
@@ -242,11 +242,11 @@
 
 	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
 		return;
-	if((c = getclient(ev->window)) && isvisible(c))
+	if(c = getclient(ev->window))
 		focus(c);
 	else if(ev->window == root) {
 		selscreen = True;
-		focustopvisible();
+		focus(NULL);
 	}
 }
 
--- a/layout.c	Mon May 28 15:05:47 2007 +0200
+++ b/layout.c	Tue May 29 11:35:20 2007 +0200
@@ -14,6 +14,22 @@
 static unsigned int nmaster = NMASTER;
 
 static void
+ban(Client *c) {
+	if (c->isbanned)
+		return;
+	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+	c->isbanned = True;
+}
+
+static void
+unban(Client *c) {
+	if (!c->isbanned)
+		return;
+	XMoveWindow(dpy, c->win, c->x, c->y);
+	c->isbanned = False;
+}
+
+static void
 tile(void) {
 	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
 	Client *c;
@@ -28,9 +44,7 @@
 
 	for(i = 0, c = clients; c; c = c->next)
 		if(isvisible(c)) {
-			if(c->isbanned)
-				XMoveWindow(dpy, c->win, c->x, c->y);
-			c->isbanned = False;
+			unban(c);
 			if(c->isfloating)
 				continue;
 			c->ismax = False;
@@ -60,12 +74,9 @@
 			resize(c, nx, ny, nw, nh, False);
 			i++;
 		}
-		else {
-			c->isbanned = True;
-			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-		}
-	if(!sel || !isvisible(sel)) 
-		focustopvisible();
+		else
+			ban(c);
+	focus(NULL);
 	restack();
 }
 
@@ -77,20 +88,16 @@
 floating(void) {
 	Client *c;
 
-	for(c = clients; c; c = c->next) {
+	for(c = clients; c; c = c->next)
 		if(isvisible(c)) {
 			if(c->isbanned)
 				XMoveWindow(dpy, c->win, c->x, c->y);
 			c->isbanned = False;
 			resize(c, c->x, c->y, c->w, c->h, True);
 		}
-		else {
-			c->isbanned = True;
-			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-		}
-	}
-	if(!sel || !isvisible(sel))
-		focustopvisible();
+		else
+			ban(c);
+	focus(NULL);
 	restack();
 }