Add resize corners

This commit is contained in:
Chay 2024-02-28 09:48:00 +02:00
parent 86ef744181
commit 3903c59f8d
2 changed files with 24 additions and 5 deletions

View file

@ -18,3 +18,4 @@ necessary as root):
- Fullscreen
- Preserve on restart
- Pertag with selection
- Resize corners

28
dwm.c
View file

@ -1455,9 +1455,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))
@ -1467,10 +1472,18 @@ 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) {
@ -1484,8 +1497,11 @@ resizemouse(const Arg *arg)
continue;
lasttime = ev.xmotion.time;
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)
{
@ -1494,11 +1510,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) {