tile.c
author Anselm R. Garbe <garbeam@gmail.com>
Mon, 13 Aug 2007 19:13:54 +0200
changeset 946 b938876de936
parent 943 d0b93818f723
child 947 970931b7dd30
permissions -rw-r--r--
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
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
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
    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;
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
	for(i = 0, c = clients; c; c = 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
    43
		if(isvisible(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
    44
			if(c->isfloating)
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
				continue;
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
			c->ismax = False;
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
			if(i == 0) { /* master */
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
				nw = mw - 2 * c->border;
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
				nh = wah - 2 * c->border;
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
    50
			}
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
    51
			else {  /* tile window */
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
				if(i == 1) {
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
    53
					ny = way;
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
    54
					nx += mw;
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
    55
				}
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
    56
				nw = waw - mw - 2 * c->border;
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
    57
				if(i + 1 == n) /* remainder */
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
					nh = (way + wah) - ny - 2 * c->border;
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
    59
				else
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
					nh = th - 2 * c->border;
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
    61
			}
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
    62
			resize(c, nx, ny, nw, nh, False);
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
    63
			if(n > 1 && 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
    64
				ny += nh + 2 * c->border;
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
			i++;
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
		}
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
}
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
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
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
    70
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
    71
	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
    72
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
    73
	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
    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
	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
    76
		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
    77
			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
    78
	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
    79
	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
    80
	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
    81
	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
    82
}