moved all tile()-related stuff into tile.c which is included from config.def.h, the default dwm is now nearly independent from the arrange() algorithm in use 4246affc
Anselm R Garbe · 2008-05-17 14:38 3 file(s) · +119 −108
config.def.h +7 −7
9 9
#define SELBORDERCOLOR  "#0066ff"
10 10
#define SELBGCOLOR      "#0066ff"
11 11
#define SELFGCOLOR      "#ffffff"
12 +
#define SNAP            32    /* snap pixel */
12 13
13 14
/* tagging */
14 15
const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
19 20
};
20 21
21 22
/* layout(s) */
22 -
#define MFACT       0.55  /* master factor [0.1 .. 0.9] */
23 23
#define RESIZEHINTS True  /* False - respect size hints in tiled resizals */
24 -
#define SNAP        32    /* snap pixel */
25 -
24 +
#define MFACT       0.55  /* master factor [0.1 .. 0.9] */
25 +
#include "tile.c"
26 26
Layout layouts[] = {
27 -
	/* symbol     function */
28 -
	{ "[]=",      tile    }, /* first entry is default */
29 -
	{ "><>",      NULL    }, /* no layout function means floating behavior */
30 -
	{ "<M>",      monocle }, /* TODO: remove this */
27 +
	/* symbol     arrange  geom */
28 +
	{ "[]=",      tile,    tilegeom }, /* first entry is default */
29 +
	{ "><>",      NULL,             }, /* no layout function means floating behavior */
30 +
	{ "<M>",      monocle, NULL     }, /* TODO: remove this */
31 31
};
32 32
33 33
/* key definitions */
dwm.c +9 −101
97 97
typedef struct {
98 98
	const char *symbol;
99 99
	void (*arrange)(void);
100 +
	void (*updategeom)(void);
100 101
} Layout;
101 102
102 103
typedef struct {
152 153
void maprequest(XEvent *e);
153 154
void monocle(void);
154 155
void movemouse(Client *c);
155 -
Client *nexttiled(Client *c);
156 +
Client *nextunfloating(Client *c);
156 157
void propertynotify(XEvent *e);
157 158
void quit(const char *arg);
158 159
void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
161 162
void run(void);
162 163
void scan(void);
163 164
void setclientstate(Client *c, long state);
164 -
void setmfact(const char *arg);
165 165
void setup(void);
166 166
void spawn(const char *arg);
167 167
void tag(const char *arg);
168 168
unsigned int textnw(const char *text, unsigned int len);
169 169
unsigned int textw(const char *text);
170 -
void tileresize(Client *c, int x, int y, int w, int h);
171 -
void tile(void);
172 170
void togglefloating(const char *arg);
173 171
void togglelayout(const char *arg);
174 172
void toggletag(const char *arg);
192 190
char stext[256];
193 191
int screen, sx, sy, sw, sh;
194 192
int (*xerrorxlib)(Display *, XErrorEvent *);
195 -
int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
193 +
int bx, by, bw, bh, blw, wx, wy, ww, wh;
196 194
int seltags = 0;
197 -
double mfact;
198 195
unsigned int numlockmask = 0;
199 196
void (*handler[LASTEvent]) (XEvent *) = {
200 197
	[ButtonPress] = buttonpress,
1072 1069
}
1073 1070
1074 1071
Client *
1075 -
nexttiled(Client *c) {
1072 +
nextunfloating(Client *c) {
1076 1073
	for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next);
1077 1074
	return c;
1078 1075
}
1337 1334
			PropModeReplace, (unsigned char *)data, 2);
1338 1335
}
1339 1336
1340 -
/* TODO: move this into tile.c */
1341 -
void
1342 -
setmfact(const char *arg) {
1343 -
	double d;
1344 -
1345 -
	if(!lt->arrange) /* TODO: check this against the actual tile() function */
1346 -
		return;
1347 -
	if(!arg)
1348 -
		mfact = MFACT;
1349 -
	else {
1350 -
		d = strtod(arg, NULL);
1351 -
		if(arg[0] == '-' || arg[0] == '+')
1352 -
			d += mfact;
1353 -
		if(d < 0.1 || d > 0.9)
1354 -
			return;
1355 -
		mfact = d;
1356 -
	}
1357 -
	updategeom();
1358 -
	arrange();
1359 -
}
1360 -
1361 1337
void
1362 1338
setup(void) {
1363 1339
	unsigned int i, w;
1372 1348
	sw = DisplayWidth(dpy, screen);
1373 1349
	sh = DisplayHeight(dpy, screen);
1374 1350
	bh = dc.font.height + 2;
1375 -
	mfact = MFACT;
1376 1351
	updategeom();
1377 1352
1378 1353
	/* init atoms */
1494 1469
}
1495 1470
1496 1471
void
1497 -
tileresize(Client *c, int x, int y, int w, int h) {
1498 -
	resize(c, x, y, w, h, RESIZEHINTS);
1499 -
	if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
1500 -
		/* client doesn't accept size constraints */
1501 -
		resize(c, x, y, w, h, False);
1502 -
}
1503 -
1504 -
void
1505 -
tile(void) {
1506 -
	int y, h;
1507 -
	unsigned int i, n;
1508 -
	Client *c;
1509 -
1510 -
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
1511 -
	if(n == 0)
1512 -
		return;
1513 -
1514 -
	/* master */
1515 -
	c = nexttiled(clients);
1516 -
1517 -
	if(n == 1)
1518 -
		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
1519 -
	else
1520 -
		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
1521 -
1522 -
	if(--n == 0)
1523 -
		return;
1524 -
1525 -
	/* tile stack */
1526 -
	y = ty;
1527 -
	h = th / n;
1528 -
	if(h < bh)
1529 -
		h = th;
1530 -
1531 -
	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
1532 -
		if(i + 1 == n) /* remainder */
1533 -
			tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw);
1534 -
		else
1535 -
			tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw);
1536 -
		if(h != th)
1537 -
			y = c->y + c->h + 2 * c->bw;
1538 -
	}
1539 -
}
1540 -
1541 -
void
1542 1472
togglefloating(const char *arg) {
1543 1473
	if(!sel)
1544 1474
		return;
1646 1576
1647 1577
void
1648 1578
updategeom(void) {
1579 +
	unsigned int i;
1649 1580
1650 1581
	/* bar geometry */
1651 1582
	bx = 0;
1658 1589
	ww = sw;
1659 1590
	wh = sh - bh;
1660 1591
1661 -
	/* master area geometry */
1662 -
	mx = wx;
1663 -
	my = wy;
1664 -
	mw = mfact * ww;
1665 -
	mh = wh;
1666 -
1667 -
	/* tile area geometry */
1668 -
	tx = mx + mw;
1669 -
	ty = wy;
1670 -
	tw = ww - mw;
1671 -
	th = wh;
1592 +
	/* update layout geometries */
1593 +
	for(i = 0; i < LENGTH(layouts); i++)
1594 +
		if(layouts[i].updategeom)
1595 +
			layouts[i].updategeom();
1672 1596
}
1673 1597
1674 1598
void
1787 1711
xerrorstart(Display *dpy, XErrorEvent *ee) {
1788 1712
	otherwm = True;
1789 1713
	return -1;
1790 -
}
1791 -
1792 -
/* TODO: move this into tile.c */
1793 -
void
1794 -
zoom(const char *arg) {
1795 -
	Client *c = sel;
1796 -
1797 -
	if(c == nexttiled(clients))
1798 -
		if(!c || !(c = nexttiled(c->next)))
1799 -
			return;
1800 -
	if(lt->arrange && !sel->isfloating) { /* TODO: check this against tile() */
1801 -
		detach(c);
1802 -
		attach(c);
1803 -
		focus(c);
1804 -
	}
1805 -
	arrange();
1806 1714
}
1807 1715
1808 1716
int
tile.c (added) +103 −0
1 +
/* See LICENSE file for copyright and license details. */
2 +
double mfact = MFACT;
3 +
int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
4 +
5 +
void setmfact(const char *arg);
6 +
void tile(void);
7 +
void tilegeom(void);
8 +
void tileresize(Client *c, int x, int y, int w, int h);
9 +
10 +
void
11 +
setmfact(const char *arg) {
12 +
	double d;
13 +
14 +
	if(lt->arrange != tile)
15 +
		return;
16 +
	if(!arg)
17 +
		mfact = MFACT;
18 +
	else {
19 +
		d = strtod(arg, NULL);
20 +
		if(arg[0] == '-' || arg[0] == '+')
21 +
			d += mfact;
22 +
		if(d < 0.1 || d > 0.9)
23 +
			return;
24 +
		mfact = d;
25 +
	}
26 +
	updategeom();
27 +
	arrange();
28 +
}
29 +
30 +
void
31 +
tile(void) {
32 +
	int y, h;
33 +
	unsigned int i, n;
34 +
	Client *c;
35 +
36 +
	for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
37 +
	if(n == 0)
38 +
		return;
39 +
40 +
	/* master */
41 +
	c = nextunfloating(clients);
42 +
43 +
	if(n == 1)
44 +
		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
45 +
	else
46 +
		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
47 +
48 +
	if(--n == 0)
49 +
		return;
50 +
51 +
	/* tile stack */
52 +
	y = ty;
53 +
	h = th / n;
54 +
	if(h < bh)
55 +
		h = th;
56 +
57 +
	for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
58 +
		if(i + 1 == n) /* remainder */
59 +
			tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw);
60 +
		else
61 +
			tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw);
62 +
		if(h != th)
63 +
			y = c->y + c->h + 2 * c->bw;
64 +
	}
65 +
}
66 +
67 +
void
68 +
tilegeom(void) {
69 +
	/* master area geometry */
70 +
	mx = wx;
71 +
	my = wy;
72 +
	mw = mfact * ww;
73 +
	mh = wh;
74 +
75 +
	/* tile area geometry */
76 +
	tx = mx + mw;
77 +
	ty = wy;
78 +
	tw = ww - mw;
79 +
	th = wh;
80 +
}
81 +
82 +
void
83 +
tileresize(Client *c, int x, int y, int w, int h) {
84 +
	resize(c, x, y, w, h, RESIZEHINTS);
85 +
	if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
86 +
		/* client doesn't accept size constraints */
87 +
		resize(c, x, y, w, h, False);
88 +
}
89 +
90 +
void
91 +
zoom(const char *arg) {
92 +
	Client *c = sel;
93 +
94 +
	if(c == nextunfloating(clients))
95 +
		if(!c || !(c = nextunfloating(c->next)))
96 +
			return;
97 +
	if(lt->arrange == tile && !sel->isfloating) {
98 +
		detach(c);
99 +
		attach(c);
100 +
		focus(c);
101 +
	}
102 +
	arrange();
103 +
}