On Mon, Jul 07, 2014 at 11:23:35PM -0400, Lee Fallat wrote:
> Do you have the right #include statements? Show us your patch as if
> you were about to submit it so someone can help you :)
I've attached the diff to this email. I only saw time.h mentioned in the
man page, so that's the only include I added.
Eric
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 <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <time.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
@@ -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]);
}