diff --git a/README.md b/README.md index a8ec577..63aadfa 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-01-29 - Added swapfocus patch + 2020-01-26 - Added transfer patch 2020-01-24 - Added barpadding patch (incl. statusallmons, statuspadding, statuscolors, systray, alpha, holdbar and extrabar patch compatibility). Moved patches.h to patches.def.h to mimic the config pattern of having default and personal settings. @@ -293,6 +295,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - clients marked with isterminal in config.h swallow a window opened by any child process, e.g. running xclock in a terminal - closing the xclock window restores the terminal window in the current position + - [swapfocus](https://dwm.suckless.org/patches/swapfocus/) + - this patch depends on the pertag patch and makes it possible to switch focus with a single shortcut (mod-s) instead of having to think if you should use mod-j or mod-k for reaching the previously used window + - [switchcol](https://dwm.suckless.org/patches/switchcol/) - allows you to switch focus between the master and stack columns using a single keybinding diff --git a/config.def.h b/config.def.h index 1ad3d6b..83e5192 100644 --- a/config.def.h +++ b/config.def.h @@ -527,6 +527,9 @@ static Key keys[] = { { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, + #if SWAPFOCUS_PATCH && PERTAG_PATCH + { MODKEY, XK_s, swapfocus, {.i = -1 } }, + #endif // SWAPFOCUS_PATCH #if SWITCHCOL_PATCH { MODKEY, XK_v, switchcol, {0} }, #endif // SWITCHCOL_PATCH @@ -644,7 +647,7 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_f, fullscreen, {0} }, #endif // FULLSCREEN_PATCH #if STICKY_PATCH - { MODKEY, XK_s, togglesticky, {0} }, + { MODKEY|ShiftMask, XK_s, togglesticky, {0} }, #endif // STICKY_PATCH { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, diff --git a/dwm.c b/dwm.c index 75d9a4f..31ac557 100644 --- a/dwm.c +++ b/dwm.c @@ -1945,6 +1945,9 @@ killclient(const Arg *arg) XSetErrorHandler(xerror); XUngrabServer(dpy); } + #if SWAPFOCUS_PATCH && PERTAG_PATCH + selmon->pertag->prevclient[selmon->pertag->curtag] = NULL; + #endif // SWAPFOCUS_PATCH } void @@ -3096,6 +3099,9 @@ tag(const Arg *arg) if (selmon->sel && arg->ui & TAGMASK) { selmon->sel->tags = arg->ui & TAGMASK; focus(NULL); + #if SWAPFOCUS_PATCH && PERTAG_PATCH + selmon->pertag->prevclient[selmon->pertag->curtag] = NULL; + #endif // SWAPFOCUS_PATCH arrange(selmon); #if VIEWONTAG_PATCH view(arg); @@ -3306,6 +3312,9 @@ unfocus(Client *c, int setfocus) { if (!c) return; + #if SWAPFOCUS_PATCH && PERTAG_PATCH + selmon->pertag->prevclient[selmon->pertag->curtag] = c; + #endif // SWAPFOCUS_PATCH grabbuttons(c, 0); #if FLOAT_BORDER_COLOR_PATCH if (c->isfloating) @@ -3782,11 +3791,17 @@ view(const Arg *arg) selmon->seltags ^= 1; /* toggle sel tagset */ #if PERTAG_PATCH pertagview(arg); + #if SWAPFOCUS_PATCH + Client *unmodified = selmon->pertag->prevclient[selmon->pertag->curtag]; + #endif // SWAPFOCUS_PATCH #else if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; #endif // PERTAG_PATCH focus(NULL); + #if SWAPFOCUS_PATCH && PERTAG_PATCH + selmon->pertag->prevclient[selmon->pertag->curtag] = unmodified; + #endif // SWAPFOCUS_PATCH arrange(selmon); #if EWMHTAGS_PATCH updatecurrentdesktop(); @@ -3871,6 +3886,10 @@ zoom(const Arg *arg) Client *at = NULL, *cold, *cprevious = NULL, *p; #endif // ZOOMSWAP_PATCH + #if SWAPFOCUS_PATCH && PERTAG_PATCH + selmon->pertag->prevclient[selmon->pertag->curtag] = nexttiled(selmon->clients); + #endif // SWAPFOCUS_PATCH + if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating) #if ZOOMSWAP_PATCH @@ -3895,10 +3914,18 @@ zoom(const Arg *arg) #else prevzoom = NULL; #endif // PERTAG_PATCH + #if SWAPFOCUS_PATCH && PERTAG_PATCH + if (!c || !(c = selmon->pertag->prevclient[selmon->pertag->curtag] = nexttiled(c->next))) + #else if (!c || !(c = nexttiled(c->next))) + #endif // SWAPFOCUS_PATCH return; } else + #if SWAPFOCUS_PATCH && PERTAG_PATCH + c = selmon->pertag->prevclient[selmon->pertag->curtag] = cprevious; + #else c = cprevious; + #endif // SWAPFOCUS_PATCH } cold = nexttiled(selmon->clients); @@ -3923,7 +3950,11 @@ zoom(const Arg *arg) arrange(c->mon); #else if (c == nexttiled(selmon->clients)) + #if SWAPFOCUS_PATCH && PERTAG_PATCH + if (!c || !(c = selmon->pertag->prevclient[selmon->pertag->curtag] = nexttiled(c->next))) + #else if (!c || !(c = nexttiled(c->next))) + #endif // SWAPFOCUS_PATCH return; pop(c); #endif // ZOOMSWAP_PATCH diff --git a/patch/holdbar.c b/patch/holdbar.c index ccf662f..a06cab3 100644 --- a/patch/holdbar.c +++ b/patch/holdbar.c @@ -47,12 +47,6 @@ updateholdbarpos(Monitor *m) { m->wy = m->my; m->wh = m->mh; - // if (m->showbar) { - // m->by = m->topbar ? m->wy : m->wy + m->wh - bh; - // m->wy = m->topbar ? m->wy - bh + bh : m->wy; - // } else { - // m->by = -bh; - // } #if EXTRABAR_PATCH #if BARPADDING_PATCH m->wh = m->wh - vertpad * m->showbar * 2 - bh * m->showbar * 2; diff --git a/patch/include.c b/patch/include.c index 1fbc504..8a404e1 100644 --- a/patch/include.c +++ b/patch/include.c @@ -101,7 +101,10 @@ #endif #if SWALLOW_PATCH #include "swallow.c" -#endif // SWALLOW_PATCH +#endif +#if SWAPFOCUS_PATCH && PERTAG_PATCH +#include "swapfocus.c" +#endif #if SWITCHCOL_PATCH #include "switchcol.c" #endif diff --git a/patch/include.h b/patch/include.h index efe0917..5ef2291 100644 --- a/patch/include.h +++ b/patch/include.h @@ -101,7 +101,10 @@ #endif #if SWALLOW_PATCH #include "swallow.h" -#endif // SWALLOW_PATCH +#endif +#if SWAPFOCUS_PATCH && PERTAG_PATCH +#include "swapfocus.h" +#endif #if SWITCHCOL_PATCH #include "switchcol.h" #endif @@ -183,4 +186,4 @@ #endif #if TILE_LAYOUT #include "tile.h" -#endif +#endif \ No newline at end of file diff --git a/patch/pertag.c b/patch/pertag.c index 708943d..f172c65 100644 --- a/patch/pertag.c +++ b/patch/pertag.c @@ -16,6 +16,9 @@ struct Pertag { #if ZOOMSWAP_PATCH Client *prevzooms[LENGTH(tags) + 1]; /* store zoom information */ #endif // ZOOMSWAP_PATCH + #if SWAPFOCUS_PATCH + Client *prevclient[LENGTH(tags) + 1]; + #endif // SWAPFOCUS_PATCH }; void @@ -56,6 +59,4 @@ pertagview(const Arg *arg) if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) togglebar(NULL); #endif // PERTAGBAR_PATCH - // strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); // ?? - // strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); } \ No newline at end of file diff --git a/patch/swapfocus.c b/patch/swapfocus.c new file mode 100644 index 0000000..7693925 --- /dev/null +++ b/patch/swapfocus.c @@ -0,0 +1,21 @@ +void +swapfocus(const Arg *arg) +{ + if (!selmon->sel) + return; + if (selmon->pertag->prevclient[selmon->pertag->curtag] != NULL + && ISVISIBLE(selmon->pertag->prevclient[selmon->pertag->curtag])) { + focus(selmon->pertag->prevclient[selmon->pertag->curtag]); + restack(selmon->pertag->prevclient[selmon->pertag->curtag]->mon); + } + else { + Client *c = NULL; + for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); + if (!c) + for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); + if (c) { + focus(c); + restack(selmon); + } + } +} \ No newline at end of file diff --git a/patch/swapfocus.h b/patch/swapfocus.h new file mode 100644 index 0000000..f573988 --- /dev/null +++ b/patch/swapfocus.h @@ -0,0 +1 @@ +static void swapfocus(const Arg *arg); \ No newline at end of file diff --git a/patches.def.h b/patches.def.h index 1477706..4ce253e 100644 --- a/patches.def.h +++ b/patches.def.h @@ -436,6 +436,13 @@ */ #define SWALLOW_PATCH 0 +/* This patch depends on the pertag patch and makes it possible to switch focus with a single + * shortcut (mod-s) instead of having to think if you should use mod-j or mod-k for reaching + * the previously used window. + * https://dwm.suckless.org/patches/swapfocus/ + */ +#define SWAPFOCUS_PATCH 0 + /* Switch focus between the master and stack columns using a single keybinding. * https://dwm.suckless.org/patches/switchcol/ */