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