rename uicb_set* to uicb_tag_set* since they apply on tags
[awesome.git] / rules.c
blob07fdb41e45b0f160d9eb2f1d896754f444616094
1 /*
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.
22 #include "util.h"
23 #include "rules.h"
25 void
26 compileregs(Rule *rules)
28 Rule *r;
29 regex_t *reg;
30 for(r = rules; r; r = r->next)
32 if(r->prop)
34 reg = p_new(regex_t, 1);
35 if(regcomp(reg, r->prop, REG_EXTENDED))
36 p_delete(&reg);
37 else
38 r->propregex = reg;
40 if(r->tags)
42 reg = p_new(regex_t, 1);
43 if(regcomp(reg, r->tags, REG_EXTENDED))
44 p_delete(&reg);
45 else
46 r->tagregex = reg;
51 Bool
52 client_match_rule(Client *c, Rule *r)
54 char *prop;
55 regmatch_t tmp;
56 ssize_t len;
57 XClassHint ch = { 0, 0 };
58 Bool ret;
60 XGetClassHint(c->display, c->win, &ch);
62 len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
63 prop = p_new(char, len + 3);
65 /* rule matching */
66 snprintf(prop, len + 3, "%s:%s:%s",
67 ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
69 ret = (r->propregex && !regexec(r->propregex, prop, 1, &tmp, 0));
71 p_delete(&prop);
73 if(ch.res_class)
74 XFree(ch.res_class);
75 if(ch.res_name)
76 XFree(ch.res_name);
78 return ret;
81 Bool
82 is_tag_match_rules(Tag *t, Rule *r)
84 regmatch_t tmp;
86 if(r->tagregex && !regexec(r->tagregex, t->name, 1, &tmp, 0))
87 return True;
89 return False;
92 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99