+resizemouse(Client *c) {
+ int ocx, ocy;
+ int nw, nh;
+ Corner sticky;
+ XEvent ev;
+
+ ocx = c->x;
+ ocy = c->y;
+ if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
+ None, cursor[CurResize], CurrentTime) != GrabSuccess)
+ return;
+ c->ismax = False;
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
+ for(;;) {
+ XMaskEvent(dpy, MOUSEMASK | ExposureMask | StructureNotifyMask, &ev);
+ switch(ev.type) {
+ default:
+ break;
+ case ConfigureRequest:
+ synconfig(c, c->x, c->y, c->w, c->h, ev.xconfigure.border_width);
+ XSync(dpy, False);
+ break;
+ case Expose:
+ handler[Expose](&ev);
+ break;
+ case MotionNotify:
+ XSync(dpy, False);
+ if((nw = abs(ocx - ev.xmotion.x)))
+ c->w = nw;
+ if((nh = abs(ocy - ev.xmotion.y)))
+ c->h = nh;
+ c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
+ c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
+ if(ocx <= ev.xmotion.x)
+ sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
+ else
+ sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
+ resize(c, True, sticky);
+ break;
+ case ButtonRelease:
+ XUngrabPointer(dpy, CurrentTime);
+ return;
+ case DestroyNotify:
+ case UnmapNotify:
+ XUngrabPointer(dpy, CurrentTime);
+ handler[ev.type](&ev);
+ return;
+ }
+ }
+}
+
+static void
+buttonpress(XEvent *e) {
+ int x;
+ Arg a;
+ Client *c;
+ XButtonPressedEvent *ev = &e->xbutton;
+
+ if(barwin == ev->window) {
+ x = 0;
+ for(a.i = 0; a.i < ntags; a.i++) {
+ x += textw(tags[a.i]);
+ if(ev->x < x) {
+ if(ev->button == Button1) {
+ if(ev->state & MODKEY)
+ tag(&a);
+ else
+ view(&a);
+ }
+ else if(ev->button == Button3) {
+ if(ev->state & MODKEY)
+ toggletag(&a);
+ else
+ toggleview(&a);
+ }
+ return;
+ }
+ }
+ if(ev->x < x + bmw) {
+ if(ev->button == Button1)
+ togglemode(NULL);
+ }
+ }
+ else if((c = getclient(ev->window))) {
+ focus(c);
+ if(CLEANMASK(ev->state) != MODKEY)
+ return;
+ if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) {
+ restack(c);
+ movemouse(c);
+ }
+ else if(ev->button == Button2)
+ zoom(NULL);
+ else if(ev->button == Button3 && (arrange == dofloat || c->isfloat)) {
+ restack(c);
+ resizemouse(c);
+ }
+ }
+}
+
+static void
+configurerequest(XEvent *e) {
+ unsigned long newmask;
+ Client *c;