diff --git a/config.mk b/config.mk index 49e182e..8231f68 100644 --- a/config.mk +++ b/config.mk @@ -16,7 +16,7 @@ X11LIB = /usr/X11R6/lib # includes and libs INCS = -I${X11INC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} -lrt # flags CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} diff --git a/dwm.c b/dwm.c index ffc8864..009a41d 100644 --- a/dwm.c +++ b/dwm.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,7 @@ struct Client { Client *snext; Monitor *mon; Window win; + double ft; }; typedef struct { @@ -177,6 +179,7 @@ static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); +static void lastclient(); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); @@ -1004,6 +1007,20 @@ killclient(const Arg *arg) { } 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 || c->ft > o->ft)) { + o = c; + } + } + + if (o != selmon->sel) { + focus(o); + } +} + +void manage(Window w, XWindowAttributes *wa) { Client *c, *t = NULL; Window trans = None; @@ -1012,6 +1029,7 @@ manage(Window w, XWindowAttributes *wa) { if(!(c = calloc(1, sizeof(Client)))) die("fatal: could not malloc() %u bytes\n", sizeof(Client)); c->win = w; + c->ft = 0; updatetitle(c); if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { c->mon = t->mon; @@ -1423,11 +1441,17 @@ sendevent(Client *c, Atom proto) { void setfocus(Client *c) { + struct timespec t; if(!c->neverfocus) { XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &(c->win), 1); + if (clock_gettime(CLOCK_MONOTONIC, &t)) { + perror("clock_gettime"); + } else { + c->ft = (double) t.tv_sec + t.tv_nsec * 0.000000001; + } } sendevent(c, wmatom[WMTakeFocus]); }