From de73c72af0250f56f9ac30a5c3f4520da250282a Mon Sep 17 00:00:00 2001 From: "Gary B. Genett" Date: Sun, 19 Feb 2023 09:40:00 -0800 Subject: patches/swapfocus: dwm-swapfocus-20160731-56a31dc.diff MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.37.4" This is a multi-part message in MIME format. --------------2.37.4 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit modified from sites: 38b351cf3689ff3fa4845d35ce9894fd9253dbb8 --- config.def.h | 1 + dwm.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) --------------2.37.4 Content-Type: text/x-patch; name="0006-patches-swapfocus-dwm-swapfocus-20160731-56a31dc.dif.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0006-patches-swapfocus-dwm-swapfocus-20160731-56a31dc.dif.patch" diff --git a/config.def.h b/config.def.h index fd00f7080db9271912d0e4352434739d3c08e1b3..9a1118791c3a2f875b58bf3979db5074416b8634 100644 --- a/config.def.h +++ b/config.def.h @@ -79,20 +79,21 @@ static const Key keys[] = { { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY|ShiftMask, XK_j, pushdown, {0} }, { MODKEY|ShiftMask, XK_k, pushup, {0} }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_Tab, swapfocus, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } }, diff --git a/dwm.c b/dwm.c index 5aa229611a27b8aa943308314b494c10e2364137..ac52b8c25991a073db15b55fae774e9c47a05708 100644 --- a/dwm.c +++ b/dwm.c @@ -203,20 +203,21 @@ static int sendevent(Client *c, Atom proto); static void sendmon(Client *c, Monitor *m); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void spawn(const Arg *arg); +static void swapfocus(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void ntoggleview(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); static void unmanage(Client *c, int destroyed); @@ -235,20 +236,21 @@ static void nview(const Arg *arg); static void view(const Arg *arg); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); static void reset_view(const Arg *arg); /* variables */ +static Client *prevclient = NULL; static const char broken[] = "broken"; static char stext[256]; static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh; /* bar height */ static int lrpad; /* sum of left and right padding for text */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, @@ -1721,20 +1723,32 @@ spawn(const Arg *arg) dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); } } +void +swapfocus(const Arg *arg) +{ + Client *c; + + for(c = selmon->clients; c && c != prevclient; c = c->next) ; + if(c == prevclient) { + focus(prevclient); + restack(prevclient->mon); + } +} + void tag(const Arg *arg) { if (selmon->sel && arg->ui & TAGMASK) { selmon->sel->tags = arg->ui & TAGMASK; focus(NULL); arrange(selmon); } } @@ -1834,20 +1848,21 @@ toggleview(const Arg *arg) focus(NULL); arrange(selmon); } } void unfocus(Client *c, int setfocus) { if (!c) return; + prevclient = c; grabbuttons(c, 0); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } } void unmanage(Client *c, int destroyed) @@ -2213,25 +2228,27 @@ int xerrorstart(Display *dpy, XErrorEvent *ee) { die("dwm: another window manager is already running"); return -1; } void zoom(const Arg *arg) { Client *c = selmon->sel; + prevclient = nexttiled(selmon->clients); if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating) return; if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) - return; + if (!c || !(c = prevclient = nexttiled(c->next))) + return; pop(c); } void reset_view(const Arg *arg) { const int mon = selmon->num; Arg n = {.i = +1}; // focusmon(next monitor) Arg m = {.f = 0}; // mfact -> facts[] Arg i = {.i = 0}; // nmaster -> masters[] Arg v = {.ui = 0}; // nviews -> views[] --------------2.37.4--