Author: Jan Christoph Ebersbach URL: http://dwm.suckless.org/patches/zoomswap This patch swaps the current window with the previous master when zooming. Index: dwm/dwm.c =================================================================== --- dwm/dwm.c.orig +++ dwm/dwm.c @@ -236,6 +236,7 @@ static int xerrorstart(Display *dpy, XEr static void zoom(const Arg *arg); /* variables */ +static Client *prevzoom = NULL; static const char broken[] = "broken"; static char stext[256]; static int screen; @@ -2109,14 +2110,38 @@ void zoom(const Arg *arg) { Client *c = selmon->sel; + Client *at = NULL, *cold, *cprevious = NULL; if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating)) return; - if (c == nexttiled(selmon->clients)) - if (!c || !(c = nexttiled(c->next))) - return; - pop(c); + if (c == nexttiled(selmon->clients)) { + at = findbefore(prevzoom); + if (at) + cprevious = nexttiled(at->next); + if (!cprevious || cprevious != prevzoom) { + prevzoom = NULL; + if(!c || !(c = nexttiled(c->next))) + return; + } else + c = cprevious; + } + cold = nexttiled(selmon->clients); + if (c != cold && !at) + at = findbefore(c); + detach(c); + attach(c); + /* swap windows instead of pushing the previous one down */ + if (c != cold && at) { + prevzoom = cold; + if(cold && at != cold) { + detach(cold); + cold->next = at->next; + at->next = cold; + } + } + focus(c); + arrange(c->mon); } int Index: dwm/zoomswap.c =================================================================== --- /dev/null +++ dwm/zoomswap.c @@ -0,0 +1,10 @@ +static Client * findbefore(Client *c); + +Client * +findbefore(Client *c) { + Client *tmp; + if(c == selmon->clients) + return NULL; + for(tmp = selmon->clients; tmp && tmp->next != c; tmp = tmp->next) ; + return tmp; +} Index: dwm/config.def.h =================================================================== --- dwm/config.def.h.orig +++ dwm/config.def.h @@ -59,6 +59,7 @@ static char dmenumon[2] = "0"; /* compon static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; +#include "zoomswap.c" static Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } },