re-work client_snapcalc() so it takes client and edge dimensions with

snapdist; allows for simplier snap calculations.

required for an upcoming diff for honoring gap.
This commit is contained in:
okan 2013-01-02 21:37:21 +00:00
parent 6e5dda99a6
commit 2ac65bd288
3 changed files with 14 additions and 16 deletions

View File

@ -850,19 +850,17 @@ client_inbound(struct client_ctx *cc, int x, int y)
}
int
client_snapcalc(int n, int dn, int nmax, int bwidth, int snapdist)
client_snapcalc(int n0, int n1, int e0, int e1, int snapdist)
{
int n0, n1, s0, s1;
int s0, s1;
s0 = s1 = 0;
n0 = n;
n1 = n + dn + (bwidth * 2);
if (abs(n0) <= snapdist)
s0 = -n0;
if (abs(e0 - n0) <= snapdist)
s0 = e0 - n0;
if (nmax - snapdist <= n1 && n1 <= nmax + snapdist)
s1 = nmax - n1;
if (abs(e1 - n1) <= snapdist)
s1 = e1 - n1;
/* possible to snap in both directions */
if (s0 != 0 && s1 != 0)

View File

@ -101,11 +101,11 @@ kbfunc_moveresize(struct client_ctx *cc, union arg *arg)
cc->geom.x = sc->view.w - 1;
cc->geom.x += client_snapcalc(cc->geom.x,
cc->geom.w, sc->view.w,
cc->bwidth, Conf.snapdist);
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
sc->view.x, sc->view.w, Conf.snapdist);
cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.h, sc->view.h,
cc->bwidth, Conf.snapdist);
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
sc->view.y, sc->view.h, Conf.snapdist);
client_move(cc);
xu_ptr_getpos(cc->win, &x, &y);

View File

@ -162,11 +162,11 @@ mousefunc_window_move(struct client_ctx *cc, void *arg)
cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
cc->geom.x += client_snapcalc(cc->geom.x,
cc->geom.w, sc->view.w,
cc->bwidth, Conf.snapdist);
cc->geom.x + cc->geom.w + (cc->bwidth * 2),
sc->view.x, sc->view.w, Conf.snapdist);
cc->geom.y += client_snapcalc(cc->geom.y,
cc->geom.h, sc->view.h,
cc->bwidth, Conf.snapdist);
cc->geom.y + cc->geom.h + (cc->bwidth * 2),
sc->view.y, sc->view.h, Conf.snapdist);
/* don't move more than 60 times / second */
if ((ev.xmotion.time - ltime) > (1000 / 60)) {