optimize rule usage
This commit is contained in:
parent
346a383258
commit
d402ae8f69
|
@ -117,10 +117,11 @@ cleanup()
|
|||
for(r = globalconf.rules; r; r = rn)
|
||||
{
|
||||
rn = r->next;
|
||||
p_delete(&r->prop);
|
||||
p_delete(&r->tags);
|
||||
p_delete(&r->propregex);
|
||||
p_delete(&r->tagregex);
|
||||
p_delete(&r->prop_r);
|
||||
p_delete(&r->tags_r);
|
||||
p_delete(&r->xpropval_r);
|
||||
p_delete(&r->icon);
|
||||
p_delete(&r->xprop);
|
||||
p_delete(&r);
|
||||
}
|
||||
|
||||
|
|
10
config.c
10
config.c
|
@ -710,14 +710,14 @@ config_parse(const char *confpatharg)
|
|||
for(i = 0; i < cfg_size(cfg_rules, "rule"); i++)
|
||||
{
|
||||
cfgsectmp = cfg_getnsec(cfg_rules, "rule", i);
|
||||
rule->prop = a_strdup(cfg_getstr(cfgsectmp, "name"));
|
||||
rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
|
||||
rule->prop_r = rules_compile_regex(cfg_getstr(cfgsectmp, "name"));
|
||||
rule->tags_r = rules_compile_regex(cfg_getstr(cfgsectmp, "tags"));
|
||||
rule->xprop = a_strdup(cfg_getstr(cfgsectmp, "xproperty_name"));
|
||||
rule->xpropval_r = rules_compile_regex(cfg_getstr(cfgsectmp, "xproperty_value"));
|
||||
rule->icon = a_strdup(cfg_getstr(cfgsectmp, "icon"));
|
||||
rule->isfloating = cfg_getbool(cfgsectmp, "float");
|
||||
rule->screen = cfg_getint(cfgsectmp, "screen");
|
||||
rule->not_master = cfg_getbool(cfgsectmp, "not_master");
|
||||
rule->xprop = a_strdup(cfg_getstr(cfgsectmp, "xproperty_name"));
|
||||
rule->xprop_val = a_strdup(cfg_getstr(cfgsectmp, "xproperty_value"));
|
||||
if(rule->screen >= get_screen_count())
|
||||
rule->screen = 0;
|
||||
|
||||
|
@ -730,8 +730,6 @@ config_parse(const char *confpatharg)
|
|||
else
|
||||
globalconf.rules = NULL;
|
||||
|
||||
compileregs(globalconf.rules);
|
||||
|
||||
/* Mouse: root window click bindings */
|
||||
globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", True);
|
||||
|
||||
|
|
9
config.h
9
config.h
|
@ -40,17 +40,14 @@ enum
|
|||
typedef struct Rule Rule;
|
||||
struct Rule
|
||||
{
|
||||
char *prop;
|
||||
char *tags;
|
||||
char *icon;
|
||||
char *xprop;
|
||||
char *xprop_val;
|
||||
int screen;
|
||||
Bool isfloating;
|
||||
Bool not_master;
|
||||
regex_t *propregex;
|
||||
regex_t *tagregex;
|
||||
regex_t *xpropvalregex;
|
||||
regex_t *prop_r;
|
||||
regex_t *tags_r;
|
||||
regex_t *xpropval_r;
|
||||
Rule *next;
|
||||
};
|
||||
|
||||
|
|
59
rules.c
59
rules.c
|
@ -25,8 +25,8 @@
|
|||
|
||||
extern AwesomeConf globalconf;
|
||||
|
||||
static regex_t *
|
||||
compile_regex(char *val)
|
||||
regex_t *
|
||||
rules_compile_regex(char *val)
|
||||
{
|
||||
regex_t *reg;
|
||||
|
||||
|
@ -42,19 +42,6 @@ compile_regex(char *val)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
compileregs(Rule *rules)
|
||||
{
|
||||
Rule *r;
|
||||
|
||||
for(r = rules; r; r = r->next)
|
||||
{
|
||||
r->propregex = compile_regex(r->prop);
|
||||
r->tagregex = compile_regex(r->tags);
|
||||
r->xpropvalregex = compile_regex(r->xprop_val);
|
||||
}
|
||||
}
|
||||
|
||||
Bool
|
||||
client_match_rule(Client *c, Rule *r)
|
||||
{
|
||||
|
@ -62,35 +49,39 @@ client_match_rule(Client *c, Rule *r)
|
|||
regmatch_t tmp;
|
||||
ssize_t len;
|
||||
XClassHint ch = { 0, 0 };
|
||||
Bool ret;
|
||||
Bool ret = False;
|
||||
|
||||
/* first try to match on name */
|
||||
XGetClassHint(globalconf.display, c->win, &ch);
|
||||
if(r->prop_r)
|
||||
{
|
||||
/* first try to match on name */
|
||||
XGetClassHint(globalconf.display, c->win, &ch);
|
||||
|
||||
len = a_strlen(ch.res_class) + a_strlen(ch.res_name) + a_strlen(c->name);
|
||||
prop = p_new(char, len + 3);
|
||||
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);
|
||||
/* 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));
|
||||
ret = !regexec(r->prop_r, prop, 1, &tmp, 0);
|
||||
|
||||
p_delete(&prop);
|
||||
p_delete(&prop);
|
||||
|
||||
if(ch.res_class)
|
||||
XFree(ch.res_class);
|
||||
if(ch.res_name)
|
||||
XFree(ch.res_name);
|
||||
|
||||
if(ret)
|
||||
return True;
|
||||
if(ch.res_class)
|
||||
XFree(ch.res_class);
|
||||
if(ch.res_name)
|
||||
XFree(ch.res_name);
|
||||
|
||||
if(ret)
|
||||
return True;
|
||||
}
|
||||
|
||||
if(r->xprop
|
||||
&& r->xpropval_r
|
||||
&& xgettextprop(globalconf.display, c->win,
|
||||
XInternAtom(globalconf.display, r->xprop, False),
|
||||
buf, ssizeof(buf)))
|
||||
ret = (r->xpropvalregex && !regexec(r->xpropvalregex, buf, 1, &tmp, 0));
|
||||
ret = !regexec(r->xpropval_r, buf, 1, &tmp, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -100,7 +91,7 @@ is_tag_match_rules(Tag *t, Rule *r)
|
|||
{
|
||||
regmatch_t tmp;
|
||||
|
||||
if(r->tagregex && !regexec(r->tagregex, t->name, 1, &tmp, 0))
|
||||
if(r->tags_r && !regexec(r->tags_r, t->name, 1, &tmp, 0))
|
||||
return True;
|
||||
|
||||
return False;
|
||||
|
|
Loading…
Reference in New Issue