From 80eadd6f5c91aacbf36a1223661334ac39a94c47 Mon Sep 17 00:00:00 2001 From: Jeu2 Date: Thu, 12 Apr 2012 12:04:57 +0200 Subject: [PATCH 1/5] add ability to set a default rule modified: src/client.c modified: src/config.c modified: src/wmfs.h --- src/client.c | 35 ++++++++++++++++++++++++++++++++++- src/config.c | 8 +++++++- src/wmfs.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/client.c b/src/client.c index bea7ea8..136bcca 100644 --- a/src/client.c +++ b/src/client.c @@ -882,6 +882,7 @@ client_apply_rule(struct client *c) XFree(data); } + // Apply a specific rule SLIST_FOREACH(r, &W->h.rule, next) { if(s) @@ -902,7 +903,8 @@ client_apply_rule(struct client *c) if(r->tag != -1) c->tag = tag_gb_id(c->screen, r->tag); - c->theme = r->theme; + if (r->theme) + c->theme = r->theme; /* free = false for originally free client */ if(r->flags & RULE_FREE) @@ -929,6 +931,37 @@ 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); + + if (r->theme) + 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; + } } struct client* diff --git a/src/config.c b/src/config.c index 506b92f..8802f74 100644 --- a/src/config.c +++ b/src/config.c @@ -261,6 +261,7 @@ config_rule(void) n = fetch_section_count(ks); SLIST_INIT(&W->h.rule); + W->crule = NULL; /* [rule] */ for(i = 0; i < n; ++i) @@ -284,7 +285,12 @@ config_rule(void) else r->theme = W->ctheme; - SLIST_INSERT_HEAD(&W->h.rule, r, next); + if (!strcmp(r->name, "default")) + { + W->crule = r; + } + else + SLIST_INSERT_HEAD(&W->h.rule, r, next); } free(ks); diff --git a/src/wmfs.h b/src/wmfs.h index 34511fb..1be645e 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -349,6 +349,7 @@ struct wmfs char *confpath; struct barwin *last_clicked_barwin; struct theme *ctheme; + struct rule *crule; /* Log file */ FILE *log; From 4a186874aa27dd970ae26ae0f662d448565c66e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Anger?= Date: Thu, 12 Apr 2012 13:39:37 +0200 Subject: [PATCH 2/5] fix crash --- src/client.c | 6 ++---- src/config.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client.c b/src/client.c index 136bcca..9e0d14c 100644 --- a/src/client.c +++ b/src/client.c @@ -903,8 +903,7 @@ client_apply_rule(struct client *c) if(r->tag != -1) c->tag = tag_gb_id(c->screen, r->tag); - if (r->theme) - c->theme = r->theme; + c->theme = r->theme; /* free = false for originally free client */ if(r->flags & RULE_FREE) @@ -942,8 +941,7 @@ client_apply_rule(struct client *c) if(r->tag != -1) c->tag = tag_gb_id(c->screen, r->tag); - if (r->theme) - c->theme = r->theme; + c->theme = r->theme; /* free = false for originally free client */ if(r->flags & RULE_FREE) diff --git a/src/config.c b/src/config.c index 8802f74..8247266 100644 --- a/src/config.c +++ b/src/config.c @@ -285,7 +285,7 @@ config_rule(void) else r->theme = W->ctheme; - if (!strcmp(r->name, "default")) + if (r->name && !strcmp(r->name, "default")) { W->crule = r; } 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 3/5] 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; From 653d8d9b7be7e014866b36f02bd841caec13e37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Anger?= Date: Thu, 12 Apr 2012 15:04:24 +0200 Subject: [PATCH 4/5] fix indentation --- src/client.c | 46 +++++++++++++++++++++++----------------------- src/config.c | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/client.c b/src/client.c index 19f533d..c2b33f2 100644 --- a/src/client.c +++ b/src/client.c @@ -849,31 +849,31 @@ client_frame_new(struct client *c) static void _apply_rule(struct client *c, struct rule *r) { - if(r->screen != -1) - c->screen = screen_gb_id(r->screen); + 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->tag = c->screen->seltag; + if(r->tag != -1) + c->tag = tag_gb_id(c->screen, r->tag); - c->theme = r->theme; + 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 = 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 */ + /* 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) - {} - */ + /* TODO + if(r->flags & RULE_IGNORE_TAG) + {} + */ - c->flags |= CLIENT_RULED; + c->flags |= CLIENT_RULED; } #define RINSTANCE 0x01 @@ -916,8 +916,8 @@ client_apply_rule(struct client *c) /* Apply a specific rule */ SLIST_FOREACH(r, &W->h.rule, next) { - if (r->instance && !strcmp(r->instance, "*")) - defaultr = r; + if (r->instance && !strcmp(r->instance, "*")) + defaultr = r; if(s) { FLAGAPPLY(flags, (xch.res_name && r->instance && !strcmp(xch.res_name, r->instance)), RINSTANCE); @@ -928,7 +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) - _apply_rule(c, r); + _apply_rule(c, r); flags = 0; } @@ -940,7 +940,7 @@ client_apply_rule(struct client *c) /* Apply default rule */ if (!(c->flags & CLIENT_RULED) && defaultr != NULL) - _apply_rule(c, defaultr); + _apply_rule(c, defaultr); } struct client* diff --git a/src/config.c b/src/config.c index 2f1a488..506b92f 100644 --- a/src/config.c +++ b/src/config.c @@ -284,7 +284,7 @@ config_rule(void) else r->theme = W->ctheme; - SLIST_INSERT_HEAD(&W->h.rule, r, next); + SLIST_INSERT_HEAD(&W->h.rule, r, next); } free(ks); From ea517457e4560f94c1e6478dcb8f2a693c1e30d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Anger?= Date: Thu, 12 Apr 2012 15:09:31 +0200 Subject: [PATCH 5/5] fix last indentation issue --- src/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.c b/src/client.c index c2b33f2..4086f1c 100644 --- a/src/client.c +++ b/src/client.c @@ -884,7 +884,7 @@ static void client_apply_rule(struct client *c) { struct rule *r; - struct rule *defaultr = NULL; + struct rule *defaultr = NULL; char *wmname = NULL; char *role = NULL; int f;