tag.c
author Anselm R. Garbe <arg@10kloc.org>
Wed, 23 Aug 2006 18:50:46 +0200
changeset 342 a1901753deef
parent 340 ae0affabdc02
child 379 fc279cd6c7be
permissions -rw-r--r--
updated man page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     1
/*
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     2
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     3
 * See LICENSE file for license details.
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     4
 */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     5
#include "dwm.h"
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
     6
#include <regex.h>
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
     7
#include <stdio.h>
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
     8
#include <stdlib.h>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     9
#include <string.h>
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    10
#include <sys/types.h>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    11
#include <X11/Xutil.h>
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    12
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    13
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    14
typedef struct {
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    15
	const char *clpattern;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    16
	const char *tpattern;
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    17
	Bool isfloat;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    18
} Rule;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    19
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    20
typedef struct {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    21
	regex_t *clregex;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    22
	regex_t *tregex;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    23
} RReg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    24
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    25
/* static */
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    26
146
f328ce9c558c centralized/externalized configuration to config.h
arg@10ksloc.org
parents: 144
diff changeset
    27
TAGS
f328ce9c558c centralized/externalized configuration to config.h
arg@10ksloc.org
parents: 144
diff changeset
    28
RULES
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 80
diff changeset
    29
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    30
static RReg *rreg = NULL;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    31
static unsigned int len = 0;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    32
125
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    33
/* extern */
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    34
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    35
Client *
142
9b9deafa0508 committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents: 138
diff changeset
    36
getnext(Client *c)
93
c498da7520c7 added heretag command which allows to tag a client of a foreign tag with current tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 84
diff changeset
    37
{
261
d6fd632d861c implement multi-tag selection through button3 click on the specific tag
Anselm R.Garbe <arg@10ksloc.org>
parents: 240
diff changeset
    38
	for(; c && !isvisible(c); c = c->next);
93
c498da7520c7 added heretag command which allows to tag a client of a foreign tag with current tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 84
diff changeset
    39
	return c;
c498da7520c7 added heretag command which allows to tag a client of a foreign tag with current tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 84
diff changeset
    40
}
c498da7520c7 added heretag command which allows to tag a client of a foreign tag with current tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 84
diff changeset
    41
127
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    42
Client *
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    43
getprev(Client *c)
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    44
{
261
d6fd632d861c implement multi-tag selection through button3 click on the specific tag
Anselm R.Garbe <arg@10ksloc.org>
parents: 240
diff changeset
    45
	for(; c && !isvisible(c); c = c->prev);
127
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    46
	return c;
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    47
}
1480e19f6377 using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents: 125
diff changeset
    48
93
c498da7520c7 added heretag command which allows to tag a client of a foreign tag with current tag
Anselm R. Garbe <garbeam@wmii.de>
parents: 84
diff changeset
    49
void
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    50
initrregs()
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    51
{
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    52
	unsigned int i;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    53
	regex_t *reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    54
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    55
	if(rreg)
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    56
		return;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    57
	len = sizeof(rule) / sizeof(rule[0]);
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    58
	rreg = emallocz(len * sizeof(RReg));
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    59
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    60
	for(i = 0; i < len; i++) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    61
		if(rule[i].clpattern) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    62
			reg = emallocz(sizeof(regex_t));
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    63
			if(regcomp(reg, rule[i].clpattern, 0))
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    64
				free(reg);
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    65
			else
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    66
				rreg[i].clregex = reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    67
		}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    68
		if(rule[i].tpattern) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    69
			reg = emallocz(sizeof(regex_t));
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    70
			if(regcomp(reg, rule[i].tpattern, 0))
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    71
				free(reg);
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    72
			else
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    73
				rreg[i].tregex = reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    74
		}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    75
	}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    76
}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    77
270
dacd3f3c5823 implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents: 267
diff changeset
    78
void
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    79
settags(Client *c)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    80
{
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    81
	char prop[512];
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    82
	unsigned int i, j;
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    83
	regmatch_t tmp;
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    84
	Bool matched = False;
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    85
	XClassHint ch;
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    86
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    87
	if(XGetClassHint(dpy, c->win, &ch)) {
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    88
		snprintf(prop, sizeof(prop), "%s:%s:%s",
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    89
				ch.res_class ? ch.res_class : "",
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    90
				ch.res_name ? ch.res_name : "", c->name);
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    91
		for(i = 0; !matched && i < len; i++)
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    92
			if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    93
				c->isfloat = rule[i].isfloat;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    94
				for(j = 0; rreg[i].tregex && j < ntags; j++) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    95
					if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    96
						matched = True;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    97
						c->tags[j] = True;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    98
					}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    99
				}
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
   100
			}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   101
		if(ch.res_class)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   102
			XFree(ch.res_class);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   103
		if(ch.res_name)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   104
			XFree(ch.res_name);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   105
	}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   106
	if(!matched)
261
d6fd632d861c implement multi-tag selection through button3 click on the specific tag
Anselm R.Garbe <arg@10ksloc.org>
parents: 240
diff changeset
   107
		for(i = 0; i < ntags; i++)
262
d659a2dce2b5 implemented viewextend and added M-S-C-n shortcuts for extending the current view... updated man page (works great!) nice feature
Anselm R.Garbe <arg@10ksloc.org>
parents: 261
diff changeset
   108
			c->tags[i] = seltag[i];
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   109
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   110
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
   111
void
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   112
tag(Arg *arg)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   113
{
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   114
	unsigned int i;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   115
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   116
	if(!sel)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   117
		return;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   118
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   119
	for(i = 0; i < ntags; i++)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   120
		sel->tags[i] = False;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   121
	sel->tags[arg->i] = True;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   122
	settitle(sel);
287
5e5e5392c7cb applied sanders tag()/toggletag() fixes
Anselm R.Garbe <arg@10ksloc.org>
parents: 285
diff changeset
   123
	if(!isvisible(sel))
5e5e5392c7cb applied sanders tag()/toggletag() fixes
Anselm R.Garbe <arg@10ksloc.org>
parents: 285
diff changeset
   124
		arrange(NULL);
340
ae0affabdc02 implemented right tag drawing in the status bar and titlebars
Anselm R. Garbe <arg@10kloc.org>
parents: 336
diff changeset
   125
	else
ae0affabdc02 implemented right tag drawing in the status bar and titlebars
Anselm R. Garbe <arg@10kloc.org>
parents: 336
diff changeset
   126
		drawstatus();
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   127
}
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   128
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   129
void
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   130
toggletag(Arg *arg)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   131
{
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   132
	unsigned int i;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   133
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   134
	if(!sel)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   135
		return;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   136
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   137
	sel->tags[arg->i] = !sel->tags[arg->i];
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   138
	for(i = 0; i < ntags && !sel->tags[i]; i++);
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   139
	if(i == ntags)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   140
		sel->tags[arg->i] = True;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   141
	settitle(sel);
287
5e5e5392c7cb applied sanders tag()/toggletag() fixes
Anselm R.Garbe <arg@10ksloc.org>
parents: 285
diff changeset
   142
	if(!isvisible(sel))
5e5e5392c7cb applied sanders tag()/toggletag() fixes
Anselm R.Garbe <arg@10ksloc.org>
parents: 285
diff changeset
   143
		arrange(NULL);
342
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   144
	else
a1901753deef updated man page
Anselm R. Garbe <arg@10kloc.org>
parents: 340
diff changeset
   145
		drawstatus();
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   146
}