dwm.c
changeset 1379 ef09cf3eee26
parent 1378 39214fe5de67
child 1380 add6eb26ebaa
equal deleted inserted replaced
1378:39214fe5de67 1379:ef09cf3eee26
    39 #ifdef XINERAMA
    39 #ifdef XINERAMA
    40 #include <X11/extensions/Xinerama.h>
    40 #include <X11/extensions/Xinerama.h>
    41 #endif
    41 #endif
    42 
    42 
    43 /* macros */
    43 /* macros */
    44 #define ADJUSTBORDER(C, BW)     if((C)->bw != (BW)) XSetWindowBorder(dpy, (C)->win, (BW));
       
    45 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    44 #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
    46 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    45 #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
    47 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    46 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
    48 #define ISVISIBLE(x)            (x->tags & tagset[seltags])
    47 #define ISVISIBLE(x)            (x->tags & tagset[seltags])
    49 #define LENGTH(x)               (sizeof x / sizeof x[0])
    48 #define LENGTH(x)               (sizeof x / sizeof x[0])
   127 	unsigned int tags;
   126 	unsigned int tags;
   128 	Bool isfloating;
   127 	Bool isfloating;
   129 } Rule;
   128 } Rule;
   130 
   129 
   131 /* function declarations */
   130 /* function declarations */
       
   131 static void adjustborder(Client *c, unsigned int bw);
   132 static void applyrules(Client *c);
   132 static void applyrules(Client *c);
   133 static void arrange(void);
   133 static void arrange(void);
   134 static void attach(Client *c);
   134 static void attach(Client *c);
   135 static void attachstack(Client *c);
   135 static void attachstack(Client *c);
   136 static void buttonpress(XEvent *e);
   136 static void buttonpress(XEvent *e);
   244 /* compile-time check if all tags fit into an unsigned int bit array. */
   244 /* compile-time check if all tags fit into an unsigned int bit array. */
   245 struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
   245 struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
   246 
   246 
   247 /* function implementations */
   247 /* function implementations */
   248 void
   248 void
       
   249 adjustborder(Client *c, unsigned int bw) {
       
   250 	XWindowChanges wc;
       
   251 
       
   252 	if(c->bw != bw) {
       
   253 		c->bw = wc.border_width = bw;
       
   254 		XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
       
   255 	}
       
   256 }
       
   257 
       
   258 void
   249 applyrules(Client *c) {
   259 applyrules(Client *c) {
   250 	unsigned int i;
   260 	unsigned int i;
   251 	Rule *r;
   261 	Rule *r;
   252 	XClassHint ch = { 0 };
   262 	XClassHint ch = { 0 };
   253 
   263 
   928 	unsigned int n;
   938 	unsigned int n;
   929 	Client *c;
   939 	Client *c;
   930 
   940 
   931 	for(n = 0, c = nexttiled(clients); c && n < 2; c = nexttiled(c->next), n++);
   941 	for(n = 0, c = nexttiled(clients); c && n < 2; c = nexttiled(c->next), n++);
   932 	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
   942 	for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
   933 		ADJUSTBORDER(c, (n == 1 ? 0 : borderpx))
   943 		adjustborder(c, n == 1 ? 0 : borderpx);
   934 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
   944 		resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
   935 	}
   945 	}
   936 }
   946 }
   937 
   947 
   938 void
   948 void
  1135 		case Expose:
  1145 		case Expose:
  1136 		case MapRequest:
  1146 		case MapRequest:
  1137 			handler[ev.type](&ev);
  1147 			handler[ev.type](&ev);
  1138 			break;
  1148 			break;
  1139 		case MotionNotify:
  1149 		case MotionNotify:
  1140 			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
  1150 			nw = MAX(ev.xmotion.x - ocx - 2*c->bw + 1, 1);
  1141 			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
  1151 			nh = MAX(ev.xmotion.y - ocy - 2*c->bw + 1, 1);
       
  1152 
  1142 			if(snap && nw >= wx && nw <= wx + ww
  1153 			if(snap && nw >= wx && nw <= wx + ww
  1143 			        && nh >= wy && nh <= wy + wh) {
  1154 			        && nh >= wy && nh <= wy + wh) {
  1144 				if(!c->isfloating && lt[sellt]->arrange
  1155 				if(!c->isfloating && lt[sellt]->arrange
  1145 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1156 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1146 					togglefloating(NULL);
  1157 					togglefloating(NULL);
  1332 void
  1343 void
  1333 showhide(Client *c) {
  1344 showhide(Client *c) {
  1334 	if(!c)
  1345 	if(!c)
  1335 		return;
  1346 		return;
  1336 	if(ISVISIBLE(c)) { /* show clients top down */
  1347 	if(ISVISIBLE(c)) { /* show clients top down */
  1337 		ADJUSTBORDER(c, borderpx)
  1348 		adjustborder(c, borderpx);
  1338 		XMoveWindow(dpy, c->win, c->x, c->y);
  1349 		XMoveWindow(dpy, c->win, c->x, c->y);
  1339 		if(!lt[sellt]->arrange || c->isfloating)
  1350 		if(!lt[sellt]->arrange || c->isfloating)
  1340 			resize(c, c->x, c->y, c->w, c->h, True);
  1351 			resize(c, c->x, c->y, c->w, c->h, True);
  1341 		showhide(c->snext);
  1352 		showhide(c->snext);
  1342 	}
  1353 	}
  1396 		return;
  1407 		return;
  1397 
  1408 
  1398 	/* master */
  1409 	/* master */
  1399 	c = nexttiled(clients);
  1410 	c = nexttiled(clients);
  1400 	mw = mfact * ww;
  1411 	mw = mfact * ww;
  1401 	ADJUSTBORDER(c, (n == 1 ? 0 : borderpx))
  1412 	adjustborder(c, n == 1 ? 0 : borderpx);
  1402 	resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
  1413 	resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
  1403 
  1414 
  1404 	if(--n == 0)
  1415 	if(--n == 0)
  1405 		return;
  1416 		return;
  1406 
  1417 
  1411 	h = wh / n;
  1422 	h = wh / n;
  1412 	if(h < bh)
  1423 	if(h < bh)
  1413 		h = wh;
  1424 		h = wh;
  1414 
  1425 
  1415 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1426 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1416 		ADJUSTBORDER(c, borderpx)
  1427 		adjustborder(c, borderpx);
  1417 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1428 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1418 		       ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints);
  1429 		       ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints);
  1419 		if(h != wh)
  1430 		if(h != wh)
  1420 			y = c->y + HEIGHT(c);
  1431 			y = c->y + HEIGHT(c);
  1421 	}
  1432 	}