diff -r cfcfa05033e3 dwm.c --- a/dwm.c Fri Oct 28 23:45:12 2011 +0100 +++ b/dwm.c Fri Oct 28 18:43:14 2011 -0700 @@ -240,6 +240,7 @@ static void updatetitle(Client *c); static void updatewmhints(Client *c); static void view(const Arg *arg); +static void warp(const Client *c); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); @@ -898,6 +899,7 @@ unfocus(selmon->sel, True); selmon = m; focus(NULL); + warp(selmon->sel); } void @@ -1418,6 +1420,8 @@ } XSync(dpy, False); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + if (m == selmon && (m->tagset[m->seltags] & m->sel->tags)) + warp(m->sel); } void @@ -1994,6 +1998,26 @@ arrange(selmon); } +void +warp(const Client *c) { + Window dummy; + int x, y, di; + unsigned int dui; + + if (!c) { + XWarpPointer(dpy, None, root, 0, 0, 0, 0, selmon->wx + selmon->ww / 2, selmon->wy + selmon->wh/2); + return; + } + + XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); + + if((x > c->x && y > c->y && x < c->x + c->w && y < c->y + c->h) || + (y > c->mon->by && y < c->mon->by + bh)) + return; + + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); +} + Client * wintoclient(Window w) { Client *c;