2 * rules.c - rules management
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 extern AwesomeConf globalconf
;
28 rules_compile_regex(char *val
)
34 reg
= p_new(regex_t
, 1);
35 if(regcomp(reg
, val
, REG_EXTENDED
))
45 client_match_rule(Client
*c
, Rule
*r
)
50 XClassHint ch
= { 0, 0 };
55 /* first try to match on name */
56 XGetClassHint(globalconf
.display
, c
->win
, &ch
);
58 len
= a_strlen(ch
.res_class
) + a_strlen(ch
.res_name
) + a_strlen(c
->name
);
59 prop
= p_new(char, len
+ 3);
62 snprintf(prop
, len
+ 3, "%s:%s:%s",
63 ch
.res_class
? ch
.res_class
: "", ch
.res_name
? ch
.res_name
: "", c
->name
);
65 ret
= !regexec(r
->prop_r
, prop
, 1, &tmp
, 0);
80 && xgettextprop(c
->win
,
81 XInternAtom(globalconf
.display
, r
->xprop
, False
),
83 ret
= !regexec(r
->xpropval_r
, buf
, 1, &tmp
, 0);
89 tag_match_rule(Tag
*t
, Rule
*r
)
93 if(r
->tags_r
&& !regexec(r
->tags_r
, t
->name
, 1, &tmp
, 0))
100 rule_matching_client(Client
*c
)
103 for(r
= globalconf
.rules
; r
; r
= r
->next
)
104 if(client_match_rule(c
, r
))
111 rules_get_fuzzy_from_str(const char *str
)
113 if(!a_strcmp(str
, "true") || !a_strcmp(str
, "yes"))
115 else if(!a_strcmp(str
, "false") || !a_strcmp(str
, "no"))
121 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80