made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts 77044e87
Anselm R. Garbe · 2007-08-13 19:13 8 file(s) · +62 −42
client.c +5 −4
230 230
	setclientstate(c, IconicState);
231 231
	c->isbanned = True;
232 232
	focus(c);
233 -
	lt->arrange();
233 +
	arrange();
234 234
}
235 235
236 236
void
237 237
resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
238 238
	double dx, dy, max, min, ratio;
239 239
	XWindowChanges wc; 
240 +
240 241
	if(sizehints) {
241 242
		if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) {
242 243
			dx = (double)(w - c->basew);
297 298
298 299
void
299 300
togglefloating(const char *arg) {
300 -
	if(!sel || lt->arrange == floating)
301 +
	if(!sel || isfloating())
301 302
		return;
302 303
	sel->isfloating = !sel->isfloating;
303 304
	if(sel->isfloating)
304 305
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
305 -
	lt->arrange();
306 +
	arrange();
306 307
}
307 308
308 309
void
334 335
	XSync(dpy, False);
335 336
	XSetErrorHandler(xerror);
336 337
	XUngrabServer(dpy);
337 -
	lt->arrange();
338 +
	arrange();
338 339
}
339 340
340 341
void
config.mk +2 −2
20 20
# flags
21 21
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
22 22
LDFLAGS = -s ${LIBS}
23 -
CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24 -
LDFLAGS = -g ${LIBS}
23 +
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24 +
#LDFLAGS = -g ${LIBS}
25 25
26 26
# Solaris
27 27
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
draw.c +1 −1
66 66
		dc.x += dc.w;
67 67
	}
68 68
	dc.w = blw;
69 -
	drawtext(lt->symbol, dc.norm);
69 +
	drawtext(getsymbol(), dc.norm);
70 70
	x = dc.x + dc.w;
71 71
	dc.w = textw(stext);
72 72
	dc.x = sw - dc.w;
dwm.h +4 −7
74 74
	} font;
75 75
} DC; /* draw context */
76 76
77 -
typedef struct {
78 -
	const char *symbol;
79 -
	void (*arrange)(void);
80 -
} Layout;
81 -
82 77
extern const char *tags[];			/* all tags */
83 78
extern char stext[256];				/* status text */
84 79
extern int screen, sx, sy, sw, sh;		/* screen geometry */
92 87
extern Cursor cursor[CurLast];
93 88
extern DC dc;					/* global draw context */
94 89
extern Display *dpy;
95 -
extern Layout *lt;
96 90
extern Window root, barwin;
97 91
98 92
/* client.c */
120 114
void grabkeys(void);			/* grab all keys defined in config.h */
121 115
122 116
/* layout.c */
123 -
void floating(void);			/* arranges all windows floating, fallback layout  */
117 +
void arrange(void);			/* arranges all windows depending on the layout in use */
124 118
void focusclient(const char *arg);	/* focuses next(1)/previous(-1) visible client */
119 +
const char *getsymbol(void);		/* returns True  symbol of enabled layout */
120 +
Bool isfloating(void);			/* returns True if floating layout is enabled */
121 +
Bool isarrange(void (*func)());		/* returns True if func is the layout function in use */
125 122
void initlayouts(void);			/* initialize layout array */
126 123
Client *nexttiled(Client *c);		/* returns tiled successor of c */
127 124
void restack(void);			/* restores z layers of all clients */
event.c +5 −5
145 145
		focus(c);
146 146
		if(CLEANMASK(ev->state) != MODKEY)
147 147
			return;
148 -
		if(ev->button == Button1 && (lt->arrange == floating || c->isfloating)) {
148 +
		if(ev->button == Button1 && (isfloating() || c->isfloating)) {
149 149
			restack();
150 150
			movemouse(c);
151 151
		}
152 152
		else if(ev->button == Button2)
153 153
			zoom(NULL);
154 154
		else if(ev->button == Button3
155 -
		&& (lt->arrange == floating || c->isfloating) && !c->isfixed)
155 +
		&& (isfloating() || c->isfloating) && !c->isfixed)
156 156
		{
157 157
			restack();
158 158
			resizemouse(c);
170 170
		c->ismax = False;
171 171
		if(ev->value_mask & CWBorderWidth)
172 172
			c->border = ev->border_width;
173 -
		if(c->isfixed || c->isfloating || (lt->arrange == floating)) {
173 +
		if(c->isfixed || c->isfloating || isfloating()) {
174 174
			if(ev->value_mask & CWX)
175 175
				c->x = ev->x;
176 176
			if(ev->value_mask & CWY)
216 216
		dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
217 217
		XResizeWindow(dpy, barwin, sw, bh);
218 218
		updatebarpos();
219 -
		lt->arrange();
219 +
		arrange();
220 220
	}
221 221
}
222 222
317 317
			case XA_WM_TRANSIENT_FOR:
318 318
				XGetTransientForHint(dpy, c->win, &trans);
319 319
				if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
320 -
					lt->arrange();
320 +
					arrange();
321 321
				break;
322 322
			case XA_WM_NORMAL_HINTS:
323 323
				updatesizehints(c);
layout.c +37 −10
2 2
#include "dwm.h"
3 3
#include <stdlib.h>
4 4
5 +
typedef struct {
6 +
	const char *symbol;
7 +
	void (*arrange)(void);
8 +
} Layout;
9 +
5 10
unsigned int blw = 0;
6 -
Layout *lt = NULL;
11 +
static Layout *lt = NULL;
7 12
8 13
/* static */
9 14
15 +
static void
16 +
floating(void) {
17 +
	Client *c;
18 +
19 +
	for(c = clients; c; c = c->next)
20 +
		if(isvisible(c))
21 +
			resize(c, c->x, c->y, c->w, c->h, True);
22 +
}
23 +
10 24
static unsigned int nlayouts = 0;
11 25
12 26
LAYOUTS
14 28
/* extern */
15 29
16 30
void
17 -
floating(void) {
31 +
arrange(void) {
18 32
	Client *c;
19 33
20 -
	if(lt->arrange != floating)
21 -
		return;
22 -
23 34
	for(c = clients; c; c = c->next)
24 -
		if(isvisible(c)) {
35 +
		if(isvisible(c))
25 36
			unban(c);
26 -
			resize(c, c->x, c->y, c->w, c->h, True);
27 -
		}
28 37
		else
29 38
			ban(c);
39 +
	lt->arrange();
30 40
	focus(NULL);
31 41
	restack();
32 42
}
53 63
		focus(c);
54 64
		restack();
55 65
	}
66 +
}
67 +
68 +
const char *
69 +
getsymbol(void)
70 +
{
71 +
	return lt->symbol;
72 +
}
73 +
74 +
Bool
75 +
isfloating(void) {
76 +
	return lt->arrange == floating;
77 +
}
78 +
79 +
Bool
80 +
isarrange(void (*func)())
81 +
{
82 +
	return func == lt->arrange;
56 83
}
57 84
58 85
void
119 146
		lt = &layout[i];
120 147
	}
121 148
	if(sel)
122 -
		lt->arrange();
149 +
		arrange();
123 150
	else
124 151
		drawstatus();
125 152
}
131 158
	else
132 159
		bpos = BarOff;
133 160
	updatebarpos();
134 -
	lt->arrange();
161 +
	arrange();
135 162
}
136 163
137 164
void
tag.c +4 −4
110 110
	i = arg ? atoi(arg) : 0;
111 111
	if(i >= 0 && i < ntags)
112 112
		sel->tags[i] = True;
113 -
	lt->arrange();
113 +
	arrange();
114 114
}
115 115
116 116
void
124 124
	for(j = 0; j < ntags && !sel->tags[j]; j++);
125 125
	if(j == ntags)
126 126
		sel->tags[i] = True;
127 -
	lt->arrange();
127 +
	arrange();
128 128
}
129 129
130 130
void
136 136
	for(j = 0; j < ntags && !seltag[j]; j++);
137 137
	if(j == ntags)
138 138
		seltag[i] = True; /* cannot toggle last view */
139 -
	lt->arrange();
139 +
	arrange();
140 140
}
141 141
142 142
void
148 148
	i = arg ? atoi(arg) : 0;
149 149
	if(i >= 0 && i < ntags)
150 150
		seltag[i] = True;
151 -
	lt->arrange();
151 +
	arrange();
152 152
}
tile.c +4 −9
12 12
addtomwfact(const char *arg) {
13 13
	double delta;
14 14
15 -
	if(lt->arrange != tile)
15 +
	if(isarrange(tile))
16 16
		return;
17 17
18 18
	/* arg handling, manipulate mwfact */
20 20
		if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
21 21
			mwfact += delta;
22 22
	}
23 -
	lt->arrange();
23 +
	arrange();
24 24
}
25 25
26 26
void
41 41
	ny = way;
42 42
	for(i = 0, c = clients; c; c = c->next)
43 43
		if(isvisible(c)) {
44 -
			unban(c);
45 44
			if(c->isfloating)
46 45
				continue;
47 46
			c->ismax = False;
65 64
				ny += nh + 2 * c->border;
66 65
			i++;
67 66
		}
68 -
		else
69 -
			ban(c);
70 -
	focus(NULL);
71 -
	restack();
72 67
}
73 68
74 69
void
75 70
zoom(const char *arg) {
76 71
	Client *c;
77 72
78 -
	if(!sel || lt->arrange == floating || sel->isfloating)
73 +
	if(!sel || !isarrange(tile) || sel->isfloating)
79 74
		return;
80 75
	if((c = sel) == nexttiled(clients))
81 76
		if(!(c = nexttiled(c->next)))
83 78
	detach(c);
84 79
	attach(c);
85 80
	focus(c);
86 -
	lt->arrange();
81 +
	arrange();
87 82
}