dwm-6.1-swapfocus.diff (1807B)
1 Author: Jan Christoph Ebersbach <jceb@e-jc.de> 2 URL: http://dwm.suckless.org/patches/swapfocus 3 This patch makes it possible to switch focus with one single shortcut (alt-s) 4 instead of having to think if you should use alt-j or alt-k for reaching the 5 last used window. 6 7 Index: dwm/dwm.c 8 =================================================================== 9 --- dwm/dwm.c.orig 2014-02-09 15:24:14.868117043 +0100 10 +++ dwm/dwm.c 2014-02-09 15:24:14.864117043 +0100 11 @@ -205,6 +205,7 @@ 12 static void showhide(Client *c); 13 static void sigchld(int unused); 14 static void spawn(const Arg *arg); 15 +static void swapfocus(); 16 static void tag(const Arg *arg); 17 static void tagmon(const Arg *arg); 18 static void tile(Monitor *); 19 @@ -234,6 +235,7 @@ 20 static void zoom(const Arg *arg); 21 22 /* variables */ 23 +static Client *prevclient = NULL; 24 static const char broken[] = "broken"; 25 static char stext[256]; 26 static int screen; 27 @@ -1584,6 +1586,16 @@ 28 } 29 30 void 31 +swapfocus(){ 32 + Client *c; 33 + for(c = selmon->clients; c && c != prevclient; c = c->next) ; 34 + if(c == prevclient) { 35 + focus(prevclient); 36 + restack(prevclient->mon); 37 + } 38 +} 39 + 40 +void 41 tag(const Arg *arg) { 42 if(selmon->sel && arg->ui & TAGMASK) { 43 selmon->sel->tags = arg->ui & TAGMASK; 44 @@ -1675,6 +1687,7 @@ 45 unfocus(Client *c, Bool setfocus) { 46 if(!c) 47 return; 48 + prevclient = c; 49 grabbuttons(c, False); 50 XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb); 51 if(setfocus) { 52 @@ -2033,12 +2046,13 @@ 53 void 54 zoom(const Arg *arg) { 55 Client *c = selmon->sel; 56 + prevclient = nexttiled(selmon->clients); 57 58 if(!selmon->lt[selmon->sellt]->arrange 59 || (selmon->sel && selmon->sel->isfloating)) 60 return; 61 if(c == nexttiled(selmon->clients)) 62 - if(!c || !(c = nexttiled(c->next))) 63 + if(!c || !(c = prevclient = nexttiled(c->next))) 64 return; 65 pop(c); 66 }