tile.c
author Anselm R. Garbe <garbeam@gmail.com>
Mon, 13 Aug 2007 19:22:51 +0200
changeset 948 4d9c86f8ed65
parent 947 970931b7dd30
child 955 b2518e01f7e3
permissions -rw-r--r--
small bugfix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     1
/* See LICENSE file for copyright and license details. */
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     2
#include "dwm.h"
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     3
#include <stdio.h>
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     4
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     5
/* static */
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     6
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
     7
static double mwfact = MWFACT;
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     8
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     9
/* extern */
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    10
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    11
void
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    12
addtomwfact(const char *arg) {
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    13
	double delta;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    14
948
4d9c86f8ed65 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 947
diff changeset
    15
	if(!isarrange(tile))
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    16
		return;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    17
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    18
	/* arg handling, manipulate mwfact */
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    19
	if(arg && (1 == sscanf(arg, "%lf", &delta))) {
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    20
		if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    21
			mwfact += delta;
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    22
	}
946
b938876de936 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
Anselm R. Garbe <garbeam@gmail.com>
parents: 943
diff changeset
    23
	arrange();
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    24
}
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    25
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    26
void
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    27
tile(void) {
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    28
	unsigned int i, n, nx, ny, nw, nh, mw, th;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    29
	Client *c;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    30
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    31
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    32
		n++;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    33
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    34
	/* window geoms */
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    35
	mw = (n == 1) ? waw : mwfact * waw;
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    36
	th = (n > 1) ? wah / (n - 1) : 0;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    37
	if(n > 1 && th < bh)
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    38
		th = wah;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    39
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    40
	nx = wax;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    41
	ny = way;
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    42
	for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) {
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    43
		c->ismax = False;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    44
		if(i == 0) { /* master */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    45
			nw = mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    46
			nh = wah - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    47
		}
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    48
		else {  /* tile window */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    49
			if(i == 1) {
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    50
				ny = way;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    51
				nx += mw;
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    52
			}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    53
			nw = waw - mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    54
			if(i + 1 == n) /* remainder */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    55
				nh = (way + wah) - ny - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    56
			else
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    57
				nh = th - 2 * c->border;
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    58
		}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    59
		resize(c, nx, ny, nw, nh, False);
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    60
		if(n > 1 && th != wah)
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    61
			ny += nh + 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    62
		i++;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    63
	}
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    64
}
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    65
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    66
void
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    67
zoom(const char *arg) {
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    68
	Client *c;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    69
946
b938876de936 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
Anselm R. Garbe <garbeam@gmail.com>
parents: 943
diff changeset
    70
	if(!sel || !isarrange(tile) || sel->isfloating)
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    71
		return;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    72
	if((c = sel) == nexttiled(clients))
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    73
		if(!(c = nexttiled(c->next)))
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    74
			return;
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    75
	detach(c);
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    76
	attach(c);
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    77
	focus(c);
946
b938876de936 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
Anselm R. Garbe <garbeam@gmail.com>
parents: 943
diff changeset
    78
	arrange();
941
8c93b982f22e separated layout-specific stuff into separate .h and .c files which are included in config.h resp. config.mk - this allows writing layouts for dwm without any need to patch existing code
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    79
}