moveresize.c (1619B)
1 void 2 moveresize(const Arg *arg) { 3 /* only floating windows can be moved */ 4 Client *c; 5 c = selmon->sel; 6 int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh; 7 char xAbs, yAbs, wAbs, hAbs; 8 int msx, msy, dx, dy, nmx, nmy; 9 unsigned int dui; 10 Window dummy; 11 12 if (!c || !arg) 13 return; 14 if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) 15 return; 16 if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8) 17 return; 18 19 /* compute new window position; prevent window from be positioned outside the current monitor */ 20 nw = c->w + w; 21 if (wAbs == 'W') 22 nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw; 23 24 nh = c->h + h; 25 if (hAbs == 'H') 26 nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw; 27 28 nx = c->x + x; 29 if (xAbs == 'X') { 30 if (x < selmon->mx) 31 nx = selmon->mx; 32 else if (x > selmon->mx + selmon->mw) 33 nx = selmon->mx + selmon->mw - nw - 2 * c->bw; 34 else 35 nx = x; 36 } 37 38 ny = c->y + y; 39 if (yAbs == 'Y') { 40 if (y < selmon->my) 41 ny = selmon->my; 42 else if (y > selmon->my + selmon->mh) 43 ny = selmon->my + selmon->mh - nh - 2 * c->bw; 44 else 45 ny = y; 46 } 47 48 ox = c->x; 49 oy = c->y; 50 ow = c->w; 51 oh = c->h; 52 53 XRaiseWindow(dpy, c->win); 54 Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui); 55 resize(c, nx, ny, nw, nh, True); 56 57 /* move cursor along with the window to avoid problems caused by the sloppy focus */ 58 if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy) 59 { 60 nmx = c->x - ox + c->w - ow; 61 nmy = c->y - oy + c->h - oh; 62 XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy); 63 } 64 } 65