| dwm-goback-20201227-61bb8b2.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| dwm-goback-20201227-61bb8b2.diff (4217B) | |
| --- | |
| 1 From ad9b42dd9f9cc984f6d7bf6351b1101b594899b4 Mon Sep 17 00:00:00 2001 | |
| 2 From: Max Schillinger <[email protected]> | |
| 3 Date: Sun, 27 Dec 2020 15:04:08 +0100 | |
| 4 Subject: [PATCH] add patch/function 'goback' | |
| 5 | |
| 6 --- | |
| 7 config.def.h | 1 + | |
| 8 dwm.c | 31 +++++++++++++++++++++++++++++-- | |
| 9 2 files changed, 30 insertions(+), 2 deletions(-) | |
| 10 | |
| 11 diff --git a/config.def.h b/config.def.h | |
| 12 index 1c0b587..c217a27 100644 | |
| 13 --- a/config.def.h | |
| 14 +++ b/config.def.h | |
| 15 @@ -72,6 +72,7 @@ static Key keys[] = { | |
| 16 { MODKEY, XK_l, setmfact, {.f … | |
| 17 { MODKEY, XK_Return, zoom, {0} … | |
| 18 { MODKEY, XK_Tab, view, {0} … | |
| 19 + { MODKEY, XK_g, goback, {0} … | |
| 20 { MODKEY|ShiftMask, XK_c, killclient, {0} … | |
| 21 { MODKEY, XK_t, setlayout, {.v … | |
| 22 { MODKEY, XK_f, setlayout, {.v … | |
| 23 diff --git a/dwm.c b/dwm.c | |
| 24 index 664c527..3d40bac 100644 | |
| 25 --- a/dwm.c | |
| 26 +++ b/dwm.c | |
| 27 @@ -173,6 +173,7 @@ static Atom getatomprop(Client *c, Atom prop); | |
| 28 static int getrootptr(int *x, int *y); | |
| 29 static long getstate(Window w); | |
| 30 static int gettextprop(Window w, Atom atom, char *text, unsigned int si… | |
| 31 +static void goback(const Arg *arg); | |
| 32 static void grabbuttons(Client *c, int focused); | |
| 33 static void grabkeys(void); | |
| 34 static void incnmaster(const Arg *arg); | |
| 35 @@ -266,7 +267,7 @@ static Cur *cursor[CurLast]; | |
| 36 static Clr **scheme; | |
| 37 static Display *dpy; | |
| 38 static Drw *drw; | |
| 39 -static Monitor *mons, *selmon; | |
| 40 +static Monitor *mons, *selmon, *prevmon; | |
| 41 static Window root, wmcheckwin; | |
| 42 | |
| 43 /* configuration, allows nested code to access above variables */ | |
| 44 @@ -427,6 +428,7 @@ buttonpress(XEvent *e) | |
| 45 /* focus monitor if necessary */ | |
| 46 if ((m = wintomon(ev->window)) && m != selmon) { | |
| 47 unfocus(selmon->sel, 1); | |
| 48 + prevmon = selmon; | |
| 49 selmon = m; | |
| 50 focus(NULL); | |
| 51 } | |
| 52 @@ -765,6 +767,7 @@ enternotify(XEvent *e) | |
| 53 m = c ? c->mon : wintomon(ev->window); | |
| 54 if (m != selmon) { | |
| 55 unfocus(selmon->sel, 1); | |
| 56 + prevmon = selmon; | |
| 57 selmon = m; | |
| 58 } else if (!c || c == selmon->sel) | |
| 59 return; | |
| 60 @@ -789,8 +792,10 @@ focus(Client *c) | |
| 61 if (selmon->sel && selmon->sel != c) | |
| 62 unfocus(selmon->sel, 0); | |
| 63 if (c) { | |
| 64 - if (c->mon != selmon) | |
| 65 + if (c->mon != selmon) { | |
| 66 + prevmon = selmon; | |
| 67 selmon = c->mon; | |
| 68 + } | |
| 69 if (c->isurgent) | |
| 70 seturgent(c, 0); | |
| 71 detachstack(c); | |
| 72 @@ -826,6 +831,7 @@ focusmon(const Arg *arg) | |
| 73 if ((m = dirtomon(arg->i)) == selmon) | |
| 74 return; | |
| 75 unfocus(selmon->sel, 0); | |
| 76 + prevmon = selmon; | |
| 77 selmon = m; | |
| 78 focus(NULL); | |
| 79 } | |
| 80 @@ -925,6 +931,21 @@ gettextprop(Window w, Atom atom, char *text, unsign… | |
| 81 return 1; | |
| 82 } | |
| 83 | |
| 84 +void | |
| 85 +goback(const Arg *arg) | |
| 86 +{ | |
| 87 + if (prevmon == NULL) { | |
| 88 + Arg a = {0}; | |
| 89 + view(&a); | |
| 90 + } else if (prevmon != selmon) { | |
| 91 + unfocus(selmon->sel, 0); | |
| 92 + Monitor *p = selmon; | |
| 93 + selmon = prevmon; | |
| 94 + focus(NULL); | |
| 95 + prevmon = p; | |
| 96 + } | |
| 97 +} | |
| 98 + | |
| 99 void | |
| 100 grabbuttons(Client *c, int focused) | |
| 101 { | |
| 102 @@ -1127,6 +1148,8 @@ motionnotify(XEvent *e) | |
| 103 return; | |
| 104 if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon… | |
| 105 unfocus(selmon->sel, 1); | |
| 106 + if (m != selmon) | |
| 107 + prevmon = selmon; | |
| 108 selmon = m; | |
| 109 focus(NULL); | |
| 110 } | |
| 111 @@ -1188,6 +1211,7 @@ movemouse(const Arg *arg) | |
| 112 XUngrabPointer(dpy, CurrentTime); | |
| 113 if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { | |
| 114 sendmon(c, m); | |
| 115 + prevmon = selmon; | |
| 116 selmon = m; | |
| 117 focus(NULL); | |
| 118 } | |
| 119 @@ -1340,6 +1364,7 @@ resizemouse(const Arg *arg) | |
| 120 while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | |
| 121 if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { | |
| 122 sendmon(c, m); | |
| 123 + prevmon = selmon; | |
| 124 selmon = m; | |
| 125 focus(NULL); | |
| 126 } | |
| 127 @@ -1743,6 +1768,7 @@ toggleview(const Arg *arg) | |
| 128 unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg… | |
| 129 | |
| 130 if (newtagset) { | |
| 131 + prevmon = NULL; | |
| 132 selmon->tagset[selmon->seltags] = newtagset; | |
| 133 focus(NULL); | |
| 134 arrange(selmon); | |
| 135 @@ -2040,6 +2066,7 @@ view(const Arg *arg) | |
| 136 { | |
| 137 if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) | |
| 138 return; | |
| 139 + prevmon = NULL; | |
| 140 selmon->seltags ^= 1; /* toggle sel tagset */ | |
| 141 if (arg->ui & TAGMASK) | |
| 142 selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; | |
| 143 -- | |
| 144 2.25.1 | |
| 145 |