introduced tile.c, some refactoring of functions 5cc27f1b
Anselm R. Garbe · 2007-02-19 13:00 8 file(s) · +150 −141
Makefile +1 −1
3 3
4 4
include config.mk
5 5
6 -
SRC = client.c draw.c event.c main.c tag.c util.c view.c
6 +
SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c
7 7
OBJ = ${SRC:.c=.o}
8 8
9 9
all: options dwm
config.arg.h +1 −1
5 5
#define TAGS \
6 6
const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8 -
#define BORDERPX		1
9 8
#define DEFMODE			dotile		/* dofloat */
10 9
#define FLOATSYMBOL		"><>"
11 10
#define TILESYMBOL		"[]="
12 11
12 +
#define BORDERPX		1
13 13
#define FONT			"-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
14 14
#define NORMBORDERCOLOR		"#333"
15 15
#define NORMBGCOLOR		"#222"
config.default.h +1 −1
5 5
#define TAGS \
6 6
const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8 -
#define BORDERPX		1
9 8
#define DEFMODE			dotile		/* dofloat */
10 9
#define FLOATSYMBOL		"><>"
11 10
#define TILESYMBOL		"[]="
12 11
12 +
#define BORDERPX		1
13 13
#define FONT			"-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
14 14
#define NORMBORDERCOLOR		"#dddddd"
15 15
#define NORMBGCOLOR		"#eeeeee"
dwm.h +8 −5
127 127
extern int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
128 128
129 129
/* tag.c */
130 -
extern void initrregs(void);			/* initialize regexps of rules defined in config.h */
130 +
extern void compileregexps(void);		/* initialize regexps of rules defined in config.h */
131 131
extern void settags(Client *c, Client *trans);	/* sets tags of c */
132 132
extern void tag(Arg *arg);			/* tags c with arg's index */
133 133
extern void toggletag(Arg *arg);		/* toggles c tags with arg's index */
134 134
135 +
/* tile.c */
136 +
extern void dotile(void);			/* arranges all windows tiled */
137 +
extern void incnmaster(Arg *arg);		/* increments nmaster with arg's index value */
138 +
extern void resizemaster(Arg *arg);		/* resizes the master percent with arg's index value */
139 +
extern void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
140 +
135 141
/* util.c */
136 142
extern void *emallocz(unsigned int size);	/* allocates zero-initialized memory, exits on error */
137 143
extern void eprint(const char *errstr, ...);	/* prints errstr and exits with 1 */
140 146
/* view.c */
141 147
extern void detach(Client *c);			/* detaches c from global client list */
142 148
extern void dofloat(void);			/* arranges all windows floating */
143 -
extern void dotile(void);			/* arranges all windows tiled */
144 149
extern void focusnext(Arg *arg);		/* focuses next visible client, arg is ignored  */
145 150
extern void focusprev(Arg *arg);		/* focuses previous visible client, arg is ignored */
146 -
extern void incnmaster(Arg *arg);		/* increments nmaster with arg's index value */
147 151
extern Bool isvisible(Client *c);		/* returns True if client is visible */
148 -
extern void resizemaster(Arg *arg);		/* resizes the master percent with arg's index value */
152 +
extern Client *nextmanaged(Client *c);		/* returns managed successor of c */
149 153
extern void restack(void);			/* restores z layers of all clients */
150 154
extern void togglefloat(Arg *arg);		/* toggles focusesd client between floating/non-floating state */
151 155
extern void togglemode(Arg *arg);		/* toggles global arrange function (dotile/dofloat) */
152 156
extern void toggleview(Arg *arg);		/* toggles the tag with arg's index (in)visible */
153 157
extern void view(Arg *arg);			/* views the tag with arg's index */
154 -
extern void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
main.c +1 −1
117 117
	wa.cursor = cursor[CurNormal];
118 118
	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
119 119
	grabkeys();
120 -
	initrregs();
120 +
	compileregexps();
121 121
	for(ntags = 0; tags[ntags]; ntags++);
122 122
	seltag = emallocz(sizeof(Bool) * ntags);
123 123
	seltag[0] = True;
tag.c +1 −1
32 32
/* extern */
33 33
34 34
void
35 -
initrregs(void) {
35 +
compileregexps(void) {
36 36
	unsigned int i;
37 37
	regex_t *reg;
38 38
tile.c (added) +132 −0
1 +
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 +
 * See LICENSE file for license details.
3 +
 */
4 +
#include "dwm.h"
5 +
6 +
/* static */
7 +
8 +
static void
9 +
togglemax(Client *c) {
10 +
	XEvent ev;
11 +
		
12 +
	if(c->isfixed)
13 +
		return;
14 +
15 +
	if((c->ismax = !c->ismax)) {
16 +
		c->rx = c->x;
17 +
		c->ry = c->y;
18 +
		c->rw = c->w;
19 +
		c->rh = c->h;
20 +
		resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
21 +
	}
22 +
	else
23 +
		resize(c, c->rx, c->ry, c->rw, c->rh, True);
24 +
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
25 +
}
26 +
27 +
/* extern */
28 +
29 +
void
30 +
dotile(void) {
31 +
	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
32 +
	Client *c;
33 +
34 +
	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
35 +
		n++;
36 +
	/* window geoms */
37 +
	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
38 +
	mw = (n > nmaster) ? (waw * master) / 1000 : waw;
39 +
	th = (n > nmaster) ? wah / (n - nmaster) : 0;
40 +
	tw = waw - mw;
41 +
42 +
	for(i = 0, c = clients; c; c = c->next)
43 +
		if(isvisible(c)) {
44 +
			if(c->isbanned)
45 +
				XMoveWindow(dpy, c->win, c->x, c->y);
46 +
			c->isbanned = False;
47 +
			if(c->isfloat)
48 +
				continue;
49 +
			c->ismax = False;
50 +
			nx = wax;
51 +
			ny = way;
52 +
			if(i < nmaster) {
53 +
				ny += i * mh;
54 +
				nw = mw - 2 * BORDERPX;
55 +
				nh = mh - 2 * BORDERPX;
56 +
			}
57 +
			else {  /* tile window */
58 +
				nx += mw;
59 +
				nw = tw - 2 * BORDERPX;
60 +
				if(th > 2 * BORDERPX) {
61 +
					ny += (i - nmaster) * th;
62 +
					nh = th - 2 * BORDERPX;
63 +
				}
64 +
				else /* fallback if th <= 2 * BORDERPX */
65 +
					nh = wah - 2 * BORDERPX;
66 +
			}
67 +
			resize(c, nx, ny, nw, nh, False);
68 +
			i++;
69 +
		}
70 +
		else {
71 +
			c->isbanned = True;
72 +
			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
73 +
		}
74 +
	if(!sel || !isvisible(sel)) {
75 +
		for(c = stack; c && !isvisible(c); c = c->snext);
76 +
		focus(c);
77 +
	}
78 +
	restack();
79 +
}
80 +
81 +
void
82 +
incnmaster(Arg *arg) {
83 +
	if((arrange == dofloat) || (nmaster + arg->i < 1)
84 +
	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
85 +
		return;
86 +
	nmaster += arg->i;
87 +
	if(sel)
88 +
		arrange();
89 +
	else
90 +
		drawstatus();
91 +
}
92 +
93 +
void
94 +
resizemaster(Arg *arg) {
95 +
	if(arrange != dotile)
96 +
		return;
97 +
	if(arg->i == 0)
98 +
		master = MASTER;
99 +
	else {
100 +
		if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
101 +
		|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
102 +
			return;
103 +
		master += arg->i;
104 +
	}
105 +
	arrange();
106 +
}
107 +
108 +
void
109 +
zoom(Arg *arg) {
110 +
	unsigned int n;
111 +
	Client *c;
112 +
113 +
	if(!sel)
114 +
		return;
115 +
	if(sel->isfloat || (arrange == dofloat)) {
116 +
		togglemax(sel);
117 +
		return;
118 +
	}
119 +
	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
120 +
		n++;
121 +
122 +
	if((c = sel) == nextmanaged(clients))
123 +
		if(!(c = nextmanaged(c->next)))
124 +
			return;
125 +
	detach(c);
126 +
	if(clients)
127 +
		clients->prev = c;
128 +
	c->next = clients;
129 +
	clients = c;
130 +
	focus(c);
131 +
	arrange();
132 +
}
view.c +5 −131
2 2
 * See LICENSE file for license details.
3 3
 */
4 4
#include "dwm.h"
5 -
#include <stdio.h>
6 -
7 -
/* static */
8 -
9 -
static Client *
10 -
nexttiled(Client *c) {
11 -
	for(; c && (c->isfloat || !isvisible(c)); c = c->next);
12 -
	return c;
13 -
}
14 -
15 -
static void
16 -
togglemax(Client *c) {
17 -
	XEvent ev;
18 -
		
19 -
	if(c->isfixed)
20 -
		return;
21 -
22 -
	if((c->ismax = !c->ismax)) {
23 -
		c->rx = c->x;
24 -
		c->ry = c->y;
25 -
		c->rw = c->w;
26 -
		c->rh = c->h;
27 -
		resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
28 -
	}
29 -
	else
30 -
		resize(c, c->rx, c->ry, c->rw, c->rh, True);
31 -
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
32 -
}
33 5
34 6
/* extern */
35 7
70 42
}
71 43
72 44
void
73 -
dotile(void) {
74 -
	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
75 -
	Client *c;
76 -
77 -
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
78 -
		n++;
79 -
	/* window geoms */
80 -
	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
81 -
	mw = (n > nmaster) ? (waw * master) / 1000 : waw;
82 -
	th = (n > nmaster) ? wah / (n - nmaster) : 0;
83 -
	tw = waw - mw;
84 -
85 -
	for(i = 0, c = clients; c; c = c->next)
86 -
		if(isvisible(c)) {
87 -
			if(c->isbanned)
88 -
				XMoveWindow(dpy, c->win, c->x, c->y);
89 -
			c->isbanned = False;
90 -
			if(c->isfloat)
91 -
				continue;
92 -
			c->ismax = False;
93 -
			nx = wax;
94 -
			ny = way;
95 -
			if(i < nmaster) {
96 -
				ny += i * mh;
97 -
				nw = mw - 2 * BORDERPX;
98 -
				nh = mh - 2 * BORDERPX;
99 -
			}
100 -
			else {  /* tile window */
101 -
				nx += mw;
102 -
				nw = tw - 2 * BORDERPX;
103 -
				if(th > 2 * BORDERPX) {
104 -
					ny += (i - nmaster) * th;
105 -
					nh = th - 2 * BORDERPX;
106 -
				}
107 -
				else /* fallback if th <= 2 * BORDERPX */
108 -
					nh = wah - 2 * BORDERPX;
109 -
			}
110 -
			resize(c, nx, ny, nw, nh, False);
111 -
			i++;
112 -
		}
113 -
		else {
114 -
			c->isbanned = True;
115 -
			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
116 -
		}
117 -
	if(!sel || !isvisible(sel)) {
118 -
		for(c = stack; c && !isvisible(c); c = c->snext);
119 -
		focus(c);
120 -
	}
121 -
	restack();
122 -
}
123 -
124 -
void
125 45
focusnext(Arg *arg) {
126 46
	Client *c;
127 47
   
153 73
	}
154 74
}
155 75
156 -
void
157 -
incnmaster(Arg *arg) {
158 -
	if((arrange == dofloat) || (nmaster + arg->i < 1)
159 -
	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
160 -
		return;
161 -
	nmaster += arg->i;
162 -
	if(sel)
163 -
		arrange();
164 -
	else
165 -
		drawstatus();
166 -
}
167 -
168 76
Bool
169 77
isvisible(Client *c) {
170 78
	unsigned int i;
175 83
	return False;
176 84
}
177 85
178 -
void
179 -
resizemaster(Arg *arg) {
180 -
	if(arrange != dotile)
181 -
		return;
182 -
	if(arg->i == 0)
183 -
		master = MASTER;
184 -
	else {
185 -
		if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
186 -
		|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
187 -
			return;
188 -
		master += arg->i;
189 -
	}
190 -
	arrange();
86 +
Client *
87 +
nextmanaged(Client *c) {
88 +
	for(; c && (c->isfloat || !isvisible(c)); c = c->next);
89 +
	return c;
191 90
}
192 91
193 92
void
203 102
	if(arrange != dofloat) {
204 103
		if(!sel->isfloat)
205 104
			XLowerWindow(dpy, sel->win);
206 -
		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
105 +
		for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
207 106
			if(c == sel)
208 107
				continue;
209 108
			XLowerWindow(dpy, c->win);
252 151
	arrange();
253 152
}
254 153
255 -
void
256 -
zoom(Arg *arg) {
257 -
	unsigned int n;
258 -
	Client *c;
259 -
260 -
	if(!sel)
261 -
		return;
262 -
	if(sel->isfloat || (arrange == dofloat)) {
263 -
		togglemax(sel);
264 -
		return;
265 -
	}
266 -
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
267 -
		n++;
268 -
269 -
	if((c = sel) == nexttiled(clients))
270 -
		if(!(c = nexttiled(c->next)))
271 -
			return;
272 -
	detach(c);
273 -
	if(clients)
274 -
		clients->prev = c;
275 -
	c->next = clients;
276 -
	clients = c;
277 -
	focus(c);
278 -
	arrange();
279 -
}