Hey,
I've created a swapfocus patch that remembers the previously selected window
for distinct tags and monitors. With the old patch, there was only one, global
`prevclient` value, so switching to a different tag means that `swapfocus`
function would no longer work on the original tab upon return. If you use
`swapfocus` and have the time, I would like some feedback on my patch. I do not
have multiple monitors, so I have not been able to confirm it works as expected
when using `swapfocus` after changing monitors.
Thanks,
Eric
--- dwm-6.0.c 2012-11-24 21:00:20.000000000 -0600
+++ dwm.c 2012-11-25 09:04:05.000000000 -0600
@@ -143,6 +143,7 @@ struct Monitor {
Monitor *next;
Window barwin;
const Layout *lt[2];
+ Client *prevclient[32];
};
typedef struct {
@@ -224,6 +225,7 @@ static void setup(void);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
+static void swapfocus();
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static int textnw(const char *text, unsigned int len);
@@ -657,6 +659,7 @@ createmon(void) {
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ for(int i = 0; i < 31; i++, m->prevclient[i] = NULL);
return m;
}
@@ -844,6 +847,12 @@ void
focus(Client *c) {
if(!c || !ISVISIBLE(c))
for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
+ else {
+ int n = 0, i;
+ for (i = c->tags & c->mon->tagset[c->mon->seltags]; i; i >>= 1, n++);
+ if (selmon->sel != selmon->prevclient[n - 1])
+ selmon->prevclient[n - 1] = selmon->sel;
+ }
/* was if(selmon->sel) */
if(selmon->sel && selmon->sel != c)
unfocus(selmon->sel, False);
@@ -1675,6 +1684,16 @@ spawn(const Arg *arg) {
}
void
+swapfocus(){
+ Client *c = selmon->sel;
+ int n = 0, i;
+ for (i = c->tags & c->mon->tagset[c->mon->seltags]; i; i >>= 1, n++);
+ if(n) {
+ focus(selmon->prevclient[n - 1]);
+ }
+}
+
+void
tag(const Arg *arg) {
if(selmon->sel && arg->ui & TAGMASK) {
selmon->sel->tags = arg->ui & TAGMASK;