sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-resizecorners-6.5.diff (2748B)


      1 Author: Chris Noxz <chris@noxz.tech>
      2 
      3 diff -up ../dwm-6.5/dwm.c ./dwm.c
      4 --- ../dwm-6.5/dwm.c	2024-03-19 12:24:52.000000000 +0100
      5 +++ ./dwm.c	2024-06-21 14:06:47.127064311 +0200
      6 @@ -1301,9 +1301,14 @@ void
      7  resizemouse(const Arg *arg)
      8  {
      9  	int ocx, ocy, nw, nh;
     10 +	int ocx2, ocy2, nx, ny;
     11  	Client *c;
     12  	Monitor *m;
     13  	XEvent ev;
     14 +	int horizcorner, vertcorner;
     15 +	int di;
     16 +	unsigned int dui;
     17 +	Window dummy;
     18  	Time lasttime = 0;
     19  
     20  	if (!(c = selmon->sel))
     21 @@ -1313,10 +1318,18 @@ resizemouse(const Arg *arg)
     22  	restack(selmon);
     23  	ocx = c->x;
     24  	ocy = c->y;
     25 +	ocx2 = c->x + c->w;
     26 +	ocy2 = c->y + c->h;
     27  	if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
     28  		None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
     29  		return;
     30 -	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
     31 +	if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui))
     32 +		return;
     33 +	horizcorner = nx < c->w / 2;
     34 +	vertcorner  = ny < c->h / 2;
     35 +	XWarpPointer (dpy, None, c->win, 0, 0, 0, 0,
     36 +			horizcorner ? (-c->bw) : (c->w + c->bw -1),
     37 +			vertcorner  ? (-c->bw) : (c->h + c->bw -1));
     38  	do {
     39  		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
     40  		switch(ev.type) {
     41 @@ -1330,8 +1343,16 @@ resizemouse(const Arg *arg)
     42  				continue;
     43  			lasttime = ev.xmotion.time;
     44  
     45 -			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
     46 -			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
     47 +			nx = horizcorner && ocx2 - ev.xmotion.x >= c->minw ? ev.xmotion.x : c->x;
     48 +			ny = vertcorner && ocy2 - ev.xmotion.y >= c->minh ? ev.xmotion.y : c->y;
     49 +			nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1);
     50 +			nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1);
     51 +
     52 +			if (horizcorner && ev.xmotion.x > ocx2)
     53 +				nx = ocx2 - (nw = c->minw);
     54 +			if (vertcorner && ev.xmotion.y > ocy2)
     55 +				ny = ocy2 - (nh = c->minh);
     56 +
     57  			if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
     58  			&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
     59  			{
     60 @@ -1340,11 +1361,13 @@ resizemouse(const Arg *arg)
     61  					togglefloating(NULL);
     62  			}
     63  			if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
     64 -				resize(c, c->x, c->y, nw, nh, 1);
     65 +				resize(c, nx, ny, nw, nh, 1);
     66  			break;
     67  		}
     68  	} while (ev.type != ButtonRelease);
     69 -	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
     70 +	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
     71 +		      horizcorner ? (-c->bw) : (c->w + c->bw - 1),
     72 +		      vertcorner ? (-c->bw) : (c->h + c->bw - 1));
     73  	XUngrabPointer(dpy, CurrentTime);
     74  	while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
     75 	if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {