Re: [dev] Focus previously focused window

From: Andreas Amann <amann_AT_physik.tu-berlin.de>
Date: Thu, 13 Dec 2012 22:16:10 +0100

On Thu, Dec 13, 2012 at 03:04:01PM -0500, Manolo Martínez wrote:
> Hello,
>
> I was wondering if anyone knows of a patch that provides the means to
> return to the previously focused window (if it exists). That is, for
> example, if I'm
> on window1 and launch a window2, MOD+p (say) would take me back to
> window1.


You can try the attached patch. Alt-Ctrl-j brings you back to the previous
window. Pressing Alt-Ctrl-j once more, you get to the one before that, and
so on. With Alt-Ctrl-k you go forward again.

Andreas

# HG changeset patch
# Parent dfd36140a7bcac030bf22a2e81892c0bf3bb52a6
cycle through focus stack

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
_AT_@ -60,6 +60,10 @@
         { MODKEY, XK_b, togglebar, {0} },
         { MODKEY, XK_j, focusstack, {.i = +1 } },
         { MODKEY, XK_k, focusstack, {.i = -1 } },
+ { MODKEY|ShiftMask, XK_j, cycletiled, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_k, cycletiled, {.i = -1 } },
+ { MODKEY|ControlMask, XK_j, cycleglobal, {.i = +1 } },
+ { MODKEY|ControlMask, XK_k, cycleglobal, {.i = -1 } },
         { MODKEY, XK_i, incnmaster, {.i = +1 } },
         { MODKEY, XK_d, incnmaster, {.i = -1 } },
         { MODKEY, XK_h, setmfact, {.f = -0.05} },
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
_AT_@ -173,6 +173,8 @@
 static void configurenotify(XEvent *e);
 static void configurerequest(XEvent *e);
 static Monitor *createmon(void);
+static void cycleglobal(const Arg *arg);
+static void cycletiled(const Arg *arg);
 static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
_AT_@ -644,6 +646,61 @@
         XSync(dpy, False);
 }
 
+void
+cycleglobal(const Arg *arg)
+{
+ Client *c = selmon->stack, *cn;
+
+ if(!c)
+ return;
+
+ if (c->snext) {
+ unfocus(selmon->sel,False);
+
+ for(cn = c; cn->snext; cn = cn->snext);
+
+ if (arg->i > 0) {
+ if (selmon->sel) {
+ cn->snext = selmon->stack;
+ c = selmon->stack = selmon->stack->snext;
+ cn->snext->snext = NULL;
+ }
+ } else {
+ c = cn;
+ }
+ }
+
+ if(!ISVISIBLE(c)) {
+ c->mon->seltags ^= 1;
+ c->mon->tagset[c->mon->seltags] = c->tags;
+ }
+ focus(c);
+ arrange(c->mon);
+}
+
+void
+cycletiled(const Arg *arg)
+{
+ Client *c = nexttiled(selmon->clients),*cn;
+ if(!selmon->lt[selmon->sellt]->arrange || !c || !(cn=nexttiled(c->next)))
+ return;
+
+ if (arg->i > 0) {
+ detach(c);
+ for(; cn->next; cn = cn->next);
+ cn->next = c;
+ c->next = NULL;
+ c = nexttiled(selmon->clients);
+
+ } else {
+ for(c=cn; (cn=nexttiled(cn->next)) != NULL; c=cn);
+ detach(c);
+ attach(c);
+ }
+ focusstack(arg);
+ arrange(c->mon);
+}
+
 Monitor *
 createmon(void) {
         Monitor *m;
Received on Thu Dec 13 2012 - 22:16:10 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 13 2012 - 22:24:04 CET