screen.c
author Anselm R. Garbe <garbeam@gmail.com>
Wed, 22 Aug 2007 19:02:17 +0200
changeset 972 c39d60829f67
parent 971 b2a0dfa22b1d
child 973 98750b173cd5
permissions -rw-r--r--
reverted release CFLAGs
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 <X11/Xutil.h>
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     7
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
     8
/* static */
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
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    11
	const char *symbol;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    12
	void (*arrange)(void);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    13
} Layout;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    14
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    15
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    16
	const char *prop;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    17
	const char *tags;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    18
	Bool isfloating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    19
} Rule;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    20
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    21
typedef struct {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    22
	regex_t *propregex;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    23
	regex_t *tagregex;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    24
} Regs;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    25
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    26
TAGS
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    27
RULES
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    28
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    29
static unsigned int nrules = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    30
static unsigned int nlayouts = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    31
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
    32
static Regs *regs = NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    33
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    34
static unsigned int
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    35
idxoftag(const char *tag) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    36
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    37
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    38
	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
    39
		if(tags[i] == tag)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    40
			return i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    41
	return 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    42
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    43
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    44
static void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    45
floating(void) { /* default floating layout */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    46
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    47
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    48
	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
    49
		if(isvisible(c))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    50
			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
    51
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    52
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    53
LAYOUTS
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
/* extern */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    56
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    57
unsigned int blw = 0;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    58
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    59
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    60
applyrules(Client *c) {
971
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
    61
	static char buf[512];
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    62
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    63
	regmatch_t tmp;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    64
	Bool matched = False;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    65
	XClassHint ch = { 0 };
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    66
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    67
	/* rule matching */
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    68
	XGetClassHint(dpy, c->win, &ch);
970
d5c3537ee3be renamed char prop[] into buf[]
Anselm R. Garbe <garbeam@gmail.com>
parents: 969
diff changeset
    69
	snprintf(buf, sizeof buf, "%s:%s:%s",
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    70
			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
    71
			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
    72
	for(i = 0; i < nrules; i++)
970
d5c3537ee3be renamed char prop[] into buf[]
Anselm R. Garbe <garbeam@gmail.com>
parents: 969
diff changeset
    73
		if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    74
			c->isfloating = rules[i].isfloating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    75
			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
    76
				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
    77
					matched = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    78
					c->tags[j] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    79
				}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    80
			}
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
	if(ch.res_class)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    83
		XFree(ch.res_class);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    84
	if(ch.res_name)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    85
		XFree(ch.res_name);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    86
	if(!matched)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    87
		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
    88
			c->tags[i] = seltags[i];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    89
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    90
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    91
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    92
arrange(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    93
	Client *c;
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
	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
    96
		if(isvisible(c))
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    97
			unban(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    98
		else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    99
			ban(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   100
	layouts[ltidx].arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   101
	focus(NULL);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   102
	restack();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   103
}
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
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   106
compileregs(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   107
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   108
	regex_t *reg;
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
	if(regs)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   111
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   112
	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
   113
	regs = emallocz(nrules * sizeof(Regs));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   114
	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
   115
		if(rules[i].prop) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   116
			reg = emallocz(sizeof(regex_t));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   117
			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
   118
				free(reg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   119
			else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   120
				regs[i].propregex = reg;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   121
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   122
		if(rules[i].tags) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   123
			reg = emallocz(sizeof(regex_t));
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   124
			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
   125
				free(reg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   126
			else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   127
				regs[i].tagregex = reg;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   128
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   129
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   130
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   131
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   132
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   133
focusnext(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   134
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   135
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   136
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   137
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   138
	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
   139
	if(!c)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   140
		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
   141
	if(c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   142
		focus(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   143
		restack();
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
focusprev(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->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
   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 && c->next; c = c->next);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   156
		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
   157
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   158
	if(c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   159
		focus(c);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   160
		restack();
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
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   163
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   164
const char *
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   165
getsymbol(void)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   166
{
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   167
	return layouts[ltidx].symbol;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   168
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   169
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   170
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   171
initlayouts(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   172
	unsigned int i, w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   173
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   174
	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
   175
	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
   176
		w = textw(layouts[i].symbol);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   177
		if(w > blw)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   178
			blw = w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   179
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   180
}
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
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   183
isfloating(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   184
	return layouts[ltidx].arrange == floating;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   185
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   186
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   187
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   188
isarrange(void (*func)())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   189
{
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   190
	return func == layouts[ltidx].arrange;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   191
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   192
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   193
Bool
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   194
isvisible(Client *c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   195
	unsigned int i;
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
	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
   198
		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
   199
			return True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   200
	return False;
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
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   203
Client *
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   204
nexttiled(Client *c) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   205
	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
   206
	return c;
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
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   209
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   210
restack(void) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   211
	Client *c;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   212
	XEvent ev;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   213
	XWindowChanges wc;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   214
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   215
	drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   216
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   217
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   218
	if(sel->isfloating || isfloating())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   219
		XRaiseWindow(dpy, sel->win);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   220
	if(!isfloating()) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   221
		wc.stack_mode = Below;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   222
		wc.sibling = barwin;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   223
		if(!sel->isfloating) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   224
			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
   225
			wc.sibling = sel->win;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   226
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   227
		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
   228
			if(c == sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   229
				continue;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   230
			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
   231
			wc.sibling = c->win;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   232
		}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   233
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   234
	XSync(dpy, False);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   235
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
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
setlayout(const char *arg) {
971
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   240
	unsigned int i;
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   241
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   242
	if(!arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   243
		if(++ltidx == nlayouts)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   244
			ltidx = 0;;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   245
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   246
	else {
971
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   247
		for(i = 0; i < nlayouts; i++)
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   248
			if(arg == layouts[i].symbol)
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   249
				break;
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   250
		if(i == nlayouts)
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   251
			return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   252
		ltidx = i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   253
	}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   254
	if(sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   255
		arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   256
	else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   257
		drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   258
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   259
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   260
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   261
tag(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   262
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   263
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   264
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   265
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   266
	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
   267
		sel->tags[i] = arg == NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   268
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   269
	if(i >= 0 && i < ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   270
		sel->tags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   271
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   272
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   273
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   274
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   275
togglebar(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   276
	if(bpos == BarOff)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   277
		bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   278
	else
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   279
		bpos = BarOff;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   280
	updatebarpos();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   281
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   282
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   283
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   284
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   285
togglefloating(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   286
	if(!sel || isfloating())
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   287
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   288
	sel->isfloating = !sel->isfloating;
971
b2a0dfa22b1d removed the _DWM_PROPERTIES handling, reverted ban/unban to XMoveWindow(), and changed argument of setlayout to layout[N].symbol check
Anselm R. Garbe <garbeam@gmail.com>
parents: 970
diff changeset
   289
	if(sel->isfloating)
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   290
		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
   291
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   292
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   293
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   294
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   295
togglemax(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   296
	XEvent ev;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   297
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   298
	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
   299
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   300
	if((sel->ismax = !sel->ismax)) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   301
		sel->rx = sel->x;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   302
		sel->ry = sel->y;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   303
		sel->rw = sel->w;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   304
		sel->rh = sel->h;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   305
		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
   306
	}
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
		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
   309
	drawstatus();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   310
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
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
toggletag(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   315
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   316
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   317
	if(!sel)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   318
		return;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   319
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   320
	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
   321
	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
   322
	if(j == ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   323
		sel->tags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   324
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   325
}
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   326
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   327
void
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   328
toggleview(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   329
	unsigned int i, j;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   330
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   331
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   332
	seltags[i] = !seltags[i];
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   333
	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
   334
	if(j == ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   335
		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
   336
	arrange();
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
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   339
void
968
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   340
updatebarpos(void) {
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   341
	XEvent ev;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   342
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   343
	wax = sx;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   344
	way = sy;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   345
	wah = sh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   346
	waw = sw;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   347
	switch(bpos) {
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   348
	default:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   349
		wah -= bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   350
		way += bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   351
		XMoveWindow(dpy, barwin, sx, sy);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   352
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   353
	case BarBot:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   354
		wah -= bh;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   355
		XMoveWindow(dpy, barwin, sx, sy + wah);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   356
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   357
	case BarOff:
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   358
		XMoveWindow(dpy, barwin, sx, sy - bh);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   359
		break;
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   360
	}
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   361
	XSync(dpy, False);
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   362
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   363
}
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   364
ce9a5452ac8c moved updatebarpos to screen
Anselm R. Garbe <garbeam@gmail.com>
parents: 967
diff changeset
   365
void
967
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   366
view(const char *arg) {
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   367
	unsigned int i;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   368
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   369
	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
   370
		seltags[i] = arg == NULL;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   371
	i = idxoftag(arg);
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   372
	if(i >= 0 && i < ntags)
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   373
		seltags[i] = True;
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   374
	arrange();
66f17bf2c278 added screen.c, removed layout.c and tag.c
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   375
}