sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-swapfocus-20160731-56a31dc.diff (1791B)


      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
     10 +++ dwm/dwm.c
     11 @@ -207,6 +207,7 @@ static void setup(void);
     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 @@ -236,6 +237,7 @@ static int xerrorstart(Display *dpy, XEr
     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 @@ -1645,6 +1647,17 @@ spawn(const Arg *arg)
     28  }
     29  
     30  void
     31 +swapfocus()
     32 +{
     33 +	Client *c;
     34 +	for(c = selmon->clients; c && c != prevclient; c = c->next) ;
     35 +	if(c == prevclient) {
     36 +		focus(prevclient);
     37 +		restack(prevclient->mon);
     38 +	}
     39 +}
     40 +
     41 +void
     42  tag(const Arg *arg)
     43  {
     44  	if (selmon->sel && arg->ui & TAGMASK) {
     45 @@ -1743,6 +1756,7 @@ unfocus(Client *c, int setfocus)
     46  {
     47  	if (!c)
     48  		return;
     49 +	prevclient = c;
     50  	grabbuttons(c, 0);
     51  	XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
     52  	if (setfocus) {
     53 @@ -2109,12 +2123,13 @@ void
     54  zoom(const Arg *arg)
     55  {
     56  	Client *c = selmon->sel;
     57 +	prevclient = nexttiled(selmon->clients);
     58  
     59  	if (!selmon->lt[selmon->sellt]->arrange
     60  	|| (selmon->sel && selmon->sel->isfloating))
     61  		return;
     62  	if (c == nexttiled(selmon->clients))
     63 -		if (!c || !(c = nexttiled(c->next)))
     64 +		if (!c || !(c = prevclient = nexttiled(c->next)))
     65  			return;
     66  	pop(c);
     67  }