summaryrefslogtreecommitdiff
path: root/dwm/patches/dwm-multimon-6-swap_focus-6.4.diff
blob: 9bd091a671e120098abef3da502b536653dd1ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# From de73c72af0250f56f9ac30a5c3f4520da250282a Mon Sep 17 00:00:00 2001
# From: "Gary B. Genett" <me@garybgenett.net>
# 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--