garbeam@18: /* garbeam@18: * (C)opyright MMVI Anselm R. Garbe garbeam@18: * (C)opyright MMVI Kris Maglione garbeam@18: * See LICENSE file for license details. garbeam@18: */ garbeam@18: garbeam@18: #include garbeam@18: #include garbeam@18: #include garbeam@18: garbeam@18: #include "wm.h" garbeam@18: garbeam@18: #define ButtonMask (ButtonPressMask | ButtonReleaseMask) garbeam@18: #define MouseMask (ButtonMask | PointerMotionMask) garbeam@18: garbeam@18: static void garbeam@18: mmatch(Client *c, int x1, int y1, int x2, int y2) garbeam@18: { garbeam@18: c->r[RFloat].width = abs(x1 - x2); garbeam@18: c->r[RFloat].height = abs(y1 - y2); garbeam@18: c->r[RFloat].width -= garbeam@18: (c->r[RFloat].width - c->size.base_width) % c->size.width_inc; garbeam@18: c->r[RFloat].height -= garbeam@18: (c->r[RFloat].height - c->size.base_height) % c->size.height_inc; garbeam@18: if(c->size.min_width && c->r[RFloat].width < c->size.min_width) garbeam@18: c->r[RFloat].width = c->size.min_width; garbeam@18: if(c->size.min_height && c->r[RFloat].height < c->size.min_height) garbeam@18: c->r[RFloat].height = c->size.min_height; garbeam@18: if(c->size.max_width && c->r[RFloat].width > c->size.max_width) garbeam@18: c->r[RFloat].width = c->size.max_width; garbeam@18: if(c->size.max_height && c->r[RFloat].height > c->size.max_height) garbeam@18: c->r[RFloat].height = c->size.max_height; garbeam@18: c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width; garbeam@18: c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height; garbeam@18: } garbeam@18: garbeam@18: void garbeam@18: mresize(Client *c) garbeam@18: { garbeam@18: XEvent ev; garbeam@18: int old_cx, old_cy; garbeam@18: garbeam@18: old_cx = c->r[RFloat].x; garbeam@18: old_cy = c->r[RFloat].y; garbeam@18: if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync, garbeam@18: None, cursor[CurResize], CurrentTime) != GrabSuccess) garbeam@18: return; garbeam@18: XGrabServer(dpy); garbeam@18: XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, garbeam@18: c->r[RFloat].width, c->r[RFloat].height); garbeam@18: for(;;) { garbeam@18: XMaskEvent(dpy, MouseMask, &ev); garbeam@18: switch(ev.type) { garbeam@18: default: break; garbeam@18: case MotionNotify: garbeam@18: XUngrabServer(dpy); garbeam@18: mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); garbeam@18: resize(c); garbeam@18: XGrabServer(dpy); garbeam@18: break; garbeam@18: case ButtonRelease: garbeam@18: XUngrabPointer(dpy, CurrentTime); garbeam@18: return; garbeam@18: } garbeam@18: } garbeam@18: } garbeam@18: garbeam@18: void garbeam@18: mmove(Client *c) garbeam@18: { garbeam@18: XEvent ev; garbeam@18: int x1, y1, old_cx, old_cy, di; garbeam@18: unsigned int dui; garbeam@18: Window dummy; garbeam@18: garbeam@18: old_cx = c->r[RFloat].x; garbeam@18: old_cy = c->r[RFloat].y; garbeam@18: if(XGrabPointer(dpy, c->win, False, MouseMask, GrabModeAsync, GrabModeAsync, garbeam@18: None, cursor[CurMove], CurrentTime) != GrabSuccess) garbeam@18: return; garbeam@18: XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); garbeam@18: XGrabServer(dpy); garbeam@18: for(;;) { garbeam@18: XMaskEvent(dpy, MouseMask, &ev); garbeam@18: switch (ev.type) { garbeam@18: default: break; garbeam@18: case MotionNotify: garbeam@18: XUngrabServer(dpy); garbeam@18: c->r[RFloat].x = old_cx + (ev.xmotion.x - x1); garbeam@18: c->r[RFloat].y = old_cy + (ev.xmotion.y - y1); garbeam@18: resize(c); garbeam@18: XGrabServer(dpy); garbeam@18: break; garbeam@18: case ButtonRelease: garbeam@18: XUngrabServer(dpy); garbeam@18: XUngrabPointer(dpy, CurrentTime); garbeam@18: return; garbeam@18: } garbeam@18: } garbeam@18: }