2007-11-13 21:40:33 +01:00
|
|
|
/*
|
|
|
|
* rules.c - rules management
|
|
|
|
*
|
2008-03-15 09:10:32 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-11-13 21:40:33 +01:00
|
|
|
*
|
|
|
|
* 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 "rules.h"
|
2008-03-04 20:39:21 +01:00
|
|
|
#include "common/xutil.h"
|
2007-11-13 21:40:33 +01:00
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
2008-01-02 12:44:18 +01:00
|
|
|
regex_t *
|
|
|
|
rules_compile_regex(char *val)
|
2008-01-02 12:23:01 +01:00
|
|
|
{
|
|
|
|
regex_t *reg;
|
|
|
|
|
|
|
|
if(val)
|
|
|
|
{
|
|
|
|
reg = p_new(regex_t, 1);
|
|
|
|
if(regcomp(reg, val, REG_EXTENDED))
|
|
|
|
p_delete(®);
|
|
|
|
else
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
bool
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_match_rule(tag_t *t, rule_t *r)
|
2007-11-13 21:40:33 +01:00
|
|
|
{
|
|
|
|
regmatch_t tmp;
|
|
|
|
|
2008-01-02 12:44:18 +01:00
|
|
|
if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0))
|
2008-03-21 16:50:17 +01:00
|
|
|
return true;
|
2007-11-13 21:40:33 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
return false;
|
2007-11-13 21:40:33 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 11:55:36 +02:00
|
|
|
rule_t *
|
2008-04-11 11:35:11 +02:00
|
|
|
rule_matching_client(client_t *c)
|
2008-01-12 22:59:13 +01:00
|
|
|
{
|
2008-04-10 11:55:36 +02:00
|
|
|
rule_t *r;
|
2008-04-09 20:32:39 +02:00
|
|
|
char *prop = NULL, buf[512];
|
|
|
|
regmatch_t tmp;
|
|
|
|
ssize_t len;
|
|
|
|
class_hint_t *ch = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if(!(ch = xutil_get_class_hint(globalconf.connection, c->win)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = a_strlen(ch->res_class) + a_strlen(ch->res_name) + a_strlen(c->name);
|
|
|
|
prop = p_new(char, len + 3);
|
|
|
|
|
|
|
|
snprintf(prop, len + 3, "%s:%s:%s",
|
|
|
|
ch->res_class ? ch->res_class : "", ch->res_name ? ch->res_name : "", c->name);
|
|
|
|
|
|
|
|
if(ch->res_class)
|
|
|
|
p_delete(&ch->res_class);
|
|
|
|
if(ch->res_name)
|
|
|
|
p_delete(&ch->res_name);
|
|
|
|
p_delete(&ch);
|
|
|
|
|
2008-01-12 22:59:13 +01:00
|
|
|
for(r = globalconf.rules; r; r = r->next)
|
2008-04-09 20:32:39 +02:00
|
|
|
{
|
|
|
|
if(r->prop_r && prop)
|
|
|
|
ret = !regexec(r->prop_r, prop, 1, &tmp, 0);
|
|
|
|
|
|
|
|
if(!ret
|
|
|
|
&& r->xprop
|
|
|
|
&& r->xpropval_r
|
|
|
|
&& xutil_gettextprop(globalconf.connection, c->win,
|
|
|
|
xutil_intern_atom(globalconf.connection, r->xprop),
|
|
|
|
buf, ssizeof(buf)))
|
|
|
|
ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
|
|
|
|
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
p_delete(&prop);
|
2008-01-12 22:59:13 +01:00
|
|
|
return r;
|
2008-04-09 20:32:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p_delete(&prop);
|
2008-01-12 22:59:13 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|