Improve code style of mouse move and resize
This commit is contained in:
parent
5bc2b252c0
commit
1eee271069
143
dwm.c
143
dwm.c
|
@ -1282,56 +1282,75 @@ monocle(Monitor *m)
|
||||||
void
|
void
|
||||||
movemouse(const Arg *arg)
|
movemouse(const Arg *arg)
|
||||||
{
|
{
|
||||||
int x, y, ocx, ocy, nx, ny;
|
Client *const c = selmon->sel;
|
||||||
Client *c;
|
if (c == NULL) return;
|
||||||
Monitor *m;
|
|
||||||
XEvent ev;
|
restack(selmon);
|
||||||
Time lasttime = 0;
|
|
||||||
|
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||||
|
None, cursor[CurMove]->cursor, CurrentTime)
|
||||||
|
!= GrabSuccess)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
if (!getrootptr(&x, &y)) return;
|
||||||
|
|
||||||
const unsigned int snap_distance = settings_get_snap_distance();
|
const unsigned int snap_distance = settings_get_snap_distance();
|
||||||
|
const int ocx = c->x;
|
||||||
|
const int ocy = c->y;
|
||||||
|
|
||||||
|
Time lasttime = 0;
|
||||||
|
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
if (!(c = selmon->sel))
|
|
||||||
return;
|
|
||||||
restack(selmon);
|
|
||||||
ocx = c->x;
|
|
||||||
ocy = c->y;
|
|
||||||
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
|
||||||
None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
|
|
||||||
return;
|
|
||||||
if (!getrootptr(&x, &y))
|
|
||||||
return;
|
|
||||||
do {
|
do {
|
||||||
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
|
XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||||||
switch(ev.type) {
|
|
||||||
|
switch (ev.type) {
|
||||||
case ConfigureRequest:
|
case ConfigureRequest:
|
||||||
case Expose:
|
case Expose:
|
||||||
case MapRequest:
|
case MapRequest:
|
||||||
handler[ev.type](&ev);
|
handler[ev.type](&ev);
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
if ((ev.xmotion.time - lasttime) <= (1000 / 60))
|
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue;
|
||||||
continue;
|
|
||||||
lasttime = ev.xmotion.time;
|
lasttime = ev.xmotion.time;
|
||||||
|
|
||||||
nx = ocx + (ev.xmotion.x - x);
|
int nx = ocx + (ev.xmotion.x - x);
|
||||||
ny = ocy + (ev.xmotion.y - y);
|
int ny = ocy + (ev.xmotion.y - y);
|
||||||
if (abs(selmon->wx - nx) < snap_distance)
|
|
||||||
|
if (abs(selmon->wx - nx) < snap_distance) {
|
||||||
nx = selmon->wx;
|
nx = selmon->wx;
|
||||||
else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap_distance)
|
} else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap_distance) {
|
||||||
nx = selmon->wx + selmon->ww - WIDTH(c);
|
nx = selmon->wx + selmon->ww - WIDTH(c);
|
||||||
if (abs(selmon->wy - ny) < snap_distance)
|
}
|
||||||
|
|
||||||
|
if (abs(selmon->wy - ny) < snap_distance) {
|
||||||
ny = selmon->wy;
|
ny = selmon->wy;
|
||||||
else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap_distance)
|
} else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap_distance) {
|
||||||
ny = selmon->wy + selmon->wh - HEIGHT(c);
|
ny = selmon->wy + selmon->wh - HEIGHT(c);
|
||||||
if (!c->isfloating && (abs(nx - c->x) > snap_distance || abs(ny - c->y) > snap_distance))
|
}
|
||||||
|
|
||||||
|
if (!c->isfloating && (abs(nx - c->x) > snap_distance || abs(ny - c->y) > snap_distance)) {
|
||||||
togglefloating(NULL);
|
togglefloating(NULL);
|
||||||
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
}
|
||||||
|
|
||||||
|
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
|
||||||
resize(c, nx, ny, c->w, c->h, c->bw, 1);
|
resize(c, nx, ny, c->w, c->h, c->bw, 1);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (ev.type != ButtonRelease);
|
} while (ev.type != ButtonRelease);
|
||||||
|
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
|
|
||||||
|
Monitor *const m = recttomon(c->x, c->y, c->w, c->h);
|
||||||
|
|
||||||
|
if (m != selmon) {
|
||||||
sendmon(c, m);
|
sendmon(c, m);
|
||||||
selmon = m;
|
selmon = m;
|
||||||
focus(NULL);
|
focus(NULL);
|
||||||
|
@ -1517,53 +1536,71 @@ resizeclient(Client *c, int x, int y, int w, int h, int bw)
|
||||||
void
|
void
|
||||||
resizemouse(const Arg *arg)
|
resizemouse(const Arg *arg)
|
||||||
{
|
{
|
||||||
int ocx, ocy, nw, nh;
|
Client *const c = selmon->sel;
|
||||||
Client *c;
|
if (c == NULL) return;
|
||||||
Monitor *m;
|
|
||||||
XEvent ev;
|
restack(selmon);
|
||||||
Time lasttime = 0;
|
|
||||||
|
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||||
|
None, cursor[CurResize]->cursor, CurrentTime)
|
||||||
|
!= GrabSuccess)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
||||||
|
|
||||||
const unsigned int snap_distance = settings_get_snap_distance();
|
const unsigned int snap_distance = settings_get_snap_distance();
|
||||||
|
const int ocx = c->x;
|
||||||
|
const int ocy = c->y;
|
||||||
|
|
||||||
|
Time lasttime = 0;
|
||||||
|
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
if (!(c = selmon->sel))
|
|
||||||
return;
|
|
||||||
restack(selmon);
|
|
||||||
ocx = c->x;
|
|
||||||
ocy = c->y;
|
|
||||||
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
|
||||||
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
|
|
||||||
return;
|
|
||||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
|
||||||
do {
|
do {
|
||||||
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
|
XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||||||
switch(ev.type) {
|
|
||||||
|
switch (ev.type) {
|
||||||
case ConfigureRequest:
|
case ConfigureRequest:
|
||||||
case Expose:
|
case Expose:
|
||||||
case MapRequest:
|
case MapRequest:
|
||||||
handler[ev.type](&ev);
|
handler[ev.type](&ev);
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
if ((ev.xmotion.time - lasttime) <= (1000 / 60))
|
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue;
|
||||||
continue;
|
|
||||||
lasttime = ev.xmotion.time;
|
lasttime = ev.xmotion.time;
|
||||||
|
|
||||||
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
|
const int nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
|
||||||
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
|
const int nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
|
||||||
if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
|
|
||||||
&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
|
if (c->mon->wx + nw >= selmon->wx &&
|
||||||
|
c->mon->wx + nw <= selmon->wx + selmon->ww &&
|
||||||
|
c->mon->wy + nh >= selmon->wy &&
|
||||||
|
c->mon->wy + nh <= selmon->wy + selmon->wh)
|
||||||
{
|
{
|
||||||
if (!c->isfloating && (abs(nw - c->w) > snap_distance || abs(nh - c->h) > snap_distance))
|
if (!c->isfloating && (abs(nw - c->w) > snap_distance || abs(nh - c->h) > snap_distance)) {
|
||||||
togglefloating(NULL);
|
togglefloating(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
|
||||||
|
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
|
||||||
resize(c, c->x, c->y, nw, nh, c->bw, 1);
|
resize(c, c->x, c->y, nw, nh, c->bw, 1);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (ev.type != ButtonRelease);
|
} while (ev.type != ButtonRelease);
|
||||||
|
|
||||||
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
|
||||||
XUngrabPointer(dpy, CurrentTime);
|
XUngrabPointer(dpy, CurrentTime);
|
||||||
|
|
||||||
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||||||
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
|
|
||||||
|
Monitor *const m = recttomon(c->x, c->y, c->w, c->h);
|
||||||
|
|
||||||
|
if (m != selmon) {
|
||||||
sendmon(c, m);
|
sendmon(c, m);
|
||||||
selmon = m;
|
selmon = m;
|
||||||
focus(NULL);
|
focus(NULL);
|
||||||
|
|
Loading…
Reference in New Issue