diff --git a/src/config.c b/src/config.c index 34807f7..eabdafe 100644 --- a/src/config.c +++ b/src/config.c @@ -143,6 +143,50 @@ config_tag(void) free(ks); } +static void +config_rule(void) +{ + int i, n; + struct conf_sec *sec, **ks; + struct rule *r; + struct theme *t; + + /* [rules] */ + sec = fetch_section_first(NULL, "rules"); + ks = fetch_section(sec, "rule"); + n = fetch_section_count(ks); + + SLIST_INIT(&W->h.rule); + + /* [rule] */ + for(i = 0; i < n; ++i) + { + r = (struct rule*)xcalloc(1, sizeof(struct rule)); + + r->class = xstrdup(fetch_opt_first(ks[i], "", "class").str); + r->instance = xstrdup(fetch_opt_first(ks[i], "", "instance").str); + r->role = xstrdup(fetch_opt_first(ks[i], "", "role").str); + r->name = xstrdup(fetch_opt_first(ks[i], "", "name").str); + r->screen = fetch_opt_first(ks[i], "-1", "screen").num; + r->tag = fetch_opt_first(ks[i], "-1", "tag").num; + + FLAGAPPLY(r->flags, fetch_opt_first(ks[i], "false", "free").boolean, RULE_FREE); + FLAGAPPLY(r->flags, fetch_opt_first(ks[i], "false", "max").boolean, RULE_MAX); + FLAGAPPLY(r->flags, fetch_opt_first(ks[i], "false", "ignore_tag").boolean, RULE_IGNORE_TAG); + + SLIST_FOREACH(t, &W->h.theme, next) + if(!strcmp(fetch_opt_first(ks[i], "", "theme").str, t->name)) + { + r->theme = t; + break; + } + + SLIST_INSERT_HEAD(&W->h.rule, r, next); + } + + free(ks); +} + static void config_keybind(void) { @@ -210,6 +254,7 @@ config_init(void) config_keybind(); config_tag(); config_bars(); + config_rule(); free(path); free_conf(); diff --git a/src/util.h b/src/util.h index 2b47e41..c6f2654 100644 --- a/src/util.h +++ b/src/util.h @@ -25,12 +25,13 @@ X##t##Window(W->dpy, w); \ } while( /* CONSTCOND */ 0); -#define ATOM(a) XInternAtom(W->dpy, (a), False) -#define LEN(x) (sizeof(x) / sizeof(*x)) -#define FLAGINT(i) (1 << i) -#define ATOI(s) strtol(s, NULL, 10) -#define ABS(j) (j < 0 ? -j : j) -#define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h) +#define ATOM(a) XInternAtom(W->dpy, (a), False) +#define LEN(x) (sizeof(x) / sizeof(*x)) +#define FLAGINT(i) (1 << i) +#define FLAGAPPLY(f, b, m) (f |= (b ? m : 0)) +#define ATOI(s) strtol(s, NULL, 10) +#define ABS(j) (j < 0 ? -j : j) +#define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h) /* * "#RRGGBB" -> 0xRRGGBB diff --git a/src/wmfs.c b/src/wmfs.c index 0f783a7..1549025 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -182,7 +182,6 @@ static void wmfs_scan(void) { struct geo g; - struct tag *t; struct client *c; int i, n, rf; int tag = -1, screen = -1, flags = -1; @@ -328,6 +327,7 @@ void wmfs_quit(void) { struct keybind *k; + struct rule *r; struct theme *t; struct client *c; @@ -359,6 +359,17 @@ wmfs_quit(void) free(t); } + while(!SLIST_EMPTY(&W->h.rule)) + { + r = SLIST_FIRST(&W->h.rule); + SLIST_REMOVE_HEAD(&W->h.rule, next); + free(r->class); + free(r->instance); + free(r->role); + free(r->name); + free(r); + } + while(!SLIST_EMPTY(&W->h.keybind)) { k = SLIST_FIRST(&W->h.keybind); diff --git a/src/wmfs.h b/src/wmfs.h index 1d17135..92bee4c 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -215,6 +215,21 @@ struct theme SLIST_ENTRY(theme) next; }; +#define RULE_FREE 0x01 +#define RULE_MAX 0x02 +#define RULE_IGNORE_TAG 0x04 +struct rule +{ + struct theme *theme; + char *class; + char *instance; + char *role; + char *name; + int tag, screen; + Flags flags; + SLIST_ENTRY(rule) next; +}; + struct wmfs { /* X11 stuffs */ @@ -242,6 +257,7 @@ struct wmfs SLIST_HEAD(, keybind) keybind; SLIST_HEAD(, barwin) barwin; SLIST_HEAD(, theme) theme; + SLIST_HEAD(, rule) rule; } h; /*