Re: [dev] Focus previously focused window

2012-12-14 Thread Andreas Amann
On Thu, Dec 13, 2012 at 04:20:13PM -0500, Manolo Martínez wrote:
 Thanks a lot. I will give it a try. I have to ask: how you just come up
 with it, prompted by my question? If so, double thanks.
 

no, I like to go back deep into the focus history myself ;-) 

I had previously posted the patch in
http://lists.suckless.org/dev/1211/13219.html, and that message also
contains some more explanations.

Andreas



[dev] Focus previously focused window

2012-12-13 Thread Manolo Martínez
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.

Thanks
Manolo

-- 



Re: [dev] Focus previously focused window

2012-12-13 Thread Andreas Amann
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
@@ -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
@@ -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);
@@ -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;





Re: [dev] Focus previously focused window

2012-12-13 Thread Manolo Martínez
On 12/13/12 at 10:16pm, Andreas Amann wrote:
 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
 

Thanks a lot. I will give it a try. I have to ask: how you just come up
with it, prompted by my question? If so, double thanks.

Manolo



Re: [dev] Focus previously focused window

2012-12-13 Thread Manolo Martínez
On 12/13/12 at 03:20pm, Eric Pruitt wrote:
 Hey Manolo,
 
 On Thu, Dec 13, 2012 at 03:04:01PM -0500, Manolo Martínez wrote:
  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.
 
 There's the swapfocus patch at http://dwm.suckless.org/patches/swapfocus. The
 downside to this patch is that it remembers _only_ the most recently selected
 window, and changing tag sets or opening and closing windows will often strip
 you of the ability to go back to a previously selected client.
 
 I wrote an alternate version of swapfocus that sorta works on a per-tag basis.
 See the patch comments for an explanation of the sorta part. That patch had
 its own problems as well, specifically that due to the way I wrote it, opening
 a new window would throw of the previous client selection at times. Some days
 ago, I decided to take a completely different approach and wrote the
 lastclient.diff patch that is also attached. With this patch, every time a
 window is focused, the time the window was focused is recorded. When you call
 the lastclient function, the most recently focused window is selected which
 eliminates problems with changing tags, but depending on your workflow, the
 focused timestamp base approach may throw you off at times.
 
 Eric

Thanks! I'm sure one of these will do the trick. The use case is pretty
simple, actually.

Manolo