rules are now stored in a linked list
This commit is contained in:
parent
8a0063a93d
commit
9f21fb3c9e
10
awesome.c
10
awesome.c
|
@ -57,6 +57,7 @@ cleanup_screen(awesome_config *awesomeconf)
|
||||||
int i;
|
int i;
|
||||||
Button *b, *bn;
|
Button *b, *bn;
|
||||||
Key *k, *kn;
|
Key *k, *kn;
|
||||||
|
Rule *r, *rn;
|
||||||
|
|
||||||
XftFontClose(awesomeconf->display, awesomeconf->font);
|
XftFontClose(awesomeconf->display, awesomeconf->font);
|
||||||
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
|
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++)
|
for(i = 0; i < awesomeconf->nlayouts; i++)
|
||||||
p_delete(&awesomeconf->layouts[i].symbol);
|
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);
|
rn = r->next;
|
||||||
p_delete(&awesomeconf->rules[i].tags);
|
p_delete(&r->prop);
|
||||||
|
p_delete(&r->tags);
|
||||||
|
p_delete(&r);
|
||||||
}
|
}
|
||||||
p_delete(&awesomeconf->tags);
|
p_delete(&awesomeconf->tags);
|
||||||
p_delete(&awesomeconf->layouts);
|
p_delete(&awesomeconf->layouts);
|
||||||
p_delete(&awesomeconf->rules);
|
|
||||||
p_delete(&awesomeconf->configpath);
|
p_delete(&awesomeconf->configpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
config.c
31
config.c
|
@ -342,6 +342,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
|
||||||
char *confpath, buf[2];
|
char *confpath, buf[2];
|
||||||
ssize_t confpath_len;
|
ssize_t confpath_len;
|
||||||
Key *key = NULL;
|
Key *key = NULL;
|
||||||
|
Rule *rule = NULL;
|
||||||
|
|
||||||
if(confpatharg)
|
if(confpatharg)
|
||||||
confpath = a_strdup(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");
|
eprint("awesome: fatal: no default layout available\n");
|
||||||
|
|
||||||
/* Rules */
|
/* Rules */
|
||||||
awesomeconf->nrules = cfg_size(cfg_rules, "rule");
|
if(cfg_size(cfg_rules, "rule"))
|
||||||
awesomeconf->rules = p_new(Rule, awesomeconf->nrules);
|
|
||||||
for(i = 0; i < awesomeconf->nrules; i++)
|
|
||||||
{
|
{
|
||||||
cfgsectmp = cfg_getnsec(cfg_rules, "rule", i);
|
awesomeconf->rules = rule = p_new(Rule, 1);
|
||||||
awesomeconf->rules[i].prop = a_strdup(cfg_getstr(cfgsectmp, "name"));
|
for(j = 0; j < cfg_size(cfg_rules, "rule"); j++)
|
||||||
awesomeconf->rules[i].tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
|
{
|
||||||
if(!a_strlen(awesomeconf->rules[i].tags))
|
cfgsectmp = cfg_getnsec(cfg_rules, "rule", j);
|
||||||
awesomeconf->rules[i].tags = NULL;
|
rule->prop = a_strdup(cfg_getstr(cfgsectmp, "name"));
|
||||||
awesomeconf->rules[i].isfloating = cfg_getbool(cfgsectmp, "float");
|
rule->tags = a_strdup(cfg_getstr(cfgsectmp, "tags"));
|
||||||
awesomeconf->rules[i].screen = cfg_getint(cfgsectmp, "screen");
|
if(!a_strlen(rule->tags))
|
||||||
if(awesomeconf->rules[i].screen >= get_screen_count(awesomeconf->display))
|
rule->tags = NULL;
|
||||||
awesomeconf->rules[i].screen = 0;
|
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 */
|
/* Tags */
|
||||||
awesomeconf->ntags = cfg_size(cfg_tags, "tag");
|
awesomeconf->ntags = cfg_size(cfg_tags, "tag");
|
||||||
|
|
8
config.h
8
config.h
|
@ -36,7 +36,8 @@ enum
|
||||||
enum
|
enum
|
||||||
{ CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
{ CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
|
|
||||||
typedef struct
|
typedef struct Rule Rule;
|
||||||
|
struct Rule
|
||||||
{
|
{
|
||||||
char *prop;
|
char *prop;
|
||||||
char *tags;
|
char *tags;
|
||||||
|
@ -44,7 +45,8 @@ typedef struct
|
||||||
Bool isfloating;
|
Bool isfloating;
|
||||||
regex_t *propregex;
|
regex_t *propregex;
|
||||||
regex_t *tagregex;
|
regex_t *tagregex;
|
||||||
} Rule;
|
Rule *next;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct awesome_config awesome_config;
|
typedef struct awesome_config awesome_config;
|
||||||
|
|
||||||
|
@ -169,8 +171,6 @@ struct awesome_config
|
||||||
int nlayouts;
|
int nlayouts;
|
||||||
/** Rules list */
|
/** Rules list */
|
||||||
Rule *rules;
|
Rule *rules;
|
||||||
/** Number of rules in *rules */
|
|
||||||
int nrules;
|
|
||||||
/** Keys bindings list */
|
/** Keys bindings list */
|
||||||
Key *keys;
|
Key *keys;
|
||||||
/** Mouse bindings list */
|
/** Mouse bindings list */
|
||||||
|
|
38
tag.c
38
tag.c
|
@ -35,6 +35,7 @@ applyrules(Client *c, awesome_config *awesomeconf)
|
||||||
Bool matched = False;
|
Bool matched = False;
|
||||||
XClassHint ch = { 0, 0 };
|
XClassHint ch = { 0, 0 };
|
||||||
char *prop;
|
char *prop;
|
||||||
|
Rule *r;
|
||||||
|
|
||||||
XGetClassHint(c->display, c->win, &ch);
|
XGetClassHint(c->display, c->win, &ch);
|
||||||
|
|
||||||
|
@ -45,25 +46,22 @@ applyrules(Client *c, awesome_config *awesomeconf)
|
||||||
/* 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);
|
||||||
for(i = 0; i < awesomeconf->nrules; i++)
|
for(r = awesomeconf->rules; r; r = r->next)
|
||||||
if(awesomeconf->rules[i].propregex && !regexec(awesomeconf->rules[i].propregex, prop, 1, &tmp, 0))
|
if(r->propregex && !regexec(r->propregex, prop, 1, &tmp, 0))
|
||||||
{
|
{
|
||||||
c->isfloating = awesomeconf->rules[i].isfloating;
|
c->isfloating = r->isfloating;
|
||||||
for(j = 0; awesomeconf->rules[i].tagregex && j < awesomeconf->ntags; j++)
|
for(j = 0; r->tagregex && j < awesomeconf->ntags; j++)
|
||||||
if(!regexec(awesomeconf->rules[i].tagregex, awesomeconf->tags[j].name, 1, &tmp, 0))
|
if(!regexec(r->tagregex, awesomeconf->tags[j].name, 1, &tmp, 0))
|
||||||
{
|
{
|
||||||
matched = True;
|
matched = True;
|
||||||
c->tags[j] = True;
|
c->tags[j] = True;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c->tags[j] = False;
|
c->tags[j] = False;
|
||||||
if(awesomeconf->rules[i].screen != -1
|
if(r->screen != -1 && r->screen != awesomeconf->screen)
|
||||||
&& awesomeconf->rules[i].screen != awesomeconf->screen)
|
|
||||||
{
|
{
|
||||||
screen = awesomeconf->rules[i].screen;
|
screen = r->screen;
|
||||||
move_client_to_screen(c,
|
move_client_to_screen(c, &awesomeconf[r->screen - awesomeconf->screen], True);
|
||||||
&awesomeconf[awesomeconf->rules[i].screen - awesomeconf->screen],
|
|
||||||
True);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p_delete(&prop);
|
p_delete(&prop);
|
||||||
|
@ -79,28 +77,28 @@ applyrules(Client *c, awesome_config *awesomeconf)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
compileregs(Rule * rules, int nrules)
|
compileregs(Rule *rules)
|
||||||
{
|
{
|
||||||
int i;
|
Rule *r;
|
||||||
regex_t *reg;
|
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);
|
reg = p_new(regex_t, 1);
|
||||||
if(regcomp(reg, rules[i].prop, REG_EXTENDED))
|
if(regcomp(reg, r->prop, REG_EXTENDED))
|
||||||
p_delete(®);
|
p_delete(®);
|
||||||
else
|
else
|
||||||
rules[i].propregex = reg;
|
r->propregex = reg;
|
||||||
}
|
}
|
||||||
if(rules[i].tags)
|
if(r->tags)
|
||||||
{
|
{
|
||||||
reg = p_new(regex_t, 1);
|
reg = p_new(regex_t, 1);
|
||||||
if(regcomp(reg, rules[i].tags, REG_EXTENDED))
|
if(regcomp(reg, r->tags, REG_EXTENDED))
|
||||||
p_delete(®);
|
p_delete(®);
|
||||||
else
|
else
|
||||||
rules[i].tagregex = reg;
|
r->tagregex = reg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
tag.h
2
tag.h
|
@ -27,7 +27,7 @@
|
||||||
/** Check if a client is tiled */
|
/** Check if a client is tiled */
|
||||||
#define IS_TILED(client, screen, tags, ntags) (client && !client->isfloating && isvisible(client, screen, tags, ntags))
|
#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);
|
Bool isvisible(Client *, int, Tag *, int);
|
||||||
int applyrules(Client * c, awesome_config *);
|
int applyrules(Client * c, awesome_config *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue