tile.c
author Anselm R Garbe <garbeam@gmail.com>
Mon, 19 May 2008 15:05:46 +0100
changeset 1215 840fd59e3141
parent 1214 941bd7c15a32
permissions -rw-r--r--
make it easier for the user, if Xinerama support is given, always use the screen 0 as window area/bar area, everything else can be used for floating clients
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     1
/* See LICENSE file for copyright and license details. */
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     2
int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     3
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     4
void setmfact(const char *arg);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     5
void tile(void);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     6
void tileresize(Client *c, int x, int y, int w, int h);
1206
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
     7
void updatetilegeom(void);
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     8
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
     9
void
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    10
setmfact(const char *arg) {
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    11
	double d;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    12
1209
c2dc0bd92158 recent changes, introduced togglebar, changed some defines into variable declarations where possible
Anselm R Garbe <garbeam@gmail.com>
parents: 1206
diff changeset
    13
	if(!arg || lt->arrange != tile)
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    14
		return;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    15
	else {
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    16
		d = strtod(arg, NULL);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    17
		if(arg[0] == '-' || arg[0] == '+')
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    18
			d += mfact;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    19
		if(d < 0.1 || d > 0.9)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    20
			return;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    21
		mfact = d;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    22
	}
1210
225aa5566f0e updatetilegeom should be fine for setmfact
Anselm R Garbe <garbeam@gmail.com>
parents: 1209
diff changeset
    23
	updatetilegeom();
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    24
	arrange();
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    25
}
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    26
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    27
void
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    28
tile(void) {
1214
941bd7c15a32 improving space usage if master is left of stack (default)
Anselm R Garbe <garbeam@gmail.com>
parents: 1211
diff changeset
    29
	int x, y, h, w;
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    30
	unsigned int i, n;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    31
	Client *c;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    32
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    33
	for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    34
	if(n == 0)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    35
		return;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    36
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    37
	/* master */
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    38
	c = nextunfloating(clients);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    39
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    40
	if(n == 1)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    41
		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    42
	else
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    43
		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    44
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    45
	if(--n == 0)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    46
		return;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    47
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    48
	/* tile stack */
1214
941bd7c15a32 improving space usage if master is left of stack (default)
Anselm R Garbe <garbeam@gmail.com>
parents: 1211
diff changeset
    49
	x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw;
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    50
	y = ty;
1214
941bd7c15a32 improving space usage if master is left of stack (default)
Anselm R Garbe <garbeam@gmail.com>
parents: 1211
diff changeset
    51
	w = (tx > c->x + c->w) ? wx + ww - x : tw;
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    52
	h = th / n;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    53
	if(h < bh)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    54
		h = th;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    55
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    56
	for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    57
		if(i + 1 == n) /* remainder */
1214
941bd7c15a32 improving space usage if master is left of stack (default)
Anselm R Garbe <garbeam@gmail.com>
parents: 1211
diff changeset
    58
			tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw);
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    59
		else
1214
941bd7c15a32 improving space usage if master is left of stack (default)
Anselm R Garbe <garbeam@gmail.com>
parents: 1211
diff changeset
    60
			tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw);
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    61
		if(h != th)
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    62
			y = c->y + c->h + 2 * c->bw;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    63
	}
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    64
}
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    65
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    66
void
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    67
tileresize(Client *c, int x, int y, int w, int h) {
1209
c2dc0bd92158 recent changes, introduced togglebar, changed some defines into variable declarations where possible
Anselm R Garbe <garbeam@gmail.com>
parents: 1206
diff changeset
    68
	resize(c, x, y, w, h, resizehints);
c2dc0bd92158 recent changes, introduced togglebar, changed some defines into variable declarations where possible
Anselm R Garbe <garbeam@gmail.com>
parents: 1206
diff changeset
    69
	if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
1203
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    70
		/* client doesn't accept size constraints */
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    71
		resize(c, x, y, w, h, False);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    72
}
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    73
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    74
void
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    75
zoom(const char *arg) {
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    76
	Client *c = sel;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    77
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    78
	if(c == nextunfloating(clients))
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    79
		if(!c || !(c = nextunfloating(c->next)))
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    80
			return;
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    81
	if(lt->arrange == tile && !sel->isfloating) {
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    82
		detach(c);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    83
		attach(c);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    84
		focus(c);
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    85
	}
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    86
	arrange();
710f0fc31764 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
Anselm R Garbe <garbeam@gmail.com>
parents:
diff changeset
    87
}
1206
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    88
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    89
void
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    90
updatetilegeom(void) {
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    91
	/* master area geometry */
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    92
	mx = wx;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    93
	my = wy;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    94
	mw = mfact * ww;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    95
	mh = wh;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    96
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    97
	/* tile area geometry */
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    98
	tx = mx + mw;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
    99
	ty = wy;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
   100
	tw = ww - mw;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
   101
	th = wh;
2914cb30c2d4 s/tilegeom/updatetilegeom/
Anselm R Garbe <garbeam@gmail.com>
parents: 1203
diff changeset
   102
}