diff -r 5cfd3c602ede dwm.c
--- a/dwm.c	Sat Dec 22 14:40:44 2007 +0000
+++ b/dwm.c	Fri Dec 28 16:04:49 2007 +0100
@@ -332,8 +332,10 @@ ban(Client *c) {
 
 void
 buttonpress(XEvent *e) {
-	unsigned int i, x;
+	unsigned int i, dui, x;
+	int x1, y1, di, px, py;
 	Client *c;
+	Window dummy;
 	XButtonPressedEvent *ev = &e->xbutton;
 
 	Monitor *m = &monitors[monitorat(-1, -1)];
@@ -360,29 +362,40 @@ buttonpress(XEvent *e) {
 		}
 		if((ev->x < x + blw) && ev->button == Button1)
 			setlayout(NULL);
+		x += blw;
+		if(sel && (ev->x > x) && (ev->x < (m->sw - textw(m, stext)))) {
+			if(ev->button == Button1) {
+				XWarpPointer(dpy, None, sel->win, 0, 0, 0, 0, -1, -1);
+				movemouse(sel);
+			}
+			else if(ev->button == Button2) {
+				if(sel->isfloating)
+					togglefloating(NULL);
+				zoom(NULL);
+				}
+			else if(ev->button == Button3)
+				resizemouse(sel);
+			else if(ev->button == Button4)
+				focusprev(NULL);
+			else if(ev->button == Button5)
+				focusnext(NULL);
+		}
 	}
 	else if((c = getclient(ev->window))) {
 		focus(c);
 		if(CLEANMASK(ev->state) != MODKEY)
 			return;
 		if(ev->button == Button1) {
-			if((m->layout->arrange == floating) || c->isfloating)
-				restack();
-			else
-				togglefloating(NULL);
+			restack();
 			movemouse(c);
 		}
 		else if(ev->button == Button2) {
 			if((floating != m->layout->arrange) && c->isfloating)
 				togglefloating(NULL);
-			else
-				zoom(NULL);
+			zoom(NULL);
 		}
 		else if(ev->button == Button3 && !c->isfixed) {
-			if((floating == m->layout->arrange) || c->isfloating)
-				restack();
-			else
-				togglefloating(NULL);
+			restack();
 			resizemouse(c);
 		}
 	}
@@ -1169,7 +1182,10 @@ movemouse(Client *c) {
 				ny = m->way;
 			else if(abs((m->way + m->wah) - (ny + c->h + 2 * c->border)) < SNAP)
 				ny = m->way + m->wah - c->h - 2 * c->border;
-			resize(c, nx, ny, c->w, c->h, False);
+			if((monitors[selmonitor].layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny -c->y) > SNAP) && !sel->isfloating)
+				togglefloating(NULL);
+			if((monitors[selmonitor].layout->arrange == floating) || c->isfloating)
+				resize(c, nx, ny, c->w, c->h, False);
 			memcpy(c->tags, monitors[monitorat(nx, ny)].seltags, sizeof initags);
 			break;
 		}
@@ -1328,7 +1344,10 @@ resizemouse(Client *c) {
 				nw = 1;
 			if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
 				nh = 1;
-			resize(c, c->x, c->y, nw, nh, True);
+			if((monitors[selmonitor].layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh -c->h) > SNAP))
+				togglefloating(NULL);
+			if((monitors[selmonitor].layout->arrange == floating) || c->isfloating)
+				resize(c, c->x, c->y, nw, nh, True);
 			break;
 		}
 	}
