I introduced {H,V}RATIO and inc{h,v,}ratio() functions - the default behaves like in dwm-4.3, config.arg.h shows how I prefer the ratio being handled (for the future I plan to change const char *arg into ..., and renaming Client into Win.) 4135e34d
Anselm R. Garbe · 2007-08-04 10:51 4 file(s) · +44 −29
config.arg.h +6 −3
31 31
	{ "><>",		floating }, \
32 32
};
33 33
#define NMASTER			1	/* clients in master area */
34 -
#define RATIO			.8	/* ratio of tile */
34 +
#define HRATIO			.8	/* horizontal ratio of tile */
35 +
#define VRATIO			.8	/* vertical ratio of tile */
35 36
#define SNAP			32	/* snap pixel */
36 37
37 38
/* key definitions */
46 47
		"exec urxvtcd -tr -bg '#222' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \
47 48
	{ MODKEY,			XK_space,	setlayout,	NULL }, \
48 49
	{ MODKEY,			XK_b,		togglebar,	NULL }, \
49 -
	{ MODKEY,			XK_h,		incratio,	".1" }, \
50 -
	{ MODKEY,			XK_l,		incratio,	"-.1" }, \
50 +
	{ MODKEY,			XK_h,		incvratio,	".1" }, \
51 +
	{ MODKEY,			XK_h,		inchratio,	".1" }, \
52 +
	{ MODKEY,			XK_l,		incvratio,	"-.1" }, \
53 +
	{ MODKEY,			XK_l,		inchratio,	"-.1" }, \
51 54
	{ MODKEY|ShiftMask,		XK_j,		incnmaster,	"1" }, \
52 55
	{ MODKEY|ShiftMask,		XK_k,		incnmaster,	"-1" }, \
53 56
	{ MODKEY,			XK_j,		focusclient,	"1" }, \
config.default.h +4 −3
32 32
	{ "><>",		floating }, \
33 33
};
34 34
#define NMASTER			1	/* clients in master area */
35 -
#define RATIO			.8	/* ratio of tile */
35 +
#define HRATIO			.8	/* horizontal ratio of tile */
36 +
#define VRATIO			1	/* vertical ratio of tile */
36 37
#define SNAP			32	/* snap pixel */
37 38
38 39
/* key definitions */
44 45
	{ MODKEY,			XK_p,		spawn, 		"exe=`dmenu_path | dmenu` && exec $exe" }, \
45 46
	{ MODKEY,			XK_space,	setlayout,	NULL }, \
46 47
	{ MODKEY,			XK_b,		togglebar,	NULL }, \
47 -
	{ MODKEY,			XK_h,		incratio,	".1" }, \
48 -
	{ MODKEY,			XK_l,		incratio,	"-.1" }, \
48 +
	{ MODKEY,			XK_h,		incvratio,	".1" }, \
49 +
	{ MODKEY,			XK_l,		incvratio,	"-.1" }, \
49 50
	{ MODKEY|ShiftMask,		XK_j,		incnmaster,	"1" }, \
50 51
	{ MODKEY|ShiftMask,		XK_k,		incnmaster,	"-1" }, \
51 52
	{ MODKEY,			XK_j,		focusclient,	"1" }, \
dwm.h +2 −2
44 44
typedef struct Client Client;
45 45
struct Client {
46 46
	char name[256];
47 -
	float scale;
48 47
	int x, y, w, h;
49 48
	int rx, ry, rw, rh; /* revert geometry */
50 49
	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
123 122
/* layout.c */
124 123
void floating(void);			/* arranges all windows floating */
125 124
void focusclient(const char *arg);	/* focuses next(1)/previous(-1) visible client */
126 -
void incratio(const char *arg);		/* increments the tile ratio with arg's value */
125 +
void inchratio(const char *arg);	/* increments the horizontal tile ratio with arg's value */
126 +
void incvratio(const char *arg);	/* increments the vertical tile ratio with arg's value */
127 127
void incnmaster(const char *arg);	/* increments nmaster with arg's index value */
128 128
void initlayouts(void);			/* initialize layout array */
129 129
Client *nexttiled(Client *c);		/* returns tiled successor of c */
layout.c +32 −21
8 8
9 9
/* static */
10 10
11 -
static double ratio = RATIO;
11 +
static double hratio = HRATIO;
12 +
static double vratio = VRATIO;
12 13
static unsigned int nlayouts = 0;
13 14
static unsigned int nmaster = NMASTER;
14 15
16 +
static void
17 +
incratio(const char *arg, double *ratio, double def) {
18 +
	double delta;
19 +
20 +
	if(lt->arrange != tile)
21 +
		return;
22 +
	if(!arg)
23 +
		*ratio = def;
24 +
	else {
25 +
		if(1 == sscanf(arg, "%lf", &delta)) {
26 +
			if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
27 +
				return;
28 +
			*ratio += delta;
29 +
		}
30 +
	}
31 +
	lt->arrange();
32 +
}
33 +
15 34
static double /* simple pow() */
16 35
spow(double x, double y)
17 36
{
31 50
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
32 51
		n++;
33 52
34 -
	mw = (n <= nmaster) ? waw :  waw / (1 + ratio);
53 +
	mw = (n <= nmaster) ? waw :  waw / (1 + hratio);
35 54
	tw = waw - mw;
36 55
37 56
	if(n > 0) {
38 57
		if(n < nmaster) {
39 58
			for(i = 0; i < n; i++)
40 -
				sum += spow(ratio, i);
59 +
				sum += spow(vratio, i);
41 60
			mscale = wah / sum;
42 61
		}
43 62
		else {
44 63
			for(i = 0; i < nmaster; i++)
45 -
				sum += spow(ratio, i);
64 +
				sum += spow(vratio, i);
46 65
			mscale = wah / sum;
47 66
			for(sum = 0, i = 0; i < (n - nmaster); i++)
48 -
				sum += spow(ratio, i);
67 +
				sum += spow(vratio, i);
49 68
			tscale = wah / sum;
50 69
		}
51 70
	}
62 81
				if(i + 1 == n || i + 1 == nmaster)
63 82
					nh = (way + wah) - ny - (2 * c->border);
64 83
				else
65 -
					nh = (mscale * spow(ratio, i)) - (2 * c->border);
84 +
					nh = (mscale * spow(vratio, i)) - (2 * c->border);
66 85
			}
67 86
			else { /* tile window */
68 87
				if(i == nmaster) {
73 92
				if(i + 1 == n)
74 93
					nh = (way + wah) - ny - (2 * c->border);
75 94
				else
76 -
					nh = (tscale * spow(ratio, i - nmaster)) - (2 * c->border);
95 +
					nh = (tscale * spow(vratio, i - nmaster)) - (2 * c->border);
77 96
			}
78 97
			if(nh < bh) {
79 98
				nh = bh;
133 152
}
134 153
135 154
void
136 -
incratio(const char *arg) {
137 -
	double delta;
155 +
inchratio(const char *arg) {
156 +
	incratio(arg, &hratio, HRATIO);
157 +
}
138 158
139 -
	if(lt->arrange != tile)
140 -
		return;
141 -
	if(!arg)
142 -
		ratio = RATIO;
143 -
	else {
144 -
		if(1 == sscanf(arg, "%lf", &delta)) {
145 -
			if(delta + ratio < .1 || delta + ratio > 1.9)
146 -
				return;
147 -
			ratio += delta;
148 -
		}
149 -
	}
150 -
	lt->arrange();
159 +
void
160 +
incvratio(const char *arg) {
161 +
	incratio(arg, &vratio, VRATIO);
151 162
}
152 163
153 164
void