screen.c
author Anselm R. Garbe <garbeam@gmail.com>
Sun, 19 Aug 2007 18:39:54 +0200
changeset 969 50fb50842dbc
parent 968 ce9a5452ac8c
child 970 d5c3537ee3be
permissions -rw-r--r--
fixed misappearance of iconified windows on SIGKILL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     1
/* See LICENSE file for copyright and license details. */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     2
#include "dwm.h"
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     3
#include <regex.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     4
#include <stdio.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     5
#include <stdlib.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     6
#include <string.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     7
#include <X11/Xatom.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     8
#include <X11/Xutil.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     9
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    10
/* static */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    11
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    12
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    13
	const char *symbol;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    14
	void (*arrange)(void);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    15
} Layout;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    16
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    17
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    18
	const char *prop;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    19
	const char *tags;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    20
	Bool isfloating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    21
} Rule;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    22
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    23
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    24
	regex_t *propregex;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    25
	regex_t *tagregex;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    26
} Regs;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    27
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    28
TAGS
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    29
RULES
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    30
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    31
static char prop[512];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    32
static unsigned int nrules = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    33
static unsigned int nlayouts = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    34
static unsigned int ltidx = 0; /* default */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    35
static Regs *regs = NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    36
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    37
static unsigned int
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    38
idxoftag(const char *tag) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    39
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    40
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    41
	for(i = 0; i < ntags; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    42
		if(tags[i] == tag)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    43
			return i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    44
	return 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    45
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    46
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    47
static void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    48
floating(void) { /* default floating layout */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    49
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    50
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    51
	for(c = clients; c; c = c->next)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    52
		if(isvisible(c))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    53
			resize(c, c->x, c->y, c->w, c->h, True);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    54
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    55
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    56
static void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    57
setdwmprops(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    58
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    59
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    60
	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    61
		prop[i] = seltags[i] ? '1' : '0';
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    62
	if(i < sizeof prop - 1)
969
50fb50842dbc fixed misappearance of iconified windows on SIGKILL
Anselm R. Garbe <garbeam@gmail.com>
parents: 968
diff changeset
    63
		prop[i++] = (char)ltidx + '0';
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    64
	prop[i] = '\0';
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    65
	XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    66
			PropModeReplace, (unsigned char *)prop, i);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    67
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    68
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    69
LAYOUTS
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    70
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    71
/* extern */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    72
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    73
unsigned int blw = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    74
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    75
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    76
applyrules(Client *c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    77
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    78
	regmatch_t tmp;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    79
	Bool matched = False;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    80
	XClassHint ch = { 0 };
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    81
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    82
	/* rule matching */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    83
	XGetClassHint(dpy, c->win, &ch);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    84
	snprintf(prop, sizeof prop, "%s:%s:%s",
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    85
			ch.res_class ? ch.res_class : "",
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    86
			ch.res_name ? ch.res_name : "", c->name);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    87
	for(i = 0; i < nrules; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    88
		if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    89
			c->isfloating = rules[i].isfloating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    90
			for(j = 0; regs[i].tagregex && j < ntags; j++) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    91
				if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    92
					matched = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    93
					c->tags[j] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    94
				}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    95
			}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    96
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    97
	if(ch.res_class)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    98
		XFree(ch.res_class);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    99
	if(ch.res_name)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   100
		XFree(ch.res_name);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   101
	if(!matched)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   102
		for(i = 0; i < ntags; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   103
			c->tags[i] = seltags[i];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   104
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   105
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   106
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   107
arrange(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   108
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   109
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   110
	for(c = clients; c; c = c->next)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   111
		if(isvisible(c))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   112
			unban(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   113
		else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   114
			ban(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   115
	layouts[ltidx].arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   116
	focus(NULL);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   117
	restack();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   118
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   119
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   120
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   121
compileregs(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   122
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   123
	regex_t *reg;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   124
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   125
	if(regs)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   126
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   127
	nrules = sizeof rules / sizeof rules[0];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   128
	regs = emallocz(nrules * sizeof(Regs));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   129
	for(i = 0; i < nrules; i++) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   130
		if(rules[i].prop) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   131
			reg = emallocz(sizeof(regex_t));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   132
			if(regcomp(reg, rules[i].prop, REG_EXTENDED))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   133
				free(reg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   134
			else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   135
				regs[i].propregex = reg;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   136
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   137
		if(rules[i].tags) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   138
			reg = emallocz(sizeof(regex_t));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   139
			if(regcomp(reg, rules[i].tags, REG_EXTENDED))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   140
				free(reg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   141
			else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   142
				regs[i].tagregex = reg;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   143
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   144
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   145
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   146
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   147
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   148
focusnext(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   149
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   150
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   151
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   152
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   153
	for(c = sel->next; c && !isvisible(c); c = c->next);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   154
	if(!c)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   155
		for(c = clients; c && !isvisible(c); c = c->next);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   156
	if(c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   157
		focus(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   158
		restack();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   159
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   160
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   161
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   162
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   163
focusprev(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   164
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   165
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   166
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   167
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   168
	for(c = sel->prev; c && !isvisible(c); c = c->prev);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   169
	if(!c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   170
		for(c = clients; c && c->next; c = c->next);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   171
		for(; c && !isvisible(c); c = c->prev);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   172
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   173
	if(c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   174
		focus(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   175
		restack();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   176
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   177
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   178
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   179
const char *
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   180
getsymbol(void)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   181
{
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   182
	return layouts[ltidx].symbol;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   183
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   184
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   185
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   186
initlayouts(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   187
	unsigned int i, w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   188
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   189
	nlayouts = sizeof layouts / sizeof layouts[0];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   190
	for(blw = i = 0; i < nlayouts; i++) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   191
		w = textw(layouts[i].symbol);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   192
		if(w > blw)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   193
			blw = w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   194
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   195
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   196
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   197
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   198
isfloating(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   199
	return layouts[ltidx].arrange == floating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   200
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   201
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   202
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   203
isarrange(void (*func)())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   204
{
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   205
	return func == layouts[ltidx].arrange;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   206
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   207
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   208
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   209
isvisible(Client *c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   210
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   211
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   212
	for(i = 0; i < ntags; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   213
		if(c->tags[i] && seltags[i])
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   214
			return True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   215
	return False;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   216
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   217
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   218
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   219
getdwmprops(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   220
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   221
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   222
	if(gettextprop(root, dwmprops, prop, sizeof prop)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   223
		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   224
			seltags[i] = prop[i] == '1';
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   225
		if(i < sizeof prop - 1 && prop[i] != '\0') {
969
50fb50842dbc fixed misappearance of iconified windows on SIGKILL
Anselm R. Garbe <garbeam@gmail.com>
parents: 968
diff changeset
   226
			if((unsigned int)(prop[i] - '0') < nlayouts)
50fb50842dbc fixed misappearance of iconified windows on SIGKILL
Anselm R. Garbe <garbeam@gmail.com>
parents: 968
diff changeset
   227
				ltidx = prop[i] - '0';
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   228
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   229
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   230
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   231
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   232
Client *
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   233
nexttiled(Client *c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   234
	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   235
	return c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   236
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   237
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   238
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   239
restack(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   240
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   241
	XEvent ev;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   242
	XWindowChanges wc;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   243
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   244
	drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   245
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   246
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   247
	if(sel->isfloating || isfloating())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   248
		XRaiseWindow(dpy, sel->win);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   249
	if(!isfloating()) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   250
		wc.stack_mode = Below;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   251
		wc.sibling = barwin;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   252
		if(!sel->isfloating) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   253
			XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   254
			wc.sibling = sel->win;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   255
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   256
		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   257
			if(c == sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   258
				continue;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   259
			XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   260
			wc.sibling = c->win;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   261
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   262
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   263
	XSync(dpy, False);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   264
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   265
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   266
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   267
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   268
setlayout(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   269
	int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   270
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   271
	if(!arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   272
		if(++ltidx == nlayouts)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   273
			ltidx = 0;;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   274
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   275
	else {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   276
		i = atoi(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   277
		if(i < 0 || i >= nlayouts)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   278
			return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   279
		ltidx = i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   280
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   281
	if(sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   282
		arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   283
	else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   284
		drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   285
	setdwmprops();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   286
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   287
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   288
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   289
tag(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   290
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   291
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   292
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   293
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   294
	for(i = 0; i < ntags; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   295
		sel->tags[i] = arg == NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   296
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   297
	if(i >= 0 && i < ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   298
		sel->tags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   299
	setprops(sel);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   300
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   301
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   302
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   303
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   304
togglebar(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   305
	if(bpos == BarOff)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   306
		bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   307
	else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   308
		bpos = BarOff;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   309
	updatebarpos();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   310
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   311
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   312
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   313
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   314
togglefloating(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   315
	if(!sel || isfloating())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   316
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   317
	sel->isfloating = !sel->isfloating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   318
	if(sel->isfloating) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   319
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   320
		setprops(sel);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   321
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   322
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   323
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   324
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   325
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   326
togglemax(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   327
	XEvent ev;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   328
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   329
	if(!sel || (!isfloating() && !sel->isfloating) || sel->isfixed)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   330
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   331
	if((sel->ismax = !sel->ismax)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   332
		sel->rx = sel->x;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   333
		sel->ry = sel->y;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   334
		sel->rw = sel->w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   335
		sel->rh = sel->h;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   336
		resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   337
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   338
	else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   339
		resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   340
	drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   341
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   342
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   343
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   344
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   345
toggletag(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   346
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   347
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   348
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   349
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   350
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   351
	sel->tags[i] = !sel->tags[i];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   352
	for(j = 0; j < ntags && !sel->tags[j]; j++);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   353
	if(j == ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   354
		sel->tags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   355
	setprops(sel);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   356
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   357
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   358
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   359
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   360
toggleview(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   361
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   362
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   363
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   364
	seltags[i] = !seltags[i];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   365
	for(j = 0; j < ntags && !seltags[j]; j++);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   366
	if(j == ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   367
		seltags[i] = True; /* cannot toggle last view */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   368
	setdwmprops();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   369
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   370
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   371
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   372
void
968
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   373
updatebarpos(void) {
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   374
	XEvent ev;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   375
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   376
	wax = sx;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   377
	way = sy;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   378
	wah = sh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   379
	waw = sw;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   380
	switch(bpos) {
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   381
	default:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   382
		wah -= bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   383
		way += bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   384
		XMoveWindow(dpy, barwin, sx, sy);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   385
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   386
	case BarBot:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   387
		wah -= bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   388
		XMoveWindow(dpy, barwin, sx, sy + wah);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   389
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   390
	case BarOff:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   391
		XMoveWindow(dpy, barwin, sx, sy - bh);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   392
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   393
	}
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   394
	XSync(dpy, False);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   395
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   396
}
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   397
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   398
void
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   399
view(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   400
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   401
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   402
	for(i = 0; i < ntags; i++)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   403
		seltags[i] = arg == NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   404
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   405
	if(i >= 0 && i < ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   406
		seltags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   407
	setdwmprops();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   408
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   409
}