110 lines
2.6 KiB
C
110 lines
2.6 KiB
C
|
|
void
|
||
|
|
dragmfact(const Arg *arg)
|
||
|
|
{
|
||
|
|
unsigned int n;
|
||
|
|
int py, px; // pointer coordinates
|
||
|
|
int ax, ay, aw, ah; // area position, width and height
|
||
|
|
int center = 0, horizontal = 0, mirror = 0, fixed = 0; // layout configuration
|
||
|
|
double fact;
|
||
|
|
Monitor *m;
|
||
|
|
XEvent ev;
|
||
|
|
Time lasttime = 0;
|
||
|
|
|
||
|
|
m = selmon;
|
||
|
|
|
||
|
|
Client *c;
|
||
|
|
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||
|
|
|
||
|
|
ax = m->wx;
|
||
|
|
ay = m->wy;
|
||
|
|
ah = m->wh;
|
||
|
|
aw = m->ww;
|
||
|
|
|
||
|
|
if (!n)
|
||
|
|
return;
|
||
|
|
|
||
|
|
/* do not allow mfact to be modified under certain conditions */
|
||
|
|
if (!m->lt[m->sellt]->arrange // floating layout
|
||
|
|
|| (!fixed && m->nmaster && n <= m->nmaster) // no master
|
||
|
|
|| m->lt[m->sellt]->arrange == &monocle
|
||
|
|
|| m->lt[m->sellt]->arrange == &grid
|
||
|
|
)
|
||
|
|
return;
|
||
|
|
|
||
|
|
if (center) {
|
||
|
|
if (horizontal) {
|
||
|
|
px = ax + aw / 2;
|
||
|
|
py = ay + ah / 2 + ah * m->mfact / 2.0;
|
||
|
|
} else { // vertical split
|
||
|
|
px = ax + aw / 2 + aw * m->mfact / 2.0;
|
||
|
|
py = ay + ah / 2;
|
||
|
|
}
|
||
|
|
} else if (horizontal) {
|
||
|
|
px = ax + aw / 2;
|
||
|
|
if (mirror)
|
||
|
|
py = ay + (ah * (1.0 - m->mfact));
|
||
|
|
else
|
||
|
|
py = ay + (ah * m->mfact);
|
||
|
|
} else { // vertical split
|
||
|
|
if (mirror)
|
||
|
|
px = ax + (aw * m->mfact);
|
||
|
|
else
|
||
|
|
px = ax + (aw * m->mfact);
|
||
|
|
py = ay + ah / 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||
|
|
None, cursor[horizontal ? CurResizeVertArrow : CurResizeHorzArrow]->cursor, CurrentTime) != GrabSuccess)
|
||
|
|
return;
|
||
|
|
|
||
|
|
XWarpPointer(dpy, None, root, 0, 0, 0, 0, px, py);
|
||
|
|
|
||
|
|
do {
|
||
|
|
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
|
||
|
|
switch(ev.type) {
|
||
|
|
case ConfigureRequest:
|
||
|
|
case Expose:
|
||
|
|
case MapRequest:
|
||
|
|
handler[ev.type](&ev);
|
||
|
|
break;
|
||
|
|
case MotionNotify:
|
||
|
|
if ((ev.xmotion.time - lasttime) <= (1000 / 40))
|
||
|
|
continue;
|
||
|
|
if (lasttime != 0) {
|
||
|
|
px = ev.xmotion.x;
|
||
|
|
py = ev.xmotion.y;
|
||
|
|
}
|
||
|
|
lasttime = ev.xmotion.time;
|
||
|
|
|
||
|
|
if (center)
|
||
|
|
if (horizontal)
|
||
|
|
if (py - ay > ah / 2)
|
||
|
|
fact = (double) 1.0 - (ay + ah - py) * 2 / (double) ah;
|
||
|
|
else
|
||
|
|
fact = (double) 1.0 - (py - ay) * 2 / (double) ah;
|
||
|
|
else
|
||
|
|
if (px - ax > aw / 2)
|
||
|
|
fact = (double) 1.0 - (ax + aw - px) * 2 / (double) aw;
|
||
|
|
else
|
||
|
|
fact = (double) 1.0 - (px - ax) * 2 / (double) aw;
|
||
|
|
else
|
||
|
|
if (horizontal)
|
||
|
|
fact = (double) (py - ay) / (double) ah;
|
||
|
|
else
|
||
|
|
fact = (double) (px - ax) / (double) aw;
|
||
|
|
|
||
|
|
if (!center && mirror)
|
||
|
|
fact = 1.0 - fact;
|
||
|
|
|
||
|
|
setmfact(&((Arg) { .f = 1.0 + fact }));
|
||
|
|
px = ev.xmotion.x;
|
||
|
|
py = ev.xmotion.y;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
} while (ev.type != ButtonRelease);
|
||
|
|
|
||
|
|
XUngrabPointer(dpy, CurrentTime);
|
||
|
|
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||
|
|
}
|
||
|
|
|