dwm.c
changeset 1311 47b3dbd9a7d3
parent 1310 1d52b420daa4
child 1312 95b9bfa84b57
equal deleted inserted replaced
1310:1d52b420daa4 1311:47b3dbd9a7d3
    42 #ifdef XINERAMA
    42 #ifdef XINERAMA
    43 #include <X11/extensions/Xinerama.h>
    43 #include <X11/extensions/Xinerama.h>
    44 #endif
    44 #endif
    45 
    45 
    46 /* macros */
    46 /* macros */
    47 #define MAX(a, b)       ((a) > (b) ? (a) : (b))
    47 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    48 #define MIN(a, b)       ((a) < (b) ? (a) : (b))
    48 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    49 #define BUTTONMASK      (ButtonPressMask|ButtonReleaseMask)
    49 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    50 #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
    50 #define ISVISIBLE(x)            (x->tags & tagset[seltags])
    51 #define LENGTH(x)       (sizeof x / sizeof x[0])
    51 #define LENGTH(x)               (sizeof x / sizeof x[0])
    52 #define MAXTAGLEN       16
    52 #define MAX(a, b)               ((a) > (b) ? (a) : (b))
    53 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
    53 #define MIN(a, b)               ((a) < (b) ? (a) : (b))
    54 #define TAGMASK         ((int)((1LL << LENGTH(tags)) - 1))
    54 #define MAXTAGLEN               16
    55 #define TEXTW(x)        (textnw(x, strlen(x)) + dc.font.height)
    55 #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
    56 #define ISVISIBLE(x)    (x->tags & tagset[seltags])
    56 #define TAGMASK                 ((int)((1LL << LENGTH(tags)) - 1))
       
    57 #define TEXTW(x)                (textnw(x, strlen(x)) + dc.font.height)
    57 
    58 
    58 /* enums */
    59 /* enums */
    59 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    60 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    60 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    61 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    61 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    62 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
   972 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
   973 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
   973 }
   974 }
   974 
   975 
   975 void
   976 void
   976 movemouse(const Arg *arg) {
   977 movemouse(const Arg *arg) {
   977 	int x1, y1, ocx, ocy, di, nx, ny;
   978 	int x, y, ocx, ocy, di, nx, ny;
   978 	unsigned int dui;
   979 	unsigned int dui;
   979 	Client *c;
   980 	Client *c;
   980 	Window dummy;
   981 	Window dummy;
   981 	XEvent ev;
   982 	XEvent ev;
   982 
   983 
   986 	ocx = nx = c->x;
   987 	ocx = nx = c->x;
   987 	ocy = ny = c->y;
   988 	ocy = ny = c->y;
   988 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
   989 	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
   989 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
   990 	None, cursor[CurMove], CurrentTime) != GrabSuccess)
   990 		return;
   991 		return;
   991 	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
   992 	XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
   992 	for(;;) {
   993 	for(;;) {
   993 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
   994 		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
   994 		switch (ev.type) {
   995 		switch (ev.type) {
   995 		case ButtonRelease:
   996 		case ButtonRelease:
   996 			XUngrabPointer(dpy, CurrentTime);
   997 			XUngrabPointer(dpy, CurrentTime);
  1000 		case MapRequest:
  1001 		case MapRequest:
  1001 			handler[ev.type](&ev);
  1002 			handler[ev.type](&ev);
  1002 			break;
  1003 			break;
  1003 		case MotionNotify:
  1004 		case MotionNotify:
  1004 			XSync(dpy, False);
  1005 			XSync(dpy, False);
  1005 			nx = ocx + (ev.xmotion.x - x1);
  1006 			nx = ocx + (ev.xmotion.x - x);
  1006 			ny = ocy + (ev.xmotion.y - y1);
  1007 			ny = ocy + (ev.xmotion.y - y);
  1007 			if(snap && nx >= wx && nx <= wx + ww
  1008 			if(snap && nx >= wx && nx <= wx + ww
  1008 			        && ny >= wy && ny <= wy + wh) {
  1009 			        && ny >= wy && ny <= wy + wh) {
  1009 				if(abs(wx - nx) < snap)
  1010 				if(abs(wx - nx) < snap)
  1010 					nx = wx;
  1011 					nx = wx;
  1011 				else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < snap)
  1012 				else if(abs((wx + ww) - (nx + c->w + 2 * c->bw)) < snap)
  1555 }
  1556 }
  1556 
  1557 
  1557 void
  1558 void
  1558 updategeom(void) {
  1559 updategeom(void) {
  1559 #ifdef XINERAMA
  1560 #ifdef XINERAMA
  1560 	int i;
  1561 	int n;
       
  1562 	unsigned int xidx = 0;
  1561 	XineramaScreenInfo *info = NULL;
  1563 	XineramaScreenInfo *info = NULL;
  1562 
  1564 
  1563 	/* window area geometry */
  1565 	/* window area geometry */
  1564 	if(XineramaIsActive(dpy)) {
  1566 	if(XineramaIsActive(dpy)) {
  1565 		info = XineramaQueryScreens(dpy, &i);
  1567 		info = XineramaQueryScreens(dpy, &n);
       
  1568 		if(n > 1) {
       
  1569 			int di, i, x, y;
       
  1570 			unsigned int dui;
       
  1571 			Window dummy;
       
  1572 			if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
       
  1573 				for(i = 0; i < n; i++)
       
  1574 					if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) {
       
  1575 						xidx = i;
       
  1576 						break;
       
  1577 					}
       
  1578 		}
  1566 		wx = info[xidx].x_org;
  1579 		wx = info[xidx].x_org;
  1567 		wy = showbar && topbar ?  info[xidx].y_org + bh : info[xidx].y_org;
  1580 		wy = showbar && topbar ?  info[xidx].y_org + bh : info[xidx].y_org;
  1568 		ww = info[xidx].width;
  1581 		ww = info[xidx].width;
  1569 		wh = showbar ? info[xidx].height - bh : info[xidx].height;
  1582 		wh = showbar ? info[xidx].height - bh : info[xidx].height;
  1570 		XFree(info);
  1583 		XFree(info);