/* * (C)opyright MMVI Anselm R. Garbe * See LICENSE file for license details. */ #include "dwm.h" #include #include #include /* static */ typedef struct { unsigned long mod; KeySym keysym; void (*func)(Arg *arg); Arg arg; } Key; KEYS #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) static void movemouse(Client *c) { int x1, y1, ocx, ocy, di; unsigned int dui; Window dummy; XEvent ev; ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove], CurrentTime) != GrabSuccess) return; XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); for(;;) { XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev); switch (ev.type) { default: break; case Expose: handler[Expose](&ev); break; case MotionNotify: XSync(dpy, False); c->x = ocx + (ev.xmotion.x - x1); c->y = ocy + (ev.xmotion.y - y1); resize(c, False, TopLeft); break; case ButtonRelease: XUngrabPointer(dpy, CurrentTime); return; } } } static void 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; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); for(;;) { XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev); switch(ev.type) { default: break; case Expose: handler[Expose](&ev); break; case MotionNotify: XSync(dpy, False); if((nw = abs(ocx - ev.xmotion.x))) c->w = abs(ocx - ev.xmotion.x); if((nh = abs(ocy - ev.xmotion.y))) c->h = abs(ocy - ev.xmotion.y); 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; } } } 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(maximized || 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 synconfig(Client *c, int x, int y, int w, int h, unsigned int border) { XEvent synev; synev.type = ConfigureNotify; synev.xconfigure.display = dpy; synev.xconfigure.event = c->win; synev.xconfigure.window = c->win; synev.xconfigure.x = x; synev.xconfigure.y = y; synev.xconfigure.width = w; synev.xconfigure.height = h; synev.xconfigure.border_width = bor