Author: Eric Pruitt, https://github.com/jameseric/ Description: Switch to most recently, previously focused window that is currently visible. --- a/dwm.c 2012-12-09 23:48:53.000000000 -0600 +++ b/dwm.c 2012-12-09 23:48:53.000000000 -0600 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ Client *snext; Monitor *mon; Window win; + struct timeval ft; }; typedef struct { @@ -224,6 +226,7 @@ static void showhide(Client *c); static void sigchld(int unused); static void spawn(const Arg *arg); +static void lastclient(); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static int textnw(const char *text, unsigned int len); @@ -865,6 +868,21 @@ } void +lastclient() { + Client *c, *o; + for (o = selmon->sel, c = selmon->clients; c; c = c->next) { + if (ISVISIBLE(c) && c != selmon->sel && (o == selmon->sel || + ((double)c->ft.tv_sec + c->ft.tv_usec * 0.000001) > + ((double)o->ft.tv_sec + o->ft.tv_usec * 0.000001))) { + o = c; + } + } + + if(o != selmon->sel) + focus(o); +} + +void focusin(XEvent *e) { /* there are some broken focus acquiring clients */ XFocusChangeEvent *ev = &e->xfocus; @@ -1520,6 +1538,8 @@ void setfocus(Client *c) { + if(gettimeofday(&c->ft, NULL)) + perror("gettimeofday(&c->ft, NULL) failed"); if(!c->neverfocus) XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); sendevent(c, wmatom[WMTakeFocus]);