sites

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

dwm-6.1-zoomswap.diff (2585B)


      1 Author: Jan Christoph Ebersbach <jceb@e-jc.de>
      2 URL: http://dwm.suckless.org/patches/zoomswap
      3 This patch swaps the current window with the previous master when zooming.
      4 
      5 Index: dwm/dwm.c
      6 ===================================================================
      7 --- dwm/dwm.c.orig	2014-02-09 15:24:16.008117074 +0100
      8 +++ dwm/dwm.c	2014-02-09 15:24:16.000117074 +0100
      9 @@ -234,6 +234,7 @@
     10  static void zoom(const Arg *arg);
     11  
     12  /* variables */
     13 +static Client *prevzoom = NULL;
     14  static const char broken[] = "broken";
     15  static char stext[256];
     16  static int screen;
     17 @@ -2033,14 +2034,38 @@
     18  void
     19  zoom(const Arg *arg) {
     20  	Client *c = selmon->sel;
     21 +	Client *at = NULL, *cold, *cprevious = NULL;
     22  
     23  	if(!selmon->lt[selmon->sellt]->arrange
     24  	|| (selmon->sel && selmon->sel->isfloating))
     25  		return;
     26 -	if(c == nexttiled(selmon->clients))
     27 -		if(!c || !(c = nexttiled(c->next)))
     28 -			return;
     29 -	pop(c);
     30 +	if(c == nexttiled(selmon->clients)) {
     31 +		at = findbefore(prevzoom);
     32 +		if(at)
     33 +			cprevious = nexttiled(at->next);
     34 +		if(!cprevious || cprevious != prevzoom) {
     35 +			prevzoom = NULL;
     36 +			if(!c || !(c = nexttiled(c->next)))
     37 +				return;
     38 +		} else
     39 +			c = cprevious;
     40 +	}
     41 +	cold = nexttiled(selmon->clients);
     42 +	if(c != cold && !at)
     43 +		at = findbefore(c);
     44 +	detach(c);
     45 +	attach(c);
     46 +	/* swap windows instead of pushing the previous one down */
     47 +	if(c != cold && at) {
     48 +		prevzoom = cold;
     49 +		if(cold && at != cold) {
     50 +			detach(cold);
     51 +			cold->next = at->next;
     52 +			at->next = cold;
     53 +		}
     54 +	}
     55 +	focus(c);
     56 +	arrange(c->mon);
     57  }
     58  
     59  int
     60 Index: dwm/zoomswap.c
     61 ===================================================================
     62 --- /dev/null	1970-01-01 00:00:00.000000000 +0000
     63 +++ dwm/zoomswap.c	2014-02-09 15:24:16.004117074 +0100
     64 @@ -0,0 +1,10 @@
     65 +static Client * findbefore(Client *c);
     66 +
     67 +Client *
     68 +findbefore(Client *c) {
     69 +	Client *tmp;
     70 +	if(c == selmon->clients)
     71 +		return NULL;
     72 +	for(tmp = selmon->clients; tmp && tmp->next != c; tmp = tmp->next) ;
     73 +	return tmp;
     74 +}
     75 Index: dwm/config.def.h
     76 ===================================================================
     77 --- dwm/config.def.h.orig	2014-02-09 15:24:16.008117074 +0100
     78 +++ dwm/config.def.h	2014-02-09 15:24:16.004117074 +0100
     79 @@ -54,6 +54,7 @@
     80  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
     81  static const char *termcmd[]  = { "st", NULL };
     82  
     83 +#include "zoomswap.c"
     84  static Key keys[] = {
     85  	/* modifier                     key        function        argument */
     86  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },