-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathdwm-dragmfact-6.2.diff
286 lines (281 loc) · 8.47 KB
/
dwm-dragmfact-6.2.diff
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
From 6977f159986240cf6bdba9cb97c3bb3cd0eb9ba4 Mon Sep 17 00:00:00 2001
From: Bakkeby <[email protected]>
Date: Wed, 26 Jun 2024 10:08:30 +0200
Subject: [PATCH] dragmfact patch with smooth sliding and support for multiple
layouts
---
config.def.h | 1 +
dwm.c | 228 ++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 228 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
index 1c0b587..72f0467 100644
--- a/config.def.h
+++ b/config.def.h
@@ -107,6 +107,7 @@ static Button buttons[] = {
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
+ { ClkClientWin, MODKEY|ShiftMask, Button1, dragmfact, {0} },
{ ClkTagBar, 0, Button1, view, {0} },
{ ClkTagBar, 0, Button3, toggleview, {0} },
{ ClkTagBar, MODKEY, Button1, tag, {0} },
diff --git a/dwm.c b/dwm.c
index 4465af1..689e338 100644
--- a/dwm.c
+++ b/dwm.c
@@ -58,7 +58,7 @@
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
-enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+enum { CurNormal, CurResize, CurMove, CurResizeHorzArrow, CurResizeVertArrow, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
@@ -161,6 +161,7 @@ static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
static Monitor *dirtomon(int dir);
+static void dragmfact(const Arg *arg);
static void drawbar(Monitor *m);
static void drawbars(void);
static void enternotify(XEvent *e);
@@ -692,6 +693,229 @@ dirtomon(int dir)
return m;
}
+void
+dragmfact(const Arg *arg)
+{
+ unsigned int n;
+ int py, px; // pointer coordinates
+ int ax, ay, aw, ah; // area position, width and height
+ int center = 0, horizontal = 0, mirror = 0, fixed = 0; // layout configuration
+ double fact;
+ Monitor *m;
+ XEvent ev;
+ Time lasttime = 0;
+
+ m = selmon;
+
+ #if VANITYGAPS_PATCH
+ int oh, ov, ih, iv;
+ getgaps(m, &oh, &ov, &ih, &iv, &n);
+ #else
+ Client *c;
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ #endif // VANITYGAPS_PATCH
+
+ ax = m->wx;
+ ay = m->wy;
+ ah = m->wh;
+ aw = m->ww;
+
+ if (!n)
+ return;
+ #if FLEXTILE_DELUXE_LAYOUT
+ else if (m->lt[m->sellt]->arrange == &flextile) {
+ int layout = m->ltaxis[LAYOUT];
+ if (layout < 0) {
+ mirror = 1;
+ layout *= -1;
+ }
+ if (layout > FLOATING_MASTER) {
+ layout -= FLOATING_MASTER;
+ fixed = 1;
+ }
+
+ if (layout == SPLIT_HORIZONTAL || layout == SPLIT_HORIZONTAL_DUAL_STACK)
+ horizontal = 1;
+ else if (layout == SPLIT_CENTERED_VERTICAL && (fixed || n - m->nmaster > 1))
+ center = 1;
+ else if (layout == FLOATING_MASTER) {
+ center = 1;
+ if (aw < ah)
+ horizontal = 1;
+ }
+ else if (layout == SPLIT_CENTERED_HORIZONTAL) {
+ if (fixed || n - m->nmaster > 1)
+ center = 1;
+ horizontal = 1;
+ }
+ }
+ #endif // FLEXTILE_DELUXE_LAYOUT
+ #if CENTEREDMASTER_LAYOUT
+ else if (m->lt[m->sellt]->arrange == ¢eredmaster && (fixed || n - m->nmaster > 1))
+ center = 1;
+ #endif // CENTEREDMASTER_LAYOUT
+ #if CENTEREDFLOATINGMASTER_LAYOUT
+ else if (m->lt[m->sellt]->arrange == ¢eredfloatingmaster)
+ center = 1;
+ #endif // CENTEREDFLOATINGMASTER_LAYOUT
+ #if BSTACK_LAYOUT
+ else if (m->lt[m->sellt]->arrange == &bstack)
+ horizontal = 1;
+ #endif // BSTACK_LAYOUT
+ #if BSTACKHORIZ_LAYOUT
+ else if (m->lt[m->sellt]->arrange == &bstackhoriz)
+ horizontal = 1;
+ #endif // BSTACKHORIZ_LAYOUT
+
+ /* do not allow mfact to be modified under certain conditions */
+ if (!m->lt[m->sellt]->arrange // floating layout
+ || (!fixed && m->nmaster && n <= m->nmaster) // no master
+ #if MONOCLE_LAYOUT
+ || m->lt[m->sellt]->arrange == &monocle
+ #endif // MONOCLE_LAYOUT
+ #if GRIDMODE_LAYOUT
+ || m->lt[m->sellt]->arrange == &grid
+ #endif // GRIDMODE_LAYOUT
+ #if HORIZGRID_LAYOUT
+ || m->lt[m->sellt]->arrange == &horizgrid
+ #endif // HORIZGRID_LAYOUT
+ #if GAPPLESSGRID_LAYOUT
+ || m->lt[m->sellt]->arrange == &gaplessgrid
+ #endif // GAPPLESSGRID_LAYOUT
+ #if NROWGRID_LAYOUT
+ || m->lt[m->sellt]->arrange == &nrowgrid
+ #endif // NROWGRID_LAYOUT
+ #if FLEXTILE_DELUXE_LAYOUT
+ || (m->lt[m->sellt]->arrange == &flextile && m->ltaxis[LAYOUT] == NO_SPLIT)
+ #endif // FLEXTILE_DELUXE_LAYOUT
+ )
+ return;
+
+ #if VANITYGAPS_PATCH
+ ay += oh;
+ ax += ov;
+ aw -= 2*ov;
+ ah -= 2*oh;
+ #endif // VANITYGAPS_PATCH
+
+ if (center) {
+ if (horizontal) {
+ px = ax + aw / 2;
+ #if VANITYGAPS_PATCH
+ py = ay + ah / 2 + (ah - 2*ih) * (m->mfact / 2.0) + ih / 2;
+ #else
+ py = ay + ah / 2 + ah * m->mfact / 2.0;
+ #endif // VANITYGAPS_PATCH
+ } else { // vertical split
+ #if VANITYGAPS_PATCH
+ px = ax + aw / 2 + (aw - 2*iv) * m->mfact / 2.0 + iv / 2;
+ #else
+ px = ax + aw / 2 + aw * m->mfact / 2.0;
+ #endif // VANITYGAPS_PATCH
+ py = ay + ah / 2;
+ }
+ } else if (horizontal) {
+ px = ax + aw / 2;
+ if (mirror)
+ #if VANITYGAPS_PATCH
+ py = ay + (ah - ih) * (1.0 - m->mfact) + ih / 2;
+ #else
+ py = ay + (ah * (1.0 - m->mfact));
+ #endif // VANITYGAPS_PATCH
+ else
+ #if VANITYGAPS_PATCH
+ py = ay + ((ah - ih) * m->mfact) + ih / 2;
+ #else
+ py = ay + (ah * m->mfact);
+ #endif // VANITYGAPS_PATCH
+ } else { // vertical split
+ if (mirror)
+ #if VANITYGAPS_PATCH
+ px = ax + (aw - iv) * (1.0 - m->mfact) + iv / 2;
+ #else
+ px = ax + (aw * m->mfact);
+ #endif // VANITYGAPS_PATCH
+ else
+ #if VANITYGAPS_PATCH
+ px = ax + ((aw - iv) * m->mfact) + iv / 2;
+ #else
+ px = ax + (aw * m->mfact);
+ #endif // VANITYGAPS_PATCH
+ py = ay + ah / 2;
+ }
+
+ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
+ None, cursor[horizontal ? CurResizeVertArrow : CurResizeHorzArrow]->cursor, CurrentTime) != GrabSuccess)
+ return;
+ XWarpPointer(dpy, None, root, 0, 0, 0, 0, px, py);
+
+ do {
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
+ switch(ev.type) {
+ case ConfigureRequest:
+ case Expose:
+ case MapRequest:
+ handler[ev.type](&ev);
+ break;
+ case MotionNotify:
+ if ((ev.xmotion.time - lasttime) <= (1000 / 40))
+ continue;
+ if (lasttime != 0) {
+ px = ev.xmotion.x;
+ py = ev.xmotion.y;
+ }
+ lasttime = ev.xmotion.time;
+
+ #if VANITYGAPS_PATCH
+ if (center)
+ if (horizontal)
+ if (py - ay > ah / 2)
+ fact = (double) 1.0 - (ay + ah - py - ih / 2) * 2 / (double) (ah - 2*ih);
+ else
+ fact = (double) 1.0 - (py - ay - ih / 2) * 2 / (double) (ah - 2*ih);
+ else
+ if (px - ax > aw / 2)
+ fact = (double) 1.0 - (ax + aw - px - iv / 2) * 2 / (double) (aw - 2*iv);
+ else
+ fact = (double) 1.0 - (px - ax - iv / 2) * 2 / (double) (aw - 2*iv);
+ else
+ if (horizontal)
+ fact = (double) (py - ay - ih / 2) / (double) (ah - ih);
+ else
+ fact = (double) (px - ax - iv / 2) / (double) (aw - iv);
+ #else
+ if (center)
+ if (horizontal)
+ if (py - ay > ah / 2)
+ fact = (double) 1.0 - (ay + ah - py) * 2 / (double) ah;
+ else
+ fact = (double) 1.0 - (py - ay) * 2 / (double) ah;
+ else
+ if (px - ax > aw / 2)
+ fact = (double) 1.0 - (ax + aw - px) * 2 / (double) aw;
+ else
+ fact = (double) 1.0 - (px - ax) * 2 / (double) aw;
+ else
+ if (horizontal)
+ fact = (double) (py - ay) / (double) ah;
+ else
+ fact = (double) (px - ax) / (double) aw;
+ #endif // VANITYGAPS_PATCH
+
+ if (!center && mirror)
+ fact = 1.0 - fact;
+
+ setmfact(&((Arg) { .f = 1.0 + fact }));
+ px = ev.xmotion.x;
+ py = ev.xmotion.y;
+ break;
+ }
+ } while (ev.type != ButtonRelease);
+
+ XUngrabPointer(dpy, CurrentTime);
+ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
void
drawbar(Monitor *m)
{
@@ -1566,6 +1790,8 @@ setup(void)
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
+ cursor[CurResizeHorzArrow] = drw_cur_create(drw, XC_sb_h_double_arrow);
+ cursor[CurResizeVertArrow] = drw_cur_create(drw, XC_sb_v_double_arrow);
/* init appearance */
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
for (i = 0; i < LENGTH(colors); i++)
--
2.45.2