Mercurial > aewl
annotate tag.c @ 383:2ec9cead84a7
applied patch similiar proposed by dave tweed
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Tue, 29 Aug 2006 17:11:37 +0200 |
parents | b00cc483d13b |
children | 126e78129f1d |
rev | line source |
---|---|
75 | 1 /* |
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | |
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 | 6 #include <regex.h> |
7 #include <stdio.h> | |
191 | 8 #include <stdlib.h> |
75 | 9 #include <string.h> |
114 | 10 #include <sys/types.h> |
75 | 11 #include <X11/Xutil.h> |
12 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
13 |
114 | 14 typedef struct { |
191 | 15 const char *clpattern; |
16 const char *tpattern; | |
114 | 17 Bool isfloat; |
18 } Rule; | |
19 | |
191 | 20 typedef struct { |
21 regex_t *clregex; | |
22 regex_t *tregex; | |
23 } RReg; | |
24 | |
25 /* static */ | |
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 | 30 static RReg *rreg = NULL; |
31 static unsigned int len = 0; | |
32 | |
383
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
33 static void |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
34 applytag() |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
35 { |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
36 /* asserts sel != NULL */ |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
37 settitle(sel); |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
38 if(!isvisible(sel)) |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
39 arrange(NULL); |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
40 else |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
41 drawstatus(); |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
42 } |
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
43 |
125 | 44 /* extern */ |
45 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
46 Client * |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
138
diff
changeset
|
47 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
|
48 { |
261
d6fd632d861c
implement multi-tag selection through button3 click on the specific tag
Anselm R.Garbe <arg@10ksloc.org>
parents:
240
diff
changeset
|
49 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
|
50 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
|
51 } |
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
|
52 |
127
1480e19f6377
using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents:
125
diff
changeset
|
53 Client * |
1480e19f6377
using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents:
125
diff
changeset
|
54 getprev(Client *c) |
1480e19f6377
using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents:
125
diff
changeset
|
55 { |
261
d6fd632d861c
implement multi-tag selection through button3 click on the specific tag
Anselm R.Garbe <arg@10ksloc.org>
parents:
240
diff
changeset
|
56 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
|
57 return c; |
1480e19f6377
using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents:
125
diff
changeset
|
58 } |
1480e19f6377
using double-linked list in order to get correct prev focus handling
arg@10ksloc.org
parents:
125
diff
changeset
|
59 |
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
|
60 void |
191 | 61 initrregs() |
62 { | |
63 unsigned int i; | |
64 regex_t *reg; | |
65 | |
66 if(rreg) | |
67 return; | |
68 len = sizeof(rule) / sizeof(rule[0]); | |
69 rreg = emallocz(len * sizeof(RReg)); | |
70 | |
71 for(i = 0; i < len; i++) { | |
72 if(rule[i].clpattern) { | |
73 reg = emallocz(sizeof(regex_t)); | |
74 if(regcomp(reg, rule[i].clpattern, 0)) | |
75 free(reg); | |
76 else | |
77 rreg[i].clregex = reg; | |
78 } | |
79 if(rule[i].tpattern) { | |
80 reg = emallocz(sizeof(regex_t)); | |
81 if(regcomp(reg, rule[i].tpattern, 0)) | |
82 free(reg); | |
83 else | |
84 rreg[i].tregex = reg; | |
85 } | |
86 } | |
87 } | |
88 | |
270
dacd3f3c5823
implemented restack behavior (floats are on top in tiled mode)
Anselm R.Garbe <arg@10ksloc.org>
parents:
267
diff
changeset
|
89 void |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
90 settags(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
91 { |
336
2a65e8b3d21a
implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents:
327
diff
changeset
|
92 char prop[512]; |
191 | 93 unsigned int i, j; |
114 | 94 regmatch_t tmp; |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
95 Bool matched = False; |
114 | 96 XClassHint ch; |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
97 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
98 if(XGetClassHint(dpy, c->win, &ch)) { |
336
2a65e8b3d21a
implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents:
327
diff
changeset
|
99 snprintf(prop, sizeof(prop), "%s:%s:%s", |
114 | 100 ch.res_class ? ch.res_class : "", |
336
2a65e8b3d21a
implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents:
327
diff
changeset
|
101 ch.res_name ? ch.res_name : "", c->name); |
191 | 102 for(i = 0; !matched && i < len; i++) |
336
2a65e8b3d21a
implemented class:inst:title matching
Anselm R. Garbe <arg@10kloc.org>
parents:
327
diff
changeset
|
103 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { |
191 | 104 c->isfloat = rule[i].isfloat; |
105 for(j = 0; rreg[i].tregex && j < ntags; j++) { | |
106 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { | |
107 matched = True; | |
108 c->tags[j] = True; | |
109 } | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
110 } |
114 | 111 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
112 if(ch.res_class) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
113 XFree(ch.res_class); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
114 if(ch.res_name) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
115 XFree(ch.res_name); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
116 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
117 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
|
118 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
|
119 c->tags[i] = seltag[i]; |
381
b00cc483d13b
still something wrong with reorder()
Anselm R. Garbe <arg@10kloc.org>
parents:
379
diff
changeset
|
120 for(i = 0; i < ntags && !c->tags[i]; i++); |
b00cc483d13b
still something wrong with reorder()
Anselm R. Garbe <arg@10kloc.org>
parents:
379
diff
changeset
|
121 c->weight = i; |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
122 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
123 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
124 void |
284
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
125 tag(Arg *arg) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
126 { |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
127 unsigned int i; |
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 if(!sel) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
130 return; |
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 for(i = 0; i < ntags; i++) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
133 sel->tags[i] = False; |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
134 sel->tags[arg->i] = True; |
383
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
135 applytag(); |
284
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 |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
138 void |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
139 toggletag(Arg *arg) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
140 { |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
141 unsigned int i; |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
142 |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
143 if(!sel) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
144 return; |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
145 |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
146 sel->tags[arg->i] = !sel->tags[arg->i]; |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
147 for(i = 0; i < ntags && !sel->tags[i]; i++); |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
148 if(i == ntags) |
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
149 sel->tags[arg->i] = True; |
383
2ec9cead84a7
applied patch similiar proposed by dave tweed
Anselm R. Garbe <arg@10kloc.org>
parents:
381
diff
changeset
|
150 applytag(); |
284
5f5c56e104de
changed replacetag into toggletag
Anselm R.Garbe <arg@10ksloc.org>
parents:
277
diff
changeset
|
151 } |