first step to a more flexible dotile() algorithm 14d05e7c
Anselm R. Garbe · 2006-09-29 12:38 7 file(s) · +52 −35
config.arg.h +4 −2
6 6
#define TAGS \
7 7
const char *tags[] = { "dev", "work", "net", "fnord", NULL };
8 8
9 -
#define DEFMODE			dotile /* dofloat */
9 +
#define DEFMODE			dotile		/* dofloat */
10 10
#define FLOATSYMBOL		"><>"
11 +
#define STACKPOS		StackRight	/* StackLeft, StackBottom */
11 12
#define TILESYMBOL		"[]="
13 +
#define VERTICALSTACK		True		/* False == horizontal stack  */
12 14
13 15
#define FONT			"-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
14 16
#define NORMBGCOLOR		"#333333"
18 20
#define STATUSBGCOLOR		"#222222"
19 21
#define STATUSFGCOLOR		"#9999cc"
20 22
21 -
#define MASTERW			60 /* percent */
23 +
#define MASTER			60 /* percent */
22 24
#define MODKEY			Mod1Mask
23 25
24 26
#define KEYS \
config.default.h +3 −1
8 8
9 9
#define DEFMODE			dotile /* dofloat */
10 10
#define FLOATSYMBOL		"><>"
11 +
#define STACKPOS		StackRight	/* StackLeft, StackBottom */
11 12
#define TILESYMBOL		"[]="
13 +
#define VERTICALSTACK		True		/* False == horizontal stack  */
12 14
13 15
#define FONT			"fixed"
14 16
#define NORMBGCOLOR		"#333366"
18 20
#define STATUSBGCOLOR		"#dddddd"
19 21
#define STATUSFGCOLOR		"#222222"
20 22
21 -
#define MASTERW			60 /* percent */
23 +
#define MASTER			60 /* percent */
22 24
#define MODKEY			Mod1Mask
23 25
24 26
#define KEYS \
config.mk +1 −1
1 1
# dwm version
2 -
VERSION = 1.7.1
2 +
VERSION = 1.8
3 3
4 4
# Customize below to fit your system
5 5
dwm.h +7 −1
48 48
enum { ColFG, ColBG, ColLast };				/* color */
49 49
50 50
typedef enum {
51 +
	StackLeft, StackBottom, StackRight
52 +
} StackPos; /* stack position*/
53 +
54 +
typedef enum {
51 55
	TopLeft, TopRight, BotLeft, BotRight
52 56
} Corner; /* window corners */
53 57
97 101
extern const char *tags[];			/* all tags */
98 102
extern char stext[1024];			/* status text */
99 103
extern int bx, by, bw, bh, bmw;			/* bar geometry, bar mode label width */
100 -
extern int mw, screen, sx, sy, sw, sh;		/* screen geometry, master width */
104 +
extern int master, screen, sx, sy, sw, sh;	/* screen geometry, master width */
101 105
extern unsigned int ntags, numlockmask;		/* number of tags, dynamic lock mask */
102 106
extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
103 107
extern void (*arrange)(Arg *);			/* arrange function, indicates mode  */
104 108
extern Atom wmatom[WMLast], netatom[NetLast];
105 109
extern Bool running, issel, *seltag;		/* seltag is array of Bool */
110 +
extern Bool isvertical;				/* stack direction */
106 111
extern Client *clients, *sel, *stack;		/* global client list and stack */
107 112
extern Cursor cursor[CurLast];
108 113
extern DC dc;					/* global draw context */
109 114
extern Display *dpy;
115 +
extern StackPos stackpos;
110 116
extern Window root, barwin;
111 117
112 118
/* client.c */
event.c +4 −1
176 176
		else
177 177
			configure(c);
178 178
		XSync(dpy, False);
179 -
		if(c->isfloat)
179 +
		if(c->isfloat) {
180 180
			resize(c, False, TopLeft);
181 +
			if(!isvisible(c))
182 +
				ban(c);
183 +
		}
181 184
		else
182 185
			arrange(NULL);
183 186
	}
main.c +2 −2
19 19
20 20
char stext[1024];
21 21
Bool *seltag;
22 -
int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh;
22 +
int bx, by, bw, bh, bmw, master, screen, sx, sy, sw, sh;
23 23
unsigned int ntags, numlockmask;
24 24
Atom wmatom[WMLast], netatom[NetLast];
25 25
Bool running = True;
133 133
	sx = sy = 0;
134 134
	sw = DisplayWidth(dpy, screen);
135 135
	sh = DisplayHeight(dpy, screen);
136 -
	mw = (sw * MASTERW) / 100;
136 +
	master = ((stackpos == StackBottom ? sh - bh : sw) * MASTER) / 100;
137 137
138 138
	bx = by = 0;
139 139
	bw = sw;
view.c +31 −27
65 65
/* extern */
66 66
67 67
void (*arrange)(Arg *) = DEFMODE;
68 +
Bool isvertical = VERTICALSTACK;
69 +
StackPos stackpos = STACKPOS;
68 70
69 71
void
70 72
detach(Client *c) {
97 99
98 100
/* This algorithm is based on a (M)aster area and a (S)tacking area.
99 101
 * It supports following arrangements:
100 -
 *
101 -
 * 	MMMS		MMMM
102 -
 * 	MMMS		MMMM
103 -
 * 	MMMS		SSSS
104 -
 *
105 -
 * The stacking area can be set to arrange clients vertically or horizontally.
106 -
 * Through inverting the algorithm it can be used to achieve following setup in
107 -
 * a dual head environment (due to running two dwm instances concurrently on
108 -
 * the specific screen):
109 -
 *
110 -
 * 	SMM MMS		MMM MMM
111 -
 * 	SMM MMS		MMM MMM
112 -
 * 	SMM MMS		SSS SSS
113 -
 *
114 -
 * This uses the center of the two screens for master areas.
102 +
 * 	MMMS		MMMM		SMMM
103 +
 * 	MMMS		MMMM		SMMM
104 +
 * 	MMMS		SSSS		SMMM
115 105
 */
116 106
void
117 107
dotile(Arg *arg) {
118 108
	int h, i, n, w;
119 109
	Client *c;
120 110
121 -
	w = sw - mw;
122 111
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
123 112
		n++;
124 113
125 -
	if(n > 1)
126 -
		h = (sh - bh) / (n - 1);
127 -
	else
128 -
		h = sh - bh;
114 +
	if(isvertical) {
115 +
		if(stackpos == StackBottom) {
116 +
			w = sw;
117 +
			if(n > 1)
118 +
				h = (sh - bh) / (n - 1);
119 +
			else
120 +
				h = sh - bh;
121 +
		}
122 +
		else {
123 +
			w = sw - master;
124 +
			if(n > 1)
125 +
				h = (sh - bh) / (n - 1);
126 +
			else
127 +
				h = sh - bh;
128 +
		}
129 +
	}
130 +
	else { /* horizontal stack */
131 +
132 +
	}
129 133
130 134
	for(i = 0, c = clients; c; c = c->next) {
131 135
		if(isvisible(c)) {
143 147
			else if(i == 0) {
144 148
				c->x = sx;
145 149
				c->y = sy + bh;
146 -
				c->w = mw - 2 * BORDERPX;
150 +
				c->w = master - 2 * BORDERPX;
147 151
				c->h = sh - 2 * BORDERPX - bh;
148 152
			}
149 153
			else if(h > bh) {
150 -
				c->x = sx + mw;
154 +
				c->x = sx + master;
151 155
				c->y = sy + (i - 1) * h + bh;
152 156
				c->w = w - 2 * BORDERPX;
153 157
				if(i + 1 == n)
156 160
					c->h = h - 2 * BORDERPX;
157 161
			}
158 162
			else { /* fallback if h < bh */
159 -
				c->x = sx + mw;
163 +
				c->x = sx + master;
160 164
				c->y = sy + bh;
161 165
				c->w = w - 2 * BORDERPX;
162 166
				c->h = sh - 2 * BORDERPX - bh;
228 232
		return;
229 233
230 234
	if(sel == getnext(clients)) {
231 -
		if(mw + arg->i > sw - 100 || mw + arg->i < 100)
235 +
		if(master + arg->i > sw - 100 || master + arg->i < 100)
232 236
			return;
233 -
		mw += arg->i;
237 +
		master += arg->i;
234 238
	}
235 239
	else {
236 -
		if(mw - arg->i > sw - 100 || mw - arg->i < 100)
240 +
		if(master - arg->i > sw - 100 || master - arg->i < 100)
237 241
			return;
238 -
		mw -= arg->i;
242 +
		master -= arg->i;
239 243
	}
240 244
	arrange(NULL);
241 245
}