From 654fba9b5e8b91892fba0d86d4dc9906bf21e8f2 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 12 Jan 2008 22:59:13 +0100 Subject: [PATCH] insert and use rule_matching_client() --- client.c | 19 +++++---------- rules.c | 13 ++++++++++- rules.h | 2 +- tag.c | 56 ++++++++++++++++++++++----------------------- widgets/netwmicon.c | 34 +++++++++++++-------------- widgets/tasklist.c | 21 ++++++++--------- 6 files changed, 72 insertions(+), 73 deletions(-) diff --git a/client.c b/client.c index 739ee1d15..3735fadfd 100644 --- a/client.c +++ b/client.c @@ -327,19 +327,12 @@ client_manage(Window w, XWindowAttributes *wa, int screen) client_saveprops(c); /* attach to the stack */ - for(rule = globalconf.rules; rule; rule = rule->next) - if(rule->not_master && client_match_rule(c, rule)) - { - client_list_append(&globalconf.clients, c); - break; - } - if(!rule) - { - if(globalconf.screens[c->screen].new_become_master) - client_list_push(&globalconf.clients, c); - else - client_list_append(&globalconf.clients, c); - } + if((rule = rule_matching_client(c)) && rule->not_master) + client_list_append(&globalconf.clients, c); + else if(globalconf.screens[c->screen].new_become_master) + client_list_push(&globalconf.clients, c); + else + client_list_append(&globalconf.clients, c); ewmh_update_net_client_list(phys_screen); diff --git a/rules.c b/rules.c index 27ada4d55..adb19de89 100644 --- a/rules.c +++ b/rules.c @@ -42,7 +42,7 @@ rules_compile_regex(char *val) return NULL; } -Bool +static Bool client_match_rule(Client *c, Rule *r) { char *prop, buf[512]; @@ -97,6 +97,17 @@ tag_match_rule(Tag *t, Rule *r) return False; } +Rule * +rule_matching_client(Client *c) +{ + Rule *r; + for(r = globalconf.rules; r; r = r->next) + if(client_match_rule(c, r)) + return r; + + return NULL; +} + RuleFloat rules_get_float_from_str(const char *str) { diff --git a/rules.h b/rules.h index 31f99111a..e00be51f8 100644 --- a/rules.h +++ b/rules.h @@ -27,9 +27,9 @@ #define RULE_NOSCREEN -1 regex_t * rules_compile_regex(char *); -Bool client_match_rule(Client *, Rule *); Bool tag_match_rule(Tag *, Rule *); RuleFloat rules_get_float_from_str(const char *); +Rule * rule_matching_client(Client *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/tag.c b/tag.c index 50481780a..93dedc5b3 100644 --- a/tag.c +++ b/tag.c @@ -100,38 +100,36 @@ tag_client_with_rules(Client *c) Tag *tag; Bool matched = False; - for(r = globalconf.rules; r; r = r->next) - if(client_match_rule(c, r)) + if((r = rule_matching_client(c))) + { + switch(r->isfloating) { - switch(r->isfloating) - { - case Tile: - c->isfloating = False; - break; - case Float: - c->isfloating = True; - client_resize(c, c->f_geometry, False); - break; - default: - break; - } - - if(r->screen != RULE_NOSCREEN && r->screen != c->screen) - move_client_to_screen(c, r->screen, True); - - for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) - if(tag_match_rule(tag, r)) - { - matched = True; - tag_client(c, tag); - } - else - untag_client(c, tag); - - if(!matched) - tag_client_with_current_selected(c); + case Tile: + c->isfloating = False; + break; + case Float: + c->isfloating = True; + client_resize(c, c->f_geometry, False); + break; + default: break; } + + if(r->screen != RULE_NOSCREEN && r->screen != c->screen) + move_client_to_screen(c, r->screen, True); + + for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) + if(tag_match_rule(tag, r)) + { + matched = True; + tag_client(c, tag); + } + else + untag_client(c, tag); + + if(!matched) + tag_client_with_current_selected(c); + } } diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index cbbe7b4e0..9f3bce1fc 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -47,26 +47,24 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, widget->area.height = widget->statusbar->height; - for(r = globalconf.rules; r; r = r->next) - if(r->icon && client_match_rule(sel, r)) - { - area = draw_get_image_size(r->icon); - widget->area.width = ((double) widget->statusbar->height / (double) area.height) - * area.width; - if(!widget->user_supplied_x) - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->area.width, - offset, - widget->alignment); + if((r = rule_matching_client(sel)) && r->icon) + { + area = draw_get_image_size(r->icon); + widget->area.width = ((double) widget->statusbar->height / (double) area.height) + * area.width; + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + widget->area.width, + offset, + widget->alignment); - if(!widget->user_supplied_y) - widget->area.y = 0; - draw_image(ctx, widget->area.x, widget->area.y, - widget->statusbar->height, r->icon); - - return widget->area.width; - } + if(!widget->user_supplied_y) + widget->area.y = 0; + draw_image(ctx, widget->area.x, widget->area.y, + widget->statusbar->height, r->icon); + return widget->area.width; + } if(!(icon = ewmh_get_window_icon(sel->win))) { diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 420ad1291..3fc349223 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -86,17 +86,16 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) if(d->show_icons) { - for(r = globalconf.rules; r; r = r->next) - if(r->icon && client_match_rule(c, r)) - { - area = draw_get_image_size(r->icon); - icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width; - draw_image(ctx, - widget->area.x + box_width * i, - widget->area.y, - widget->statusbar->height, - r->icon); - } + if((r = rule_matching_client(c)) && r->icon) + { + area = draw_get_image_size(r->icon); + icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width; + draw_image(ctx, + widget->area.x + box_width * i, + widget->area.y, + widget->statusbar->height, + r->icon); + } if(!icon_width && (icon = ewmh_get_window_icon(c->win))) {