dwm.c
changeset 1443 dabe14ecb5e9
parent 1440 d4f7bc21588f
child 1444 19dc2b0c61e2
equal deleted inserted replaced
1442:dfbdc1947270 1443:dabe14ecb5e9
   146 	Bool isfloating;
   146 	Bool isfloating;
   147 } Rule;
   147 } Rule;
   148 
   148 
   149 /* function declarations */
   149 /* function declarations */
   150 static void applyrules(Client *c);
   150 static void applyrules(Client *c);
   151 static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h);
   151 static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
   152 static void arrange(void);
   152 static void arrange(void);
   153 static void attach(Client *c);
   153 static void attach(Client *c);
   154 static void attachstack(Client *c);
   154 static void attachstack(Client *c);
   155 static void buttonpress(XEvent *e);
   155 static void buttonpress(XEvent *e);
   156 static void checkotherwm(void);
   156 static void checkotherwm(void);
   192 static void movemouse(const Arg *arg);
   192 static void movemouse(const Arg *arg);
   193 static Client *nexttiled(Client *c);
   193 static Client *nexttiled(Client *c);
   194 static Monitor *pointertomon(int x, int y);
   194 static Monitor *pointertomon(int x, int y);
   195 static void propertynotify(XEvent *e);
   195 static void propertynotify(XEvent *e);
   196 static void quit(const Arg *arg);
   196 static void quit(const Arg *arg);
   197 static void resize(Client *c, int x, int y, int w, int h);
   197 static void resize(Client *c, int x, int y, int w, int h, Bool interact);
   198 static void resizemouse(const Arg *arg);
   198 static void resizemouse(const Arg *arg);
   199 static void restack(Monitor *m);
   199 static void restack(Monitor *m);
   200 static void run(void);
   200 static void run(void);
   201 static void scan(void);
   201 static void scan(void);
   202 static void sendmon(Client *c, Monitor *m);
   202 static void sendmon(Client *c, Monitor *m);
   296 	}
   296 	}
   297 	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
   297 	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
   298 }
   298 }
   299 
   299 
   300 Bool
   300 Bool
   301 applysizehints(Client *c, int *x, int *y, int *w, int *h) {
   301 applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
   302 	Bool baseismin;
   302 	Bool baseismin;
   303 	Monitor *m = c->mon;
   303 	Monitor *m = c->mon;
   304 
   304 
   305 	/* set minimum possible */
   305 	/* set minimum possible */
   306 	*w = MAX(1, *w);
   306 	*w = MAX(1, *w);
   307 	*h = MAX(1, *h);
   307 	*h = MAX(1, *h);
   308 
   308 
   309 	if(*x > m->mx + m->mw)
   309 	if(interact) {
   310 		*x = m->mx + m->mw - WIDTH(c);
   310 		if(*x > sw)
   311 	if(*y > m->my + m->mh)
   311 			*x = sw - WIDTH(c);
   312 		*y = m->my + m->mh - HEIGHT(c);
   312 		if(*y > sh)
   313 	if(*x + *w + 2 * c->bw < m->mx)
   313 			*y = sh - HEIGHT(c);
   314 		*x = m->mx;
   314 		if(*x + *w + 2 * c->bw < 0)
   315 	if(*y + *h + 2 * c->bw < m->my)
   315 			*x = 0;
   316 		*y = m->my;
   316 		if(*y + *h + 2 * c->bw < 0)
       
   317 			*y = 0;
       
   318 	}
       
   319 	else {
       
   320 		if(*x > m->mx + m->mw)
       
   321 			*x = m->mx + m->mw - WIDTH(c);
       
   322 		if(*y > m->my + m->mh)
       
   323 			*y = m->my + m->mh - HEIGHT(c);
       
   324 		if(*x + *w + 2 * c->bw < m->mx)
       
   325 			*x = m->mx;
       
   326 		if(*y + *h + 2 * c->bw < m->my)
       
   327 			*y = m->my;
       
   328 	}
   317 	if(*h < bh)
   329 	if(*h < bh)
   318 		*h = bh;
   330 		*h = bh;
   319 	if(*w < bh)
   331 	if(*w < bh)
   320 		*w = bh;
   332 		*w = bh;
   321 
   333 
  1118 void
  1130 void
  1119 monocle(Monitor *m) {
  1131 monocle(Monitor *m) {
  1120 	Client *c;
  1132 	Client *c;
  1121 
  1133 
  1122 	for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
  1134 	for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
  1123 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
  1135 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
  1124 }
  1136 }
  1125 
  1137 
  1126 void
  1138 void
  1127 movemouse(const Arg *arg) {
  1139 movemouse(const Arg *arg) {
  1128 	int x, y, ocx, ocy, nx, ny;
  1140 	int x, y, ocx, ocy, nx, ny;
  1164 				if(!c->isfloating && lt[selmon->sellt]->arrange
  1176 				if(!c->isfloating && lt[selmon->sellt]->arrange
  1165 				                  && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1177 				                  && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
  1166 					togglefloating(NULL);
  1178 					togglefloating(NULL);
  1167 			}
  1179 			}
  1168 			if(!lt[selmon->sellt]->arrange || c->isfloating)
  1180 			if(!lt[selmon->sellt]->arrange || c->isfloating)
  1169 				resize(c, nx, ny, c->w, c->h);
  1181 				resize(c, nx, ny, c->w, c->h, True);
  1170 			break;
  1182 			break;
  1171 		}
  1183 		}
  1172 	}
  1184 	}
  1173 	while(ev.type != ButtonRelease);
  1185 	while(ev.type != ButtonRelease);
  1174 	XUngrabPointer(dpy, CurrentTime);
  1186 	XUngrabPointer(dpy, CurrentTime);
  1233 quit(const Arg *arg) {
  1245 quit(const Arg *arg) {
  1234 	running = False;
  1246 	running = False;
  1235 }
  1247 }
  1236 
  1248 
  1237 void
  1249 void
  1238 resize(Client *c, int x, int y, int w, int h) {
  1250 resize(Client *c, int x, int y, int w, int h, Bool interact) {
  1239 	XWindowChanges wc;
  1251 	XWindowChanges wc;
  1240 
  1252 
  1241 	if(applysizehints(c, &x, &y, &w, &h)) {
  1253 	if(applysizehints(c, &x, &y, &w, &h, interact)) {
  1242 		c->x = wc.x = x;
  1254 		c->x = wc.x = x;
  1243 		c->y = wc.y = y;
  1255 		c->y = wc.y = y;
  1244 		c->w = wc.width = w;
  1256 		c->w = wc.width = w;
  1245 		c->h = wc.height = h;
  1257 		c->h = wc.height = h;
  1246 		wc.border_width = c->bw;
  1258 		wc.border_width = c->bw;
  1284 				if(!c->isfloating && lt[selmon->sellt]->arrange
  1296 				if(!c->isfloating && lt[selmon->sellt]->arrange
  1285 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1297 				   && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
  1286 					togglefloating(NULL);
  1298 					togglefloating(NULL);
  1287 			}
  1299 			}
  1288 			if(!lt[selmon->sellt]->arrange || c->isfloating)
  1300 			if(!lt[selmon->sellt]->arrange || c->isfloating)
  1289 				resize(c, c->x, c->y, nw, nh);
  1301 				resize(c, c->x, c->y, nw, nh, True);
  1290 			break;
  1302 			break;
  1291 		}
  1303 		}
  1292 	}
  1304 	}
  1293 	while(ev.type != ButtonRelease);
  1305 	while(ev.type != ButtonRelease);
  1294 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1306 	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
  1482 	if(!c)
  1494 	if(!c)
  1483 		return;
  1495 		return;
  1484 	if(ISVISIBLE(c)) { /* show clients top down */
  1496 	if(ISVISIBLE(c)) { /* show clients top down */
  1485 		XMoveWindow(dpy, c->win, c->x, c->y);
  1497 		XMoveWindow(dpy, c->win, c->x, c->y);
  1486 		if(!lt[c->mon->sellt]->arrange || c->isfloating)
  1498 		if(!lt[c->mon->sellt]->arrange || c->isfloating)
  1487 			resize(c, c->x, c->y, c->w, c->h);
  1499 			resize(c, c->x, c->y, c->w, c->h, False);
  1488 		showhide(c->snext);
  1500 		showhide(c->snext);
  1489 	}
  1501 	}
  1490 	else { /* hide clients bottom up */
  1502 	else { /* hide clients bottom up */
  1491 		showhide(c->snext);
  1503 		showhide(c->snext);
  1492 		XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  1504 		XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  1552 		return;
  1564 		return;
  1553 
  1565 
  1554 	/* master */
  1566 	/* master */
  1555 	c = nexttiled(m->clients);
  1567 	c = nexttiled(m->clients);
  1556 	mw = m->mfact * m->ww;
  1568 	mw = m->mfact * m->ww;
  1557 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
  1569 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False);
  1558 
  1570 
  1559 	if(--n == 0)
  1571 	if(--n == 0)
  1560 		return;
  1572 		return;
  1561 
  1573 
  1562 	/* tile stack */
  1574 	/* tile stack */
  1567 	if(h < bh)
  1579 	if(h < bh)
  1568 		h = m->wh;
  1580 		h = m->wh;
  1569 
  1581 
  1570 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1582 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
  1571 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1583 		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
  1572 		       ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw));
  1584 		       ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False);
  1573 		if(h != m->wh)
  1585 		if(h != m->wh)
  1574 			y = c->y + HEIGHT(c);
  1586 			y = c->y + HEIGHT(c);
  1575 	}
  1587 	}
  1576 }
  1588 }
  1577 
  1589 
  1587 togglefloating(const Arg *arg) {
  1599 togglefloating(const Arg *arg) {
  1588 	if(!selmon->sel)
  1600 	if(!selmon->sel)
  1589 		return;
  1601 		return;
  1590 	selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
  1602 	selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
  1591 	if(selmon->sel->isfloating)
  1603 	if(selmon->sel->isfloating)
  1592 		resize(selmon->sel, selmon->sel->x, selmon->sel->y, selmon->sel->w, selmon->sel->h);
  1604 		resize(selmon->sel, selmon->sel->x, selmon->sel->y,
       
  1605 		       selmon->sel->w, selmon->sel->h, False);
  1593 	arrange();
  1606 	arrange();
  1594 }
  1607 }
  1595 
  1608 
  1596 void
  1609 void
  1597 toggletag(const Arg *arg) {
  1610 toggletag(const Arg *arg) {