Xinqi Bao's Git
f54ac3f83da11a02d8cbe2c99ce528aa637ea1d1
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
25 static Regs
*regs
= NULL
;
26 static unsigned int nrules
= 0;
37 nrules
= sizeof rule
/ sizeof rule
[0];
38 regs
= emallocz(nrules
* sizeof(Regs
));
39 for(i
= 0; i
< nrules
; i
++) {
41 reg
= emallocz(sizeof(regex_t
));
42 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
45 regs
[i
].propregex
= reg
;
48 reg
= emallocz(sizeof(regex_t
));
49 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
52 regs
[i
].tagregex
= reg
;
58 isvisible(Client
*c
) {
61 for(i
= 0; i
< ntags
; i
++)
62 if(c
->tags
[i
] && seltag
[i
])
68 settags(Client
*c
, Client
*trans
) {
72 Bool matched
= trans
!= NULL
;
73 XClassHint ch
= { 0 };
76 for(i
= 0; i
< ntags
; i
++)
77 c
->tags
[i
] = trans
->tags
[i
];
79 XGetClassHint(dpy
, c
->win
, &ch
);
80 snprintf(prop
, sizeof prop
, "%s:%s:%s",
81 ch
.res_class
? ch
.res_class
: "",
82 ch
.res_name
? ch
.res_name
: "", c
->name
);
83 for(i
= 0; i
< nrules
; i
++)
84 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
85 c
->isversatile
= rule
[i
].isversatile
;
86 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
87 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
99 for(i
= 0; i
< ntags
; i
++)
100 c
->tags
[i
] = seltag
[i
];
109 for(i
= 0; i
< ntags
; i
++)
110 sel
->tags
[i
] = (arg
->i
== -1) ? True
: False
;
111 if(arg
->i
>= 0 && arg
->i
< ntags
)
112 sel
->tags
[arg
->i
] = True
;
117 toggletag(Arg
*arg
) {
122 sel
->tags
[arg
->i
] = !sel
->tags
[arg
->i
];
123 for(i
= 0; i
< ntags
&& !sel
->tags
[i
]; i
++);
125 sel
->tags
[arg
->i
] = True
;
130 toggleview(Arg
*arg
) {
133 seltag
[arg
->i
] = !seltag
[arg
->i
];
134 for(i
= 0; i
< ntags
&& !seltag
[i
]; i
++);
136 seltag
[arg
->i
] = True
; /* cannot toggle last view */
144 for(i
= 0; i
< ntags
; i
++)
145 seltag
[i
] = (arg
->i
== -1) ? True
: False
;
146 if(arg
->i
>= 0 && arg
->i
< ntags
)
147 seltag
[arg
->i
] = True
;