2007-11-13 21:40:33 +01:00
|
|
|
/*
|
|
|
|
* rules.c - rules management
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "rules.h"
|
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
2007-11-13 22:45:46 +01:00
|
|
|
void
|
|
|
|
compileregs(Rule *rules)
|
|
|
|
{
|
|
|
|
Rule *r;
|
|
|
|
regex_t *reg;
|
|
|
|
for(r = rules; r; r = r->next)
|
|
|
|
{
|
|
|
|
if(r->prop)
|
|
|
|
{
|
|
|
|
reg = p_new(regex_t, 1);
|
|
|
|
if(regcomp(reg, r->prop, REG_EXTENDED))
|
|
|
|
p_delete(®);
|
|
|
|
else
|
|
|
|
r->propregex = reg;
|
|
|
|
}
|
|
|
|
if(r->tags)
|
|
|
|
{
|
|
|
|
reg = p_new(regex_t, 1);
|
|
|
|
if(regcomp(reg, r->tags, REG_EXTENDED))
|
|
|
|
p_delete(®);
|
|
|
|
else
|
|
|
|
r->tagregex = reg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-13 21:40:33 +01:00
|
|
|
Bool
|
|
|
|
client_match_rule(Client *c, Rule *r)
|
|
|
|
{
|
|
|
|
char *prop;
|
|
|
|
regmatch_t tmp;
|
|
|
|
ssize_t len;
|
|
|
|
XClassHint ch = { 0, 0 };
|
|
|
|
Bool ret;
|
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
XGetClassHint(globalconf.display, c->win, &ch);
|
2007-11-13 21:40:33 +01:00
|
|
|
|
|
|
|
len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
|
|
|
|
prop = p_new(char, len + 3);
|
|
|
|
|
|
|
|
/* rule matching */
|
|
|
|
snprintf(prop, len + 3, "%s:%s:%s",
|
|
|
|
ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
|
|
|
|
|
|
|
|
ret = (r->propregex && !regexec(r->propregex, prop, 1, &tmp, 0));
|
|
|
|
|
|
|
|
p_delete(&prop);
|
|
|
|
|
|
|
|
if(ch.res_class)
|
|
|
|
XFree(ch.res_class);
|
|
|
|
if(ch.res_name)
|
|
|
|
XFree(ch.res_name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2007-11-13 22:41:23 +01:00
|
|
|
is_tag_match_rules(Tag *t, Rule *r)
|
2007-11-13 21:40:33 +01:00
|
|
|
{
|
|
|
|
regmatch_t tmp;
|
|
|
|
|
2007-11-13 22:41:23 +01:00
|
|
|
if(r->tagregex && !regexec(r->tagregex, t->name, 1, &tmp, 0))
|
2007-11-13 21:40:33 +01:00
|
|
|
return True;
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|