Xinqi Bao's Git
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
26 static Regs
*regs
= NULL
;
27 static unsigned int nrules
= 0;
38 nrules
= sizeof rule
/ sizeof rule
[0];
39 regs
= emallocz(nrules
* sizeof(Regs
));
40 for(i
= 0; i
< nrules
; i
++) {
42 reg
= emallocz(sizeof(regex_t
));
43 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
46 regs
[i
].propregex
= reg
;
49 reg
= emallocz(sizeof(regex_t
));
50 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
53 regs
[i
].tagregex
= reg
;
59 isvisible(Client
*c
) {
62 for(i
= 0; i
< ntags
; i
++)
63 if(c
->tags
[i
] && seltag
[i
])
69 settags(Client
*c
, Client
*trans
) {
73 Bool matched
= trans
!= NULL
;
74 XClassHint ch
= { 0 };
77 for(i
= 0; i
< ntags
; i
++)
78 c
->tags
[i
] = trans
->tags
[i
];
80 XGetClassHint(dpy
, c
->win
, &ch
);
81 snprintf(prop
, sizeof prop
, "%s:%s:%s",
82 ch
.res_class
? ch
.res_class
: "",
83 ch
.res_name
? ch
.res_name
: "", c
->name
);
84 for(i
= 0; i
< nrules
; i
++)
85 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
86 c
->isversatile
= rule
[i
].isversatile
;
87 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
88 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
100 for(i
= 0; i
< ntags
; i
++)
101 c
->tags
[i
] = seltag
[i
];
105 tag(const char *arg
) {
110 for(i
= 0; i
< ntags
; i
++)
111 sel
->tags
[i
] = arg
== NULL
;
112 i
= arg
? atoi(arg
) : 0;
113 if(i
>= 0 && i
< ntags
)
119 toggletag(const char *arg
) {
124 i
= arg
? atoi(arg
) : 0;
125 sel
->tags
[i
] = !sel
->tags
[i
];
126 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
133 toggleview(const char *arg
) {
136 i
= arg
? atoi(arg
) : 0;
137 seltag
[i
] = !seltag
[i
];
138 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
140 seltag
[i
] = True
; /* cannot toggle last view */
145 view(const char *arg
) {
148 for(i
= 0; i
< ntags
; i
++)
149 seltag
[i
] = arg
== NULL
;
150 i
= arg
? atoi(arg
) : 0;
151 if(i
>= 0 && i
< ntags
)