You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
patches/dwm/dwm-resizecorners-6.2.diff

90 lines
2.9 KiB
Diff

From 7e64cf33b56a4ad51a12f6e391c224defdf62255 Mon Sep 17 00:00:00 2001
From: bakkeby <bakkeby@gmail.com>
Date: Tue, 7 Apr 2020 12:36:21 +0200
Subject: [PATCH] Resize a floating window from any corner
By default, windows only from the bottom right corner.
With this patch the mouse is warped to the nearest corner and you
resize from there.
Refer to https://dwm.suckless.org/patches/resizecorners/
Authors:
dusty - dusty@teknik.io
Klemens Nanni kl3@posteo.org (6.1 version)
---
dwm.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/dwm.c b/dwm.c
index 4465af1..9922271 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1291,9 +1291,14 @@ void
resizemouse(const Arg *arg)
{
int ocx, ocy, nw, nh;
+ int ocx2, ocy2, nx, ny;
Client *c;
Monitor *m;
XEvent ev;
+ int horizcorner, vertcorner;
+ int di;
+ unsigned int dui;
+ Window dummy;
Time lasttime = 0;
if (!(c = selmon->sel))
@@ -1303,10 +1308,19 @@ resizemouse(const Arg *arg)
restack(selmon);
ocx = c->x;
ocy = c->y;
+ ocx2 = c->x + c->w;
+ ocy2 = c->y + c->h;
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
return;
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
+ if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui))
+ return;
+ horizcorner = nx < c->w / 2;
+ vertcorner = ny < c->h / 2;
+ XWarpPointer (dpy, None, c->win, 0, 0, 0, 0,
+ horizcorner ? (-c->bw) : (c->w + c->bw - 1),
+ vertcorner ? (-c->bw) : (c->h + c->bw - 1));
+
do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch(ev.type) {
@@ -1322,6 +1336,11 @@ resizemouse(const Arg *arg)
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
+ nx = horizcorner ? ev.xmotion.x : c->x;
+ ny = vertcorner ? ev.xmotion.y : c->y;
+ nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1);
+ nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1);
+
if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
{
@@ -1330,11 +1349,13 @@ resizemouse(const Arg *arg)
togglefloating(NULL);
}
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
- resize(c, c->x, c->y, nw, nh, 1);
+ resize(c, nx, ny, nw, nh, 1);
break;
}
} while (ev.type != ButtonRelease);
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
+ horizcorner ? (-c->bw) : (c->w + c->bw - 1),
+ vertcorner ? (-c->bw) : (c->h + c->bw - 1));
XUngrabPointer(dpy, CurrentTime);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
--
2.19.1