rules are now stored in a linked list

This commit is contained in:
Julien Danjou 2007-11-12 19:25:10 +01:00
parent 8a0063a93d
commit 9f21fb3c9e
5 changed files with 47 additions and 42 deletions

View File

@ -57,6 +57,7 @@ cleanup_screen(awesome_config *awesomeconf)
int i;
Button *b, *bn;
Key *k, *kn;
Rule *r, *rn;
XftFontClose(awesomeconf->display, awesomeconf->font);
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
@ -97,14 +98,15 @@ cleanup_screen(awesome_config *awesomeconf)
}
for(i = 0; i < awesomeconf->nlayouts; i++)
p_delete(&awesomeconf->layouts[i].symbol);
for(i = 0; i < awesomeconf->nrules; i++)
for(r = awesomeconf->rules; r; r = rn)
{
p_delete(&awesomeconf->rules[i].prop);
p_delete(&awesomeconf->rules[i].tags);
rn = r->next;
p_delete(&r->prop);
p_delete(&r->tags);
p_delete(&r);
}
p_delete(&awesomeconf->tags);
p_delete(&awesomeconf->layouts);
p_delete(&awesomeconf->rules);
p_delete(&awesomeconf->configpath);
}

View File

@ -342,6 +342,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
char *confpath, buf[2];
ssize_t confpath_len;
Key *key = NULL;
Rule *rule = NULL;
if(confpatharg)
confpath = a_strdup(confpatharg);
@ -443,22 +444,26 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
eprint("awesome: fatal: no default layout available\n");
/* Rules */
awesomeconf->nrules = cfg_size(cfg_rules, "rule");
awesomeconf->rules = p_new(Rule, awesomeconf->nrules);
for(i = 0; i < awesomeconf->nrules; i++)
if(cfg_size(cfg_rules, "rule"))
{
cfgsectmp = cfg_getnsec(cfg_rules, "rule", i);
awesomeconf->rules[i].prop = a_strdup(cfg_getstr(cfgsectmp, "name"));
awesomeconf->rules[i].tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
if(!a_strlen(awesomeconf->rules[i].tags))
awesomeconf->rules[i].tags = NULL;
awesomeconf->rules[i].isfloating = cfg_getbool(cfgsectmp, "float");
awesomeconf->rules[i].screen = cfg_getint(cfgsectmp, "screen");
if(awesomeconf->rules[i].screen >= get_screen_count(awesomeconf->display))
awesomeconf->rules[i].screen = 0;
awesomeconf->rules = rule = p_new(Rule, 1);
for(j = 0; j < cfg_size(cfg_rules, "rule"); j++)
{
cfgsectmp = cfg_getnsec(cfg_rules, "rule", j);
rule->prop = a_strdup(cfg_getstr(cfgsectmp, "name"));
rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
if(!a_strlen(rule->tags))
rule->tags = NULL;
rule->isfloating = cfg_getbool(cfgsectmp, "float");
rule->screen = cfg_getint(cfgsectmp, "screen");
if(rule->screen >= get_screen_count(awesomeconf->display))
rule->screen = 0;
}
}
else
awesomeconf->rules = NULL;
compileregs(awesomeconf->rules, awesomeconf->nrules);
compileregs(awesomeconf->rules);
/* Tags */
awesomeconf->ntags = cfg_size(cfg_tags, "tag");

View File

@ -36,7 +36,8 @@ enum
enum
{ CurNormal, CurResize, CurMove, CurLast }; /* cursor */
typedef struct
typedef struct Rule Rule;
struct Rule
{
char *prop;
char *tags;
@ -44,7 +45,8 @@ typedef struct
Bool isfloating;
regex_t *propregex;
regex_t *tagregex;
} Rule;
Rule *next;
};
typedef struct awesome_config awesome_config;
@ -169,8 +171,6 @@ struct awesome_config
int nlayouts;
/** Rules list */
Rule *rules;
/** Number of rules in *rules */
int nrules;
/** Keys bindings list */
Key *keys;
/** Mouse bindings list */

38
tag.c
View File

@ -35,6 +35,7 @@ applyrules(Client *c, awesome_config *awesomeconf)
Bool matched = False;
XClassHint ch = { 0, 0 };
char *prop;
Rule *r;
XGetClassHint(c->display, c->win, &ch);
@ -45,25 +46,22 @@ applyrules(Client *c, awesome_config *awesomeconf)
/* rule matching */
snprintf(prop, len + 3, "%s:%s:%s",
ch.res_class ? ch.res_class : "", ch.res_name ? ch.res_name : "", c->name);
for(i = 0; i < awesomeconf->nrules; i++)
if(awesomeconf->rules[i].propregex && !regexec(awesomeconf->rules[i].propregex, prop, 1, &tmp, 0))
for(r = awesomeconf->rules; r; r = r->next)
if(r->propregex && !regexec(r->propregex, prop, 1, &tmp, 0))
{
c->isfloating = awesomeconf->rules[i].isfloating;
for(j = 0; awesomeconf->rules[i].tagregex && j < awesomeconf->ntags; j++)
if(!regexec(awesomeconf->rules[i].tagregex, awesomeconf->tags[j].name, 1, &tmp, 0))
c->isfloating = r->isfloating;
for(j = 0; r->tagregex && j < awesomeconf->ntags; j++)
if(!regexec(r->tagregex, awesomeconf->tags[j].name, 1, &tmp, 0))
{
matched = True;
c->tags[j] = True;
}
else
c->tags[j] = False;
if(awesomeconf->rules[i].screen != -1
&& awesomeconf->rules[i].screen != awesomeconf->screen)
if(r->screen != -1 && r->screen != awesomeconf->screen)
{
screen = awesomeconf->rules[i].screen;
move_client_to_screen(c,
&awesomeconf[awesomeconf->rules[i].screen - awesomeconf->screen],
True);
screen = r->screen;
move_client_to_screen(c, &awesomeconf[r->screen - awesomeconf->screen], True);
}
}
p_delete(&prop);
@ -79,28 +77,28 @@ applyrules(Client *c, awesome_config *awesomeconf)
}
void
compileregs(Rule * rules, int nrules)
compileregs(Rule *rules)
{
int i;
Rule *r;
regex_t *reg;
for(i = 0; i < nrules; i++)
for(r = rules; r; r = r->next)
{
if(rules[i].prop)
if(r->prop)
{
reg = p_new(regex_t, 1);
if(regcomp(reg, rules[i].prop, REG_EXTENDED))
if(regcomp(reg, r->prop, REG_EXTENDED))
p_delete(&reg);
else
rules[i].propregex = reg;
r->propregex = reg;
}
if(rules[i].tags)
if(r->tags)
{
reg = p_new(regex_t, 1);
if(regcomp(reg, rules[i].tags, REG_EXTENDED))
if(regcomp(reg, r->tags, REG_EXTENDED))
p_delete(&reg);
else
rules[i].tagregex = reg;
r->tagregex = reg;
}
}
}

2
tag.h
View File

@ -27,7 +27,7 @@
/** Check if a client is tiled */
#define IS_TILED(client, screen, tags, ntags) (client && !client->isfloating && isvisible(client, screen, tags, ntags))
void compileregs(Rule *, int);
void compileregs(Rule *);
Bool isvisible(Client *, int, Tag *, int);
int applyrules(Client * c, awesome_config *);