tile.c
author Anselm R. Garbe <garbeam@gmail.com>
Fri, 17 Aug 2007 21:12:55 +0200
changeset 960 b5f856fcef4c
parent 959 0aeefb841608
child 962 8d1df2c37229
permissions -rw-r--r--
renamed seltag into seltags
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
959
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    12
setmwfact(const char *arg) {
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    13
	double delta, newfact;
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
    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;
943
d0b93818f723 renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    17
	/* arg handling, manipulate mwfact */
955
b2518e01f7e3 applied Jukka's patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 948
diff changeset
    18
	if(arg == NULL)
b2518e01f7e3 applied Jukka's patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 948
diff changeset
    19
		mwfact = MWFACT;
b2518e01f7e3 applied Jukka's patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 948
diff changeset
    20
	else if(1 == sscanf(arg, "%lf", &delta)) {
959
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    21
		if(arg[0] != '+' && arg[0] != '-')
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    22
			newfact = delta;
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    23
		else
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    24
			newfact = mwfact + delta;
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    25
		if(newfact < 0.1)
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    26
			newfact = 0.1;
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    27
		else if(newfact > 0.9)
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    28
			newfact = 0.9;
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    29
		mwfact = newfact;
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
    30
	}
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
    31
	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
    32
}
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
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
    35
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
    36
	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
    37
	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
    38
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
	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
    40
		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
    41
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
    42
	/* 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
    43
	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
    44
	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
    45
	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
    46
		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
    47
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
    48
	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
    49
	ny = way;
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    50
	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
    51
		c->ismax = False;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    52
		if(i == 0) { /* master */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    53
			nw = mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    54
			nh = wah - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    55
		}
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    56
		else {  /* tile window */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    57
			if(i == 1) {
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    58
				ny = way;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    59
				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
    60
			}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    61
			nw = waw - mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    62
			if(i + 1 == n) /* remainder */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    63
				nh = (way + wah) - ny - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    64
			else
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    65
				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
    66
		}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    67
		resize(c, nx, ny, nw, nh, False);
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    68
		if(n > 1 && th != wah)
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    69
			ny += nh + 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    70
		i++;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    71
	}
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
    72
}
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
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
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
    75
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
    76
	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
    77
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
	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
    79
		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
    80
	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
    81
		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
    82
			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
    83
	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
    84
	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
    85
	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
    86
	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
    87
}