some polishing in tileh/tilev 831428b0
Anselm R Garbe · 2008-03-13 13:59 1 file(s) · +50 −52
dwm.c +50 −52
117 117
void configure(Client *c);
118 118
void configurenotify(XEvent *e);
119 119
void configurerequest(XEvent *e);
120 +
unsigned int counttiled(void);
120 121
void destroynotify(XEvent *e);
121 122
void detach(Client *c);
122 123
void detachstack(Client *c);
170 171
unsigned int textw(const char *text);
171 172
void tileh(void);
172 173
void tilehstack(unsigned int n);
173 -
unsigned int tilemaster(void);
174 +
Client *tilemaster(unsigned int n);
175 +
void tileresize(Client *c, int x, int y, int w, int h);
174 176
void tilev(void);
175 177
void tilevstack(unsigned int n);
176 178
void togglefloating(const char *arg);
456 458
		XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
457 459
	}
458 460
	XSync(dpy, False);
461 +
}
462 +
463 +
unsigned int
464 +
counttiled(void) {
465 +
	unsigned int n;
466 +
	Client *c;
467 +
468 +
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
469 +
	return n;
459 470
}
460 471
461 472
void
1579 1590
}
1580 1591
1581 1592
void
1582 -
tileresize(Client *c, int x, int y, int w, int h) {
1583 -
	resize(c, x, y, w, h, RESIZEHINTS);
1584 -
	if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
1585 -
		/* client doesn't accept size constraints */
1586 -
		resize(c, x, y, w, h, False);
1587 -
}
1588 -
1589 -
void
1590 1593
tileh(void) {
1591 -
	tilehstack(tilemaster());
1592 -
}
1593 -
1594 -
void
1595 -
tilehstack(unsigned int n) {
1596 -
	int i, x, w;
1594 +
	int x, w;
1595 +
	unsigned int i, n = counttiled();
1597 1596
	Client *c;
1598 1597
1599 1598
	if(n == 0)
1600 1599
		return;
1600 +
	c = tilemaster(n);
1601 +
	if(--n == 0)
1602 +
		return;
1601 1603
1602 1604
	x = tx;
1603 1605
	w = tw / n;
1604 1606
	if(w < bh)
1605 1607
		w = tw;
1606 1608
1607 -
	for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++)
1608 -
		if(i > 0) {
1609 -
			if(i > 1 && i == n) /* remainder */
1610 -
				tileresize(c, x, ty, (tx + tw) - x - 2 * c->border,
1611 -
				              th - 2 * c->border);
1612 -
			else
1613 -
				tileresize(c, x, ty, w - 2 * c->border,
1614 -
				              th - 2 * c->border);
1615 -
			if(w != tw)
1616 -
				x = c->x + c->w + 2 * c->border;
1617 -
		}
1609 +
	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
1610 +
		if(i + 1 == n) /* remainder */
1611 +
			tileresize(c, x, ty, (tx + tw) - x - 2 * c->border, th - 2 * c->border);
1612 +
		else
1613 +
			tileresize(c, x, ty, w - 2 * c->border, th - 2 * c->border);
1614 +
		if(w != tw)
1615 +
			x = c->x + c->w + 2 * c->border;
1616 +
	}
1618 1617
}
1619 1618
1620 -
unsigned int
1621 -
tilemaster(void) {
1622 -
	unsigned int n;
1623 -
	Client *c, *mc;
1619 +
Client *
1620 +
tilemaster(unsigned int n) {
1621 +
	Client *c = nexttiled(clients);
1624 1622
1625 -
	for(n = 0, mc = c = nexttiled(clients); c; c = nexttiled(c->next))
1626 -
		n++;
1627 -
	if(n == 0)
1628 -
		return 0;
1629 1623
	if(n == 1)
1630 -
		tileresize(mc, mox, moy, mow - 2 * mc->border, moh - 2 * mc->border);
1624 +
		tileresize(c, mox, moy, mow - 2 * c->border, moh - 2 * c->border);
1631 1625
	else
1632 -
		tileresize(mc, mx, my, mw - 2 * mc->border, mh - 2 * mc->border);
1633 -
	return n - 1;
1626 +
		tileresize(c, mx, my, mw - 2 * c->border, mh - 2 * c->border);
1627 +
	return c;
1634 1628
}
1635 1629
1636 1630
void
1637 -
tilev(void) {
1638 -
	tilevstack(tilemaster());
1631 +
tileresize(Client *c, int x, int y, int w, int h) {
1632 +
	resize(c, x, y, w, h, RESIZEHINTS);
1633 +
	if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
1634 +
		/* client doesn't accept size constraints */
1635 +
		resize(c, x, y, w, h, False);
1639 1636
}
1640 1637
1641 1638
void
1642 -
tilevstack(unsigned int n) {
1643 -
	int i, y, h;
1639 +
tilev(void) {
1640 +
	int y, h;
1641 +
	unsigned int i, n = counttiled();
1644 1642
	Client *c;
1645 1643
1646 1644
	if(n == 0)
1647 1645
		return;
1646 +
	c = tilemaster(n);
1647 +
	if(--n == 0)
1648 +
		return;
1648 1649
1649 1650
	y = ty;
1650 1651
	h = th / n;
1651 1652
	if(h < bh)
1652 1653
		h = th;
1653 1654
1654 -
	for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++)
1655 -
		if(i > 0) {
1656 -
			if(i > 1 && i == n) /* remainder */
1657 -
				tileresize(c, tx, y, tw - 2 * c->border,
1658 -
				              (ty + th) - y - 2 * c->border);
1659 -
			else
1660 -
				tileresize(c, tx, y, tw - 2 * c->border,
1661 -
				              h - 2 * c->border);
1662 -
			if(h != th)
1663 -
				y = c->y + c->h + 2 * c->border;
1664 -
		}
1655 +
	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
1656 +
		if(i + 1 == n) /* remainder */
1657 +
			tileresize(c, tx, y, tw - 2 * c->border, (ty + th) - y - 2 * c->border);
1658 +
		else
1659 +
			tileresize(c, tx, y, tw - 2 * c->border, h - 2 * c->border);
1660 +
		if(h != th)
1661 +
			y = c->y + c->h + 2 * c->border;
1662 +
	}
1665 1663
}
1666 1664
1667 1665
void