Xinqi Bao's Git
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <sys/types.h>
11 #include <X11/Xutil.h>
15 const char *clpattern
;
30 static RReg
*rreg
= NULL
;
31 static unsigned int len
= 0;
37 for(; c
&& !isvisible(c
); c
= c
->next
);
43 for(; c
&& !isvisible(c
); c
= c
->prev
);
54 len
= sizeof(rule
) / sizeof(rule
[0]);
55 rreg
= emallocz(len
* sizeof(RReg
));
57 for(i
= 0; i
< len
; i
++) {
58 if(rule
[i
].clpattern
) {
59 reg
= emallocz(sizeof(regex_t
));
60 if(regcomp(reg
, rule
[i
].clpattern
, 0))
63 rreg
[i
].clregex
= reg
;
65 if(rule
[i
].tpattern
) {
66 reg
= emallocz(sizeof(regex_t
));
67 if(regcomp(reg
, rule
[i
].tpattern
, 0))
76 settags(Client
*c
, Client
*trans
) {
80 Bool matched
= trans
!= NULL
;
84 for(i
= 0; i
< ntags
; i
++)
85 c
->tags
[i
] = trans
->tags
[i
];
87 else if(XGetClassHint(dpy
, c
->win
, &ch
)) {
88 snprintf(prop
, sizeof(prop
), "%s:%s:%s",
89 ch
.res_class
? ch
.res_class
: "",
90 ch
.res_name
? ch
.res_name
: "", c
->name
);
91 for(i
= 0; !matched
&& i
< len
; i
++)
92 if(rreg
[i
].clregex
&& !regexec(rreg
[i
].clregex
, prop
, 1, &tmp
, 0)) {
93 c
->isfloat
= rule
[i
].isfloat
;
94 for(j
= 0; rreg
[i
].tregex
&& j
< ntags
; j
++) {
95 if(!regexec(rreg
[i
].tregex
, tags
[j
], 1, &tmp
, 0)) {
107 for(i
= 0; i
< ntags
; i
++)
108 c
->tags
[i
] = seltag
[i
];
109 for(c
->weight
= 0; c
->weight
< ntags
&& !c
->tags
[c
->weight
]; c
->weight
++);
119 for(i
= 0; i
< ntags
; i
++)
120 sel
->tags
[i
] = False
;
121 sel
->tags
[arg
->i
] = True
;
122 sel
->weight
= arg
->i
;
127 toggletag(Arg
*arg
) {
133 sel
->tags
[arg
->i
] = !sel
->tags
[arg
->i
];
134 for(i
= 0; i
< ntags
&& !sel
->tags
[i
]; i
++);
136 sel
->tags
[arg
->i
] = True
;
137 sel
->weight
= (i
== ntags
) ? arg
->i
: i
;