add various autostuff to ignore
[awesome.git] / rules.c
blob8e2800d8e1aa4ddc9df5f4bd61c464417dc337e8
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"
24 #include "xutil.h"
26 extern AwesomeConf globalconf;
28 regex_t *
29 rules_compile_regex(char *val)
31 regex_t *reg;
33 if(val)
35 reg = p_new(regex_t, 1);
36 if(regcomp(reg, val, REG_EXTENDED))
37 p_delete(&reg);
38 else
39 return reg;
42 return NULL;
45 Bool
46 client_match_rule(Client *c, Rule *r)
48 char *prop, buf[512];
49 regmatch_t tmp;
50 ssize_t len;
51 XClassHint ch = { 0, 0 };
52 Bool ret = False;
54 if(r->prop_r)
56 /* first try to match on name */
57 XGetClassHint(globalconf.display, c->win, &ch);
59 len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
60 prop = p_new(char, len + 3);
62 /* rule matching */
63 snprintf(prop, len + 3, "%s:%s:%s",
64 ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
66 ret = !regexec(r->prop_r, prop, 1, &tmp, 0);
68 p_delete(&prop);
70 if(ch.res_class)
71 XFree(ch.res_class);
72 if(ch.res_name)
73 XFree(ch.res_name);
75 if(ret)
76 return True;
79 if(r->xprop
80 && r->xpropval_r
81 && xgettextprop(globalconf.display, c->win,
82 XInternAtom(globalconf.display, r->xprop, False),
83 buf, ssizeof(buf)))
84 ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
86 return ret;
89 Bool
90 is_tag_match_rules(Tag *t, Rule *r)
92 regmatch_t tmp;
94 if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0))
95 return True;
97 return False;
100 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80