tag.c
author Anselm R. Garbe <arg@suckless.org>
Wed, 16 May 2007 22:05:02 +0200
changeset 889 00f4180df72b
parent 858 b797071ebbd4
child 905 ca352bd2f8f7
permissions -rw-r--r--
no that change breaks fullscreen apps
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
858
b797071ebbd4 yet another fix of copyright compactisition
Anselm R. Garbe <arg@suckless.org>
parents: 857
diff changeset
     1
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
b797071ebbd4 yet another fix of copyright compactisition
Anselm R. Garbe <arg@suckless.org>
parents: 857
diff changeset
     2
 * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
857
453788ae925c making Copyright notices more compact
Anselm R. Garbe <arg@suckless.org>
parents: 837
diff changeset
     3
 * 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
     4
#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
     5
#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
     6
#include <stdio.h>
791
9ab130668f41 rechecked with OpenBSD
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
     7
#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
     8
#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
     9
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
/* 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
    11
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
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
    13
	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
    14
	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
    15
	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
    16
} 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
    17
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
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
    19
	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
    20
	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
    21
} 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
    22
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
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
    24
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
    25
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 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
    27
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
    28
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
/* 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
    30
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
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
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
    33
	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
    34
	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
    35
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
	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
    37
		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
    38
	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
    39
	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
    40
	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
    41
		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
    42
			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
    43
			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
    44
				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
    45
			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
    46
				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
    47
		}
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
		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
    49
			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
    50
			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
    51
				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
    52
			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
    53
				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
    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
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
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
    59
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
    60
	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
    61
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
	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
    63
		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
    64
			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
    65
	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
    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
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
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
    69
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
    70
	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
    71
	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
    72
	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
    73
	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
    74
	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
    75
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
	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
    77
		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
    78
			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
    79
	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
    80
		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
    81
		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
    82
				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
    83
				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
    84
		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
    85
			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
    86
				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
    87
				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
    88
					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
    89
						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
    90
						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
    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
			}
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
		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
    95
			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
    96
		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
    97
			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
    98
	}
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
	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
   100
		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
   101
			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
   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
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
   104
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
   105
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
   106
	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
   107
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
	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
   109
		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
   110
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   111
		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
   112
	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
   113
	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
   114
		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
   115
	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
   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
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
   118
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
   119
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
   120
	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
   121
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
	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
   123
		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
   124
	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
   125
	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
   126
	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
   127
	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
   128
		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
   129
	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
   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
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
   132
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
   133
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
   134
	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
   135
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
   136
	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
   137
	seltag[i] = !seltag[i];
826
d900a3f821a3 small bugfix
Anselm R. Garbe <arg@suckless.org>
parents: 823
diff changeset
   138
	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
   139
	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
   140
		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
   141
	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
   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
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
   144
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
   145
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
   146
	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
   147
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
   148
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   149
		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
   150
	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
   151
	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
   152
		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
   153
	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
   154
}