2
0
mirror of https://github.com/bakkeby/patches synced 2024-11-13 07:10:31 +00:00
patches/dwm/dwm-dragfact-6.3.diff

162 lines
4.8 KiB
Diff

From a949d129b7e51bcda7372cfc304ad081d66445d6 Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 12 Sep 2022 12:47:08 +0200
Subject: [PATCH 2/2] Adding dragfact patch (combines dragmfact and dragcfact)
---
config.def.h | 3 +-
dwm.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 5b0cfde..3889a18 100644
--- a/config.def.h
+++ b/config.def.h
@@ -110,7 +110,8 @@ static Button buttons[] = {
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
- { ClkClientWin, MODKEY, Button3, resizemouse, {0} },
+ { ClkClientWin, MODKEY, Button3, resizeorfacts, {0} },
+ { ClkClientWin, MODKEY|ShiftMask, Button3, resizemouse, {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 bcb155d..30e64ac 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, CurDragFact, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
@@ -162,6 +162,7 @@ static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
static Monitor *dirtomon(int dir);
+static void dragfact(const Arg *arg);
static void drawbar(Monitor *m);
static void drawbars(void);
static void enternotify(XEvent *e);
@@ -193,6 +194,7 @@ static Monitor *recttomon(int x, int y, int w, int h);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
+static void resizeorfacts(const Arg *arg);
static void restack(Monitor *m);
static void run(void);
static void scan(void);
@@ -695,6 +697,75 @@ dirtomon(int dir)
return m;
}
+void
+dragfact(const Arg *arg)
+{
+ unsigned int n;
+ int px, py; // pointer coordinates
+ int dist_x, dist_y;
+ int horizontal = 0; // layout configuration
+ float mfact, cfact, cf, cw, ch, mw, mh;
+ Client *c;
+ Monitor *m = selmon;
+ XEvent ev;
+ Time lasttime = 0;
+
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ if (!(c = m->sel) || !n || !m->lt[m->sellt]->arrange)
+ return;
+
+ /* Add custom handling for horizontal layouts here, e.g. */
+ // if (m->lt[m->sellt]->arrange == bstack)
+ // horizontal = 1;
+
+ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
+ None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
+ return;
+
+ if (!getrootptr(&px, &py))
+ return;
+
+ cf = c->cfact;
+ ch = c->h;
+ cw = c->w;
+ mw = m->ww * m->mfact;
+ mh = m->wh * m->mfact;
+
+ 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;
+ lasttime = ev.xmotion.time;
+
+ dist_x = ev.xmotion.x - px;
+ dist_y = ev.xmotion.y - py;
+
+ if (horizontal) {
+ cfact = (float) cf * (cw + dist_x) / cw;
+ mfact = (float) (mh + dist_y) / m->wh;
+ } else {
+ cfact = (float) cf * (ch - dist_y) / ch;
+ mfact = (float) (mw + dist_x) / m->ww;
+ }
+
+ c->cfact = MAX(0.25, MIN(4.0, cfact));
+ m->mfact = MAX(0.05, MIN(0.95, mfact));
+ arrangemon(m);
+ break;
+ }
+ } while (ev.type != ButtonRelease);
+
+ XUngrabPointer(dpy, CurrentTime);
+ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
void
drawbar(Monitor *m)
{
@@ -1351,6 +1422,20 @@ resizemouse(const Arg *arg)
}
}
+void
+resizeorfacts(const Arg *arg)
+{
+ Monitor *m = selmon;
+
+ if (!m->sel)
+ return;
+
+ if (!m->lt[m->sellt]->arrange || m->sel->isfloating)
+ resizemouse(arg);
+ else
+ dragfact(arg);
+}
+
void
restack(Monitor *m)
{
@@ -1591,6 +1676,7 @@ 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[CurDragFact] = drw_cur_create(drw, XC_rightbutton);
/* init appearance */
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
for (i = 0; i < LENGTH(colors); i++)
--
2.19.1