tag.c
author Anselm R. Garbe <arg@suckless.org>
Fri, 13 Apr 2007 11:32:38 +0200
changeset 857 453788ae925c
parent 837 123231b9eb87
child 858 b797071ebbd4
permissions -rw-r--r--
making Copyright notices more compact
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
857
453788ae925c making Copyright notices more compact
Anselm R. Garbe <arg@suckless.org>
parents: 837
diff changeset
     1
/* © 2004-2007 Anselm R. Garbe <garbeam at gmail dot com>
453788ae925c making Copyright notices more compact
Anselm R. Garbe <arg@suckless.org>
parents: 837
diff changeset
     2
 * See LICENSE file for license details. */
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     3
#include "dwm.h"
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     4
#include <regex.h>
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     5
#include <stdio.h>
791
9ab130668f41 rechecked with OpenBSD
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
     6
#include <stdlib.h>
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     7
#include <X11/Xutil.h>
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     8
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
     9
/* static */
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    10
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    11
typedef struct {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    12
	const char *prop;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    13
	const char *tags;
837
123231b9eb87 renamed untiled into floating, keeping tiled instead of tiling (afaik tiled sounds more correct) - English speakers convinced me
Anselm R. Garbe <arg@suckless.org>
parents: 830
diff changeset
    14
	Bool isfloating;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    15
} Rule;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    16
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    17
typedef struct {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    18
	regex_t *propregex;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    19
	regex_t *tagregex;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    20
} Regs;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    21
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    22
TAGS
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    23
RULES
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    24
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    25
static Regs *regs = NULL;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    26
static unsigned int nrules = 0;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    27
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    28
/* extern */
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    29
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    30
void
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    31
compileregs(void) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    32
	unsigned int i;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    33
	regex_t *reg;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    34
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    35
	if(regs)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    36
		return;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    37
	nrules = sizeof rule / sizeof rule[0];
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    38
	regs = emallocz(nrules * sizeof(Regs));
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    39
	for(i = 0; i < nrules; i++) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    40
		if(rule[i].prop) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    41
			reg = emallocz(sizeof(regex_t));
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    42
			if(regcomp(reg, rule[i].prop, REG_EXTENDED))
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    43
				free(reg);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    44
			else
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    45
				regs[i].propregex = reg;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    46
		}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    47
		if(rule[i].tags) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    48
			reg = emallocz(sizeof(regex_t));
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    49
			if(regcomp(reg, rule[i].tags, REG_EXTENDED))
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    50
				free(reg);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    51
			else
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    52
				regs[i].tagregex = reg;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    53
		}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    54
	}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    55
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    56
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    57
Bool
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    58
isvisible(Client *c) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    59
	unsigned int i;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    60
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    61
	for(i = 0; i < ntags; i++)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    62
		if(c->tags[i] && seltag[i])
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    63
			return True;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    64
	return False;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    65
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    66
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    67
void
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    68
settags(Client *c, Client *trans) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    69
	char prop[512];
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    70
	unsigned int i, j;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    71
	regmatch_t tmp;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    72
	Bool matched = trans != NULL;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    73
	XClassHint ch = { 0 };
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    74
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    75
	if(matched)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    76
		for(i = 0; i < ntags; i++)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    77
			c->tags[i] = trans->tags[i];
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    78
	else {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    79
		XGetClassHint(dpy, c->win, &ch);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    80
		snprintf(prop, sizeof prop, "%s:%s:%s",
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    81
				ch.res_class ? ch.res_class : "",
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    82
				ch.res_name ? ch.res_name : "", c->name);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    83
		for(i = 0; i < nrules; i++)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    84
			if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
837
123231b9eb87 renamed untiled into floating, keeping tiled instead of tiling (afaik tiled sounds more correct) - English speakers convinced me
Anselm R. Garbe <arg@suckless.org>
parents: 830
diff changeset
    85
				c->isfloating = rule[i].isfloating;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    86
				for(j = 0; regs[i].tagregex && j < ntags; j++) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    87
					if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    88
						matched = True;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    89
						c->tags[j] = True;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    90
					}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    91
				}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    92
			}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    93
		if(ch.res_class)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    94
			XFree(ch.res_class);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    95
		if(ch.res_name)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    96
			XFree(ch.res_name);
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    97
	}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    98
	if(!matched)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
    99
		for(i = 0; i < ntags; i++)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   100
			c->tags[i] = seltag[i];
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   101
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   102
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   103
void
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   104
tag(const char *arg) {
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   105
	int i;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   106
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   107
	if(!sel)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   108
		return;
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   109
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   110
		sel->tags[i] = arg == NULL;
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   111
	i = arg ? atoi(arg) : 0;
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   112
	if(i >= 0 && i < ntags)
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   113
		sel->tags[i] = True;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   114
	lt->arrange();
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   115
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   116
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   117
void
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   118
toggletag(const char *arg) {
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   119
	int i, j;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   120
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   121
	if(!sel)
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   122
		return;
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   123
	i = arg ? atoi(arg) : 0;
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   124
	sel->tags[i] = !sel->tags[i];
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   125
	for(j = 0; j < ntags && !sel->tags[j]; j++);
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   126
	if(j == ntags)
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   127
		sel->tags[i] = True;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   128
	lt->arrange();
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   129
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   130
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   131
void
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   132
toggleview(const char *arg) {
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   133
	int i, j;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   134
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   135
	i = arg ? atoi(arg) : 0;
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   136
	seltag[i] = !seltag[i];
826
d900a3f821a3 small bugfix
Anselm R. Garbe <arg@suckless.org>
parents: 823
diff changeset
   137
	for(j = 0; j < ntags && !seltag[j]; j++);
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   138
	if(j == ntags)
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   139
		seltag[i] = True; /* cannot toggle last view */
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   140
	lt->arrange();
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   141
}
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   142
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   143
void
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   144
view(const char *arg) {
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   145
	int i;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   146
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   147
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   148
		seltag[i] = arg == NULL;
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   149
	i = arg ? atoi(arg) : 0;
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   150
	if(i >= 0 && i < ntags)
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 813
diff changeset
   151
		seltag[i] = True;
790
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   152
	lt->arrange();
48e7c3b45250 split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
Anselm R. Garbe <arg@suckless.org>
parents:
diff changeset
   153
}