From 3540bb1cadfb9ba71cf280d1e35e4423ec5c5fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Anger?= Date: Thu, 12 Apr 2012 14:52:47 +0200 Subject: [PATCH] clean code --- src/client.c | 95 +++++++++++++++++++++------------------------------- src/config.c | 8 +---- src/wmfs.h | 1 - 3 files changed, 39 insertions(+), 65 deletions(-) diff --git a/src/client.c b/src/client.c index 9e0d14c..19f533d 100644 --- a/src/client.c +++ b/src/client.c @@ -846,6 +846,36 @@ client_frame_new(struct client *c) XReparentWindow(W->dpy, c->win, c->frame, c->border, c->tbarw); } +static void +_apply_rule(struct client *c, struct rule *r) +{ + if(r->screen != -1) + c->screen = screen_gb_id(r->screen); + + c->tag = c->screen->seltag; + if(r->tag != -1) + c->tag = tag_gb_id(c->screen, r->tag); + + c->theme = r->theme; + + /* free = false for originally free client */ + if(r->flags & RULE_FREE) + c->flags |= CLIENT_FREE; + else + c->flags &= ~CLIENT_FREE; + + /* Free rule is not compatible with tab rule */ + if(r->flags & RULE_TAB) + W->flags ^= WMFS_TABNOC; /* < can be disable by client_tab_next_opened */ + + /* TODO + if(r->flags & RULE_IGNORE_TAG) + {} + */ + + c->flags |= CLIENT_RULED; +} + #define RINSTANCE 0x01 #define RCLASS 0x02 #define RROLE 0x04 @@ -854,6 +884,7 @@ static void client_apply_rule(struct client *c) { struct rule *r; + struct rule *defaultr = NULL; char *wmname = NULL; char *role = NULL; int f; @@ -882,9 +913,11 @@ client_apply_rule(struct client *c) XFree(data); } - // Apply a specific rule + /* Apply a specific rule */ SLIST_FOREACH(r, &W->h.rule, next) { + if (r->instance && !strcmp(r->instance, "*")) + defaultr = r; if(s) { FLAGAPPLY(flags, (xch.res_name && r->instance && !strcmp(xch.res_name, r->instance)), RINSTANCE); @@ -895,33 +928,7 @@ client_apply_rule(struct client *c) FLAGAPPLY(flags, ((role && r->role && !strcmp(role, r->role)) || !role || !r->role), RROLE); if(flags & (RINSTANCE | RCLASS | RNAME) && flags & RROLE) - { - if(r->screen != -1) - c->screen = screen_gb_id(r->screen); - - c->tag = c->screen->seltag; - if(r->tag != -1) - c->tag = tag_gb_id(c->screen, r->tag); - - c->theme = r->theme; - - /* free = false for originally free client */ - if(r->flags & RULE_FREE) - c->flags |= CLIENT_FREE; - else - c->flags &= ~CLIENT_FREE; - - /* Free rule is not compatible with tab rule */ - if(r->flags & RULE_TAB) - W->flags ^= WMFS_TABNOC; /* < can be disable by client_tab_next_opened */ - - /* TODO - if(r->flags & RULE_IGNORE_TAG) - {} - */ - - c->flags |= CLIENT_RULED; - } + _apply_rule(c, r); flags = 0; } @@ -931,35 +938,9 @@ client_apply_rule(struct client *c) if(wmname) free(wmname); - // Apply default rule - if (!(c->flags & CLIENT_RULED) && (r = W->crule) != NULL) - { - if(r->screen != -1) - c->screen = screen_gb_id(r->screen); - - c->tag = c->screen->seltag; - if(r->tag != -1) - c->tag = tag_gb_id(c->screen, r->tag); - - c->theme = r->theme; - - /* free = false for originally free client */ - if(r->flags & RULE_FREE) - c->flags |= CLIENT_FREE; - else - c->flags &= ~CLIENT_FREE; - - /* Free rule is not compatible with tab rule */ - if(r->flags & RULE_TAB) - W->flags ^= WMFS_TABNOC; /* < can be disable by client_tab_next_opened */ - - /* TODO - if(r->flags & RULE_IGNORE_TAG) - {} - */ - - c->flags |= CLIENT_RULED; - } + /* Apply default rule */ + if (!(c->flags & CLIENT_RULED) && defaultr != NULL) + _apply_rule(c, defaultr); } struct client* diff --git a/src/config.c b/src/config.c index 8247266..2f1a488 100644 --- a/src/config.c +++ b/src/config.c @@ -261,7 +261,6 @@ config_rule(void) n = fetch_section_count(ks); SLIST_INIT(&W->h.rule); - W->crule = NULL; /* [rule] */ for(i = 0; i < n; ++i) @@ -285,12 +284,7 @@ config_rule(void) else r->theme = W->ctheme; - if (r->name && !strcmp(r->name, "default")) - { - W->crule = r; - } - else - SLIST_INSERT_HEAD(&W->h.rule, r, next); + SLIST_INSERT_HEAD(&W->h.rule, r, next); } free(ks); diff --git a/src/wmfs.h b/src/wmfs.h index 1be645e..34511fb 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -349,7 +349,6 @@ struct wmfs char *confpath; struct barwin *last_clicked_barwin; struct theme *ctheme; - struct rule *crule; /* Log file */ FILE *log;