dwm-moveresize-6.0.diff (2025B)
1 Author: Jan Christoph Ebersbach <jceb@e-jc.de> 2 URL: http://dwm.suckless.org/patches/historical/moveresize 3 These patches provide helper functions for moving and resizing floating windows 4 using keybindings. 5 6 diff -r ec4baab78314 moveresize.c 7 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8 +++ b/moveresize.c Fri Apr 06 08:23:15 2012 +0200 9 @@ -0,0 +1,64 @@ 10 +void 11 +moveresize(const Arg *arg) { 12 + /* only floating windows can be moved */ 13 + Client *c; 14 + c = selmon->sel; 15 + int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh; 16 + char xAbs, yAbs, wAbs, hAbs; 17 + int msx, msy, dx, dy, nmx, nmy; 18 + unsigned int dui; 19 + Window dummy; 20 + 21 + if (!c || !arg) 22 + return; 23 + if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) 24 + return; 25 + if(sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8) 26 + return; 27 + /* compute new window position; prevent window from be positioned outside the current monitor */ 28 + nw = c->w + w; 29 + if(wAbs == 'W') 30 + nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw; 31 + 32 + nh = c->h + h; 33 + if(hAbs == 'H') 34 + nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw; 35 + 36 + nx = c->x + x; 37 + if(xAbs == 'X') { 38 + if(x < selmon->mx) 39 + nx = selmon->mx; 40 + else if(x > selmon->mx + selmon->mw) 41 + nx = selmon->mx + selmon->mw - nw - 2 * c->bw; 42 + else 43 + nx = x; 44 + } 45 + 46 + ny = c->y + y; 47 + if(yAbs == 'Y') { 48 + if(y < selmon->my) 49 + ny = selmon->my; 50 + else if(y > selmon->my + selmon->mh) 51 + ny = selmon->my + selmon->mh - nh - 2 * c->bw; 52 + else 53 + ny = y; 54 + } 55 + 56 + ox = c->x; 57 + oy = c->y; 58 + ow = c->w; 59 + oh = c->h; 60 + 61 + XRaiseWindow(dpy, c->win); 62 + Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui); 63 + resize(c, nx, ny, nw, nh, True); 64 + 65 + /* move cursor along with the window to avoid problems caused by the sloppy focus */ 66 + if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy) 67 + { 68 + nmx = c->x - ox + c->w - ow; 69 + nmy = c->y - oy + c->h - oh; 70 + XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy); 71 + } 72 +} 73 +