tag.c
author Anselm R. Garbe <garbeam@gmail.com>
Wed, 15 Aug 2007 19:27:32 +0200
changeset 953 d7de5c7bdbe4
parent 950 ebf2363d95f9
child 954 18381a2cda42
permissions -rw-r--r--
fififi
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
910
c13cb8c6b7a5 referred to LICENSE file
Anselm R. Garbe <arg@suckless.org>
parents: 909
diff changeset
     1
/* See LICENSE file for copyright and 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
     2
#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
     3
#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
     4
#include <stdio.h>
791
9ab130668f41 rechecked with OpenBSD
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
     5
#include <stdlib.h>
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
     6
#include <string.h>
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
     7
#include <X11/Xatom.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;
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    28
static char prop[512];
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
    29
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    30
static void
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    31
persistconfig(Client *c) {
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    32
	unsigned int i;
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    33
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    34
	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    35
		prop[i] = c->tags[i] ? '1' : '0';
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    36
	if(i < sizeof prop - 1)
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    37
		prop[i++] = c->isfloating ? '1' : '0';
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    38
	prop[i] = '\0';
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    39
	XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    40
			PropModeReplace, (unsigned char *)prop, i);
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    41
}
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    42
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
    43
/* 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
    44
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
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
    46
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
    47
	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
    48
	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
    49
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(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
    51
		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
    52
	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
    53
	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
    54
	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
    55
		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
    56
			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
    57
			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
    58
				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
    59
			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
    60
				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
    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
		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
    63
			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
    64
			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
    65
				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
    66
			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
    67
				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
    68
		}
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
	}
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
}
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
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
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
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
    74
	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
    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
	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
		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
    78
			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
    79
	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
    80
}
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
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
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
    83
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
    84
	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
    85
	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
    86
	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
    87
	XClassHint ch = { 0 };
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    88
	XTextProperty name;
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
    89
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    90
	if(matched) {
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
    91
		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
    92
			c->tags[i] = trans->tags[i];
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    93
	}
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
    94
	else {
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    95
		/* check if window has set a property */
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    96
		name.nitems = 0;
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
    97
		XGetTextProperty(dpy, c->win, &name, dwmconfig);
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    98
		if(name.nitems && name.encoding == XA_STRING) {
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    99
			strncpy(prop, (char *)name.value, sizeof prop - 1);
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   100
			prop[sizeof prop - 1] = '\0';
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   101
			XFree(name.value);
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   102
			for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   103
				if((c->tags[i] = prop[i] == '1'))
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   104
					matched = True;
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   105
			if(i < sizeof prop - 1 && prop[i] != '\0')
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   106
				c->isfloating = prop[i] == '1';
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   107
		}
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
   108
	}
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
   109
	if(!matched) {
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
   110
		/* rule matching */
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
   111
		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
   112
		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
   113
				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
   114
				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
   115
		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
   116
			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
   117
				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
   118
				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
   119
					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
   120
						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
   121
						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
   122
					}
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
				}
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
   124
			}
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
   125
		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
   126
			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
   127
		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
   128
			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
   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
	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
   131
		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
   132
			c->tags[i] = seltag[i];
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   133
	persistconfig(c);
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
}
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
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
   136
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
   137
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
   138
	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
   139
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
	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
   141
		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
   142
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   143
		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
   144
	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
   145
	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
   146
		sel->tags[i] = True;
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
   147
	if(sel)
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   148
		persistconfig(sel);
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   149
	arrange();
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   150
}
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   151
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   152
void
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   153
togglefloating(const char *arg) {
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   154
	if(!sel || isfloating())
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   155
		return;
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   156
	sel->isfloating = !sel->isfloating;
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   157
	if(sel->isfloating)
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   158
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   159
	arrange();
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
   160
}
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
   161
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
   162
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
   163
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
   164
	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
   165
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
   166
	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
   167
		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
   168
	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
   169
	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
   170
	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
   171
	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
   172
		sel->tags[i] = True;
950
ebf2363d95f9 small bugfix
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
   173
	if(sel)
953
Anselm R. Garbe <garbeam@gmail.com>
parents: 950
diff changeset
   174
		persistconfig(sel);
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   175
	arrange();
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
   176
}
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
   177
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
   178
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
   179
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
   180
	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
   181
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
   182
	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
   183
	seltag[i] = !seltag[i];
826
d900a3f821a3 small bugfix
Anselm R. Garbe <arg@suckless.org>
parents: 823
diff changeset
   184
	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
   185
	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
   186
		seltag[i] = True; /* cannot toggle last view */
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   187
	arrange();
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
   188
}
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
   189
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
   190
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
   191
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
   192
	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
   193
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
   194
	for(i = 0; i < ntags; i++)
827
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
   195
		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
   196
	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
   197
	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
   198
		seltag[i] = True;
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   199
	arrange();
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
   200
}