Xinqi Bao's Git
1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
14 const char *clpattern
;
29 static RReg
*rreg
= NULL
;
30 static unsigned int len
= 0;
36 for(; c
&& !isvisible(c
); c
= c
->next
);
42 for(; c
&& !isvisible(c
); c
= c
->prev
);
53 len
= sizeof(rule
) / sizeof(rule
[0]);
54 rreg
= emallocz(len
* sizeof(RReg
));
55 for(i
= 0; i
< len
; i
++) {
56 if(rule
[i
].clpattern
) {
57 reg
= emallocz(sizeof(regex_t
));
58 if(regcomp(reg
, rule
[i
].clpattern
, 0))
61 rreg
[i
].clregex
= reg
;
63 if(rule
[i
].tpattern
) {
64 reg
= emallocz(sizeof(regex_t
));
65 if(regcomp(reg
, rule
[i
].tpattern
, 0))
74 settags(Client
*c
, Client
*trans
) {
78 Bool matched
= trans
!= NULL
;
82 for(i
= 0; i
< ntags
; i
++)
83 c
->tags
[i
] = trans
->tags
[i
];
85 else if(XGetClassHint(dpy
, c
->win
, &ch
)) {
86 snprintf(prop
, sizeof(prop
), "%s:%s:%s",
87 ch
.res_class
? ch
.res_class
: "",
88 ch
.res_name
? ch
.res_name
: "", c
->name
);
89 for(i
= 0; !matched
&& i
< len
; i
++)
90 if(rreg
[i
].clregex
&& !regexec(rreg
[i
].clregex
, prop
, 1, &tmp
, 0)) {
91 c
->isfloat
= rule
[i
].isfloat
;
92 for(j
= 0; rreg
[i
].tregex
&& j
< ntags
; j
++) {
93 if(!regexec(rreg
[i
].tregex
, tags
[j
], 1, &tmp
, 0)) {
105 for(i
= 0; i
< ntags
; i
++)
106 c
->tags
[i
] = seltag
[i
];
107 for(c
->weight
= 0; c
->weight
< ntags
&& !c
->tags
[c
->weight
]; c
->weight
++);
116 for(i
= 0; i
< ntags
; i
++)
117 sel
->tags
[i
] = False
;
118 sel
->tags
[arg
->i
] = True
;
119 sel
->weight
= arg
->i
;
124 toggletag(Arg
*arg
) {
129 sel
->tags
[arg
->i
] = !sel
->tags
[arg
->i
];
130 for(i
= 0; i
< ntags
&& !sel
->tags
[i
]; i
++);
132 sel
->tags
[arg
->i
] = True
;
133 sel
->weight
= (i
== ntags
) ? arg
->i
: i
;