diff --git a/README.md b/README.md index 8af4f53..f8d6440 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-09-05 - Alpha, systray and pertag patches added +2019-09-05 - Alpha, systray, pertag and zoomswap patches added ### Patches included: @@ -23,3 +23,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - [systray](https://dwm.suckless.org/patches/systray/) - adds system tray in the status bar + + - [zoomswap](https://dwm.suckless.org/patches/zoomswap/) + - allows a master and a stack window to swap places rather than every window on the screen changing position + diff --git a/dwm.c b/dwm.c index 228f14d..fae2157 100644 --- a/dwm.c +++ b/dwm.c @@ -197,7 +197,9 @@ static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); +#if !ZOOMSWAP_PATCH static void pop(Client *); +#endif // !ZOOMSWAP_PATCH static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); @@ -1391,6 +1393,7 @@ nexttiled(Client *c) return c; } +#if !ZOOMSWAP_PATCH void pop(Client *c) { @@ -1399,6 +1402,7 @@ pop(Client *c) focus(c); arrange(c->mon); } +#endif // !ZOOMSWAP_PATCH void propertynotify(XEvent *e) @@ -2506,14 +2510,66 @@ void zoom(const Arg *arg) { Client *c = selmon->sel; + #if ZOOMSWAP_PATCH + Client *at = NULL, *cold, *cprevious = NULL, *p; + #endif // ZOOMSWAP_PATCH if (!selmon->lt[selmon->sellt]->arrange - || (selmon->sel && selmon->sel->isfloating)) + || (selmon->sel && selmon->sel->isfloating) + #if ZOOMSWAP_PATCH + || !c + #endif // ZOOMSWAP_PATCH + ) return; + + #if ZOOMSWAP_PATCH + if (c == nexttiled(selmon->clients)) { + #if PERTAG_PATCH + p = selmon->pertag->prevzooms[selmon->pertag->curtag]; + #else + p = prevzoom; + #endif // PERTAG_PATCH + at = prevtiled(p); + if (at) + cprevious = nexttiled(at->next); + if (!cprevious || cprevious != p) { + #if PERTAG_PATCH + selmon->pertag->prevzooms[selmon->pertag->curtag] = NULL; + #else + prevzoom = NULL; + #endif // PERTAG_PATCH + if (!c || !(c = nexttiled(c->next))) + return; + } else + c = cprevious; + } + + cold = nexttiled(selmon->clients); + if (c != cold && !at) + at = prevtiled(c); + detach(c); + attach(c); + /* swap windows instead of pushing the previous one down */ + if (c != cold && at) { + #if PERTAG_PATCH + selmon->pertag->prevzooms[selmon->pertag->curtag] = cold; + #else + prevzoom = cold; + #endif // PERTAG_PATCH + if (cold && at != cold) { + detach(cold); + cold->next = at->next; + at->next = cold; + } + } + focus(c); + arrange(c->mon); + #else if (c == nexttiled(selmon->clients)) if (!c || !(c = nexttiled(c->next))) return; pop(c); + #endif // ZOOMSWAP_PATCH } int diff --git a/patch/include.c b/patch/include.c index 811fadd..d14c844 100644 --- a/patch/include.c +++ b/patch/include.c @@ -9,3 +9,7 @@ #if SYSTRAY_PATCH #include "systray.c" #endif + +#if ZOOMSWAP_PATCH +#include "zoomswap.c" +#endif // ZOOMSWAP_PATCH diff --git a/patch/include.h b/patch/include.h index 5605b77..52b0514 100644 --- a/patch/include.h +++ b/patch/include.h @@ -4,4 +4,8 @@ #if SYSTRAY_PATCH #include "systray.h" -#endif \ No newline at end of file +#endif + +#if ZOOMSWAP_PATCH +#include "zoomswap.h" +#endif // ZOOMSWAP_PATCH \ No newline at end of file diff --git a/patch/pertag.c b/patch/pertag.c index 818c7ab..967e46a 100644 --- a/patch/pertag.c +++ b/patch/pertag.c @@ -7,5 +7,7 @@ struct Pertag { #if PERTAGBAR_PATCH Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ #endif // PERTAGBAR_PATCH + #if ZOOMSWAP_PATCH Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */ + #endif // ZOOMSWAP_PATCH }; \ No newline at end of file diff --git a/patch/zoomswap.c b/patch/zoomswap.c new file mode 100644 index 0000000..b7d0fa1 --- /dev/null +++ b/patch/zoomswap.c @@ -0,0 +1,13 @@ + +#if !PERTAG_PATCH +static Client *prevzoom = NULL; +#endif // PERTAG_PATCH + +Client * +prevtiled(Client *c) { + Client *p; + if (!c || c == c->mon->clients) + return NULL; + for (p = c->mon->clients; p && p->next != c; p = p->next); + return p; +} \ No newline at end of file diff --git a/patch/zoomswap.h b/patch/zoomswap.h new file mode 100644 index 0000000..31633b5 --- /dev/null +++ b/patch/zoomswap.h @@ -0,0 +1 @@ +static Client *prevtiled(Client *c); \ No newline at end of file diff --git a/patches.h b/patches.h index 8fe09ec..e452c28 100644 --- a/patches.h +++ b/patches.h @@ -26,4 +26,10 @@ /* This controls whether or not to also store bar position on a per * tag basis, or leave it as one bar per monitor. */ -#define PERTAGBAR_PATCH 0 \ No newline at end of file +#define PERTAGBAR_PATCH 0 + +/* The zoomswap patch allows a master and a stack window to swap places + * rather than every window on the screen changing position. + * https://dwm.suckless.org/patches/zoomswap/ + */ +#define ZOOMSWAP_PATCH 0 \ No newline at end of file