tag.c
author Anselm R. Garbe <arg@suckless.org>
Fri, 16 Feb 2007 10:20:34 +0100
changeset 761 4e835c2a7a12
parent 757 22dfaeb82491
child 769 dc60583894e0
permissions -rw-r--r--
removed getnext/getprev, redundant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
644
1ed8c40dde36 corrections
arg@mig29
parents: 643
diff changeset
     1
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     2
 * See LICENSE file for license details.
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     3
 */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     4
#include "dwm.h"
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
     5
#include <regex.h>
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
     6
#include <stdio.h>
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
     7
#include <stdlib.h>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     8
#include <string.h>
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
     9
#include <sys/types.h>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    10
#include <X11/Xutil.h>
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
    11
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    12
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    13
typedef struct {
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    14
	const char *clpattern;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    15
	const char *tpattern;
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    16
	Bool isfloat;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    17
} Rule;
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    18
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    19
typedef struct {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    20
	regex_t *clregex;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    21
	regex_t *tregex;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    22
} RReg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    23
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    24
/* static */
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    25
146
f328ce9c558c centralized/externalized configuration to config.h
arg@10ksloc.org
parents: 144
diff changeset
    26
TAGS
f328ce9c558c centralized/externalized configuration to config.h
arg@10ksloc.org
parents: 144
diff changeset
    27
RULES
84
052fe7498930 ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents: 80
diff changeset
    28
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    29
static RReg *rreg = NULL;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    30
static unsigned int len = 0;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    31
125
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    32
/* extern */
b4b8b4236599 cleaned the CUSTOMIZE flags
arg@10ksloc.org
parents: 124
diff changeset
    33
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
    34
void
487
be4f90c03582 applied Jukkas patch
arg@mmvi
parents: 461
diff changeset
    35
initrregs(void) {
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    36
	unsigned int i;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    37
	regex_t *reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    38
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    39
	if(rreg)
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    40
		return;
581
601842ee4484 applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents: 573
diff changeset
    41
	len = sizeof rule / sizeof rule[0];
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    42
	rreg = emallocz(len * sizeof(RReg));
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    43
	for(i = 0; i < len; i++) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    44
		if(rule[i].clpattern) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    45
			reg = emallocz(sizeof(regex_t));
609
dcbbfabc8ecc applied Manuel's regex patch
arg@mig29
parents: 594
diff changeset
    46
			if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    47
				free(reg);
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    48
			else
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    49
				rreg[i].clregex = reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    50
		}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    51
		if(rule[i].tpattern) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    52
			reg = emallocz(sizeof(regex_t));
609
dcbbfabc8ecc applied Manuel's regex patch
arg@mig29
parents: 594
diff changeset
    53
			if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    54
				free(reg);
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    55
			else
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    56
				rreg[i].tregex = reg;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    57
		}
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    58
	}
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
270
dacd3f3c5823 implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents: 267
diff changeset
    61
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 441
diff changeset
    62
settags(Client *c, Client *trans) {
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    63
	char prop[512];
191
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    64
	unsigned int i, j;
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    65
	regmatch_t tmp;
431
a230e4432bb7 moved transient_for tag inheritance to settags
Anselm R. Garbe <arg@10kloc.org>
parents: 430
diff changeset
    66
	Bool matched = trans != NULL;
742
39b941868ce3 adapting John Grahor's patch to dwm-3.5
Anselm R. Garbe <arg@suckless.org>
parents: 644
diff changeset
    67
	XClassHint ch = { 0 };
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    68
757
22dfaeb82491 made for/if/else constructs more consistent, some code polishing
Anselm R. Garbe <arg@suckless.org>
parents: 742
diff changeset
    69
	if(matched)
431
a230e4432bb7 moved transient_for tag inheritance to settags
Anselm R. Garbe <arg@10kloc.org>
parents: 430
diff changeset
    70
		for(i = 0; i < ntags; i++)
a230e4432bb7 moved transient_for tag inheritance to settags
Anselm R. Garbe <arg@10kloc.org>
parents: 430
diff changeset
    71
			c->tags[i] = trans->tags[i];
742
39b941868ce3 adapting John Grahor's patch to dwm-3.5
Anselm R. Garbe <arg@suckless.org>
parents: 644
diff changeset
    72
	else {
39b941868ce3 adapting John Grahor's patch to dwm-3.5
Anselm R. Garbe <arg@suckless.org>
parents: 644
diff changeset
    73
		XGetClassHint(dpy, c->win, &ch);
581
601842ee4484 applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents: 573
diff changeset
    74
		snprintf(prop, sizeof prop, "%s:%s:%s",
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    75
				ch.res_class ? ch.res_class : "",
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    76
				ch.res_name ? ch.res_name : "", c->name);
609
dcbbfabc8ecc applied Manuel's regex patch
arg@mig29
parents: 594
diff changeset
    77
		for(i = 0; i < len; i++)
336
2a65e8b3d21a implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
    78
			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
    79
				c->isfloat = rule[i].isfloat;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    80
				for(j = 0; rreg[i].tregex && j < ntags; j++) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    81
					if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    82
						matched = True;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    83
						c->tags[j] = True;
56fee1dc9d53 switched to regexp matching for Rules
arg@10ksloc.org
parents: 178
diff changeset
    84
					}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    85
				}
114
dfa5cd0969a6 implemented regexp matching for rules
arg@10ksloc.org
parents: 104
diff changeset
    86
			}
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    87
		if(ch.res_class)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    88
			XFree(ch.res_class);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    89
		if(ch.res_name)
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    90
			XFree(ch.res_name);
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    91
	}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    92
	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
    93
		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
    94
			c->tags[i] = seltag[i];
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    95
}
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    96
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
    97
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 441
diff changeset
    98
tag(Arg *arg) {
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
    99
	unsigned int i;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   100
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   101
	if(!sel)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   102
		return;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   103
	for(i = 0; i < ntags; i++)
594
f7dcd3ac8d6f removed viewall(), replaced with view(-1); added tag(-1) to tag a client with all tags (new key combo MODKEY-Shift-0)
arg@mig29
parents: 581
diff changeset
   104
		sel->tags[i] = (arg->i == -1) ? True : False;
611
c7f84f23ec5a hotfix of a serious crashing bug
arg@mig29
parents: 609
diff changeset
   105
	if(arg->i >= 0 && arg->i < ntags)
c7f84f23ec5a hotfix of a serious crashing bug
arg@mig29
parents: 609
diff changeset
   106
		sel->tags[arg->i] = True;
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
   107
	arrange();
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   108
}
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   109
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   110
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 441
diff changeset
   111
toggletag(Arg *arg) {
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   112
	unsigned int i;
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
	if(!sel)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   115
		return;
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   116
	sel->tags[arg->i] = !sel->tags[arg->i];
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   117
	for(i = 0; i < ntags && !sel->tags[i]; i++);
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   118
	if(i == ntags)
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   119
		sel->tags[arg->i] = True;
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
   120
	arrange();
284
5f5c56e104de changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents: 277
diff changeset
   121
}