tile.c
author Anselm R. Garbe <garbeam@gmail.com>
Wed, 22 Aug 2007 19:01:05 +0200
changeset 971 b2a0dfa22b1d
parent 962 8d1df2c37229
child 976 7c117df5d202
permissions -rw-r--r--
removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
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) {
962
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    13
	double 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
    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] != '-')
962
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    22
			mwfact = delta;
959
0aeefb841608 applied Jukka Salmi's setmwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 955
diff changeset
    23
		else
962
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    24
			mwfact += delta;
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    25
		if(mwfact < 0.1)
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    26
			mwfact = 0.1;
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    27
		else if(mwfact > 0.9)
8d1df2c37229 applied Gottox mwfact patch
Anselm R. Garbe <garbeam@gmail.com>
parents: 959
diff changeset
    28
			mwfact = 0.9;
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
    29
	}
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
    30
	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
    31
}
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
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
    34
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
    35
	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
    36
	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
    37
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
	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
    39
		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
    40
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
	/* 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
    42
	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
    43
	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
    44
	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
    45
		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
    46
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
	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
    48
	ny = way;
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    49
	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
    50
		c->ismax = False;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    51
		if(i == 0) { /* master */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    52
			nw = mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    53
			nh = wah - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    54
		}
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    55
		else {  /* tile window */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    56
			if(i == 1) {
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    57
				ny = way;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    58
				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
    59
			}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    60
			nw = waw - mw - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    61
			if(i + 1 == n) /* remainder */
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    62
				nh = (way + wah) - ny - 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    63
			else
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    64
				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
    65
		}
947
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    66
		resize(c, nx, ny, nw, nh, False);
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    67
		if(n > 1 && th != wah)
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    68
			ny += nh + 2 * c->border;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    69
		i++;
970931b7dd30 made tile simplier
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    70
	}
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
}
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
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
    74
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
    75
	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
    76
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
    77
	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
    78
		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
    79
	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
    80
		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
    81
			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
    82
	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
    83
	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
    84
	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
    85
	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
    86
}