From e885449144ec99e1ae1b20d1ca84c437fe6ea87c Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 10 Jun 2011 19:25:18 +0200 Subject: [PATCH] Cfactor/Split/Tag: Use macro instead of function for test functions and use bitfield instead of bool array in tag functions --- src/cfactor.c | 45 +++------------------------------------------ src/split.c | 30 ++++++++++++------------------ src/tag.c | 28 ++++++++++------------------ src/wmfs.h | 9 +++++++-- 4 files changed, 32 insertions(+), 80 deletions(-) diff --git a/src/cfactor.c b/src/cfactor.c index f8a3e49..80b721d 100644 --- a/src/cfactor.c +++ b/src/cfactor.c @@ -99,30 +99,6 @@ cfactor_geo(Geo geo, int fact[4], int *err) return cgeo; } -/** Return test of parent compatibility between cg & ccg client geometry - *\param cg First geo - *\param ccg Second geo - *\param p Direction of resizing -*/ -bool -cfactor_parentrow(Geo cg, Geo ccg, Position p) -{ - switch(p) - { - case Left: - return (ccg.x == cg.x); - case Top: - return (ccg.y == cg.y); - case Bottom: - return (ccg.y + ccg.height == cg.y + cg.height); - case Right: - default: - return (ccg.x + ccg.width == cg.x + cg.width); - } - - return False; -} - /** Get c parents of row and resize *\param c Client pointer *\param p Direction of resizing @@ -136,7 +112,7 @@ _cfactor_arrange_row(Client *c, Position p, int fac) /* Travel clients to search parents of row and apply fact */ for(cc = tiled_client(c->screen, clients); cc; cc = tiled_client(c->screen, cc->next)) - if(cfactor_parentrow(cgeo, cc->frame_geo, p)) + if(CFACTOR_PARENTROW(cgeo, cc->frame_geo, p)) { cc->tilefact[p] += fac; client_moveresize(cc, cc->geo, (tags[cc->screen][cc->tag].flags & ResizeHintFlag)); @@ -162,7 +138,7 @@ _cfactor_check_geo_row(Client *c, Position p, int fac) /* Travel clients to search parents of row and check geos */ for(cc = tiled_client(c->screen, clients); cc; cc = tiled_client(c->screen, cc->next)) - if(cfactor_parentrow(cgeo, cc->frame_geo, p)) + if(CFACTOR_PARENTROW(cgeo, cc->frame_geo, p)) { (Geo)cfactor_geo(cc->wrgeo, f, &e); if(e) @@ -198,21 +174,6 @@ cfactor_arrange_two(Client *c1, Client *c2, Position p, int fac) } -/* Check 2 clients parenting compatibility - *\param g1 client1 geo - *\param g2 client2 geo - *\param p Direction of resizing - *\returm 1/0 -*/ -bool -cfactor_check_2pc(Geo g1, Geo g2, Position p) -{ - if(LDIR(p)) - return (g1.height == g2.height); - else - return (g1.width == g2.width); -} - /** Get c parents of row and resize, exception checking same size before arranging row *\param c Client pointer *\param gc Client pointer @@ -222,7 +183,7 @@ cfactor_check_2pc(Geo g1, Geo g2, Position p) static void cfactor_arrange_row(Client *c, Client *gc, Position p, int fac) { - if(cfactor_check_2pc(c->frame_geo, gc->frame_geo, p)) + if(CFACTOR_CHECK2(c->frame_geo, gc->frame_geo, p)) cfactor_arrange_two(c, gc, p, fac); else { diff --git a/src/split.c b/src/split.c index 8b4412a..21234f3 100644 --- a/src/split.c +++ b/src/split.c @@ -32,6 +32,11 @@ #include "wmfs.h" +#define SPLIT_CHECK_ROW(g1, g2, p) \ + (LDIR(p) \ + ? (g1.y >= g2.y && (g1.y + g1.height) <= (g2.y + g2.height)) \ + : (g1.x >= g2.x && (g1.x + g1.width) <= (g2.x + g2.width))) \ + #define SPLIT_MOVE_DIR(d) \ void \ uicb_split_move_##d(uicb_t cmd) \ @@ -65,17 +70,6 @@ _split_arrange_size(Geo g, Geo *cg, Position p) return; } -/** Check if parent client of last closed client is OK for row resize -*/ -static bool -_split_check_row(Geo g1, Geo g2, Position p) -{ - if(LDIR(p)) - return (g1.y >= g2.y && (g1.y + g1.height) <= (g2.y + g2.height)); - else - return (g1.x >= g2.x && (g1.x + g1.width) <= (g2.x + g2.width)); -} - /** Set layout current clients to split/unsplit */ void @@ -135,8 +129,8 @@ _split_check_row_dir(Client *c, Client *g, Position p) for(s = 0, cgeo = c->frame_geo, cc = tiled_client(c->screen, clients); cc; cc = tiled_client(c->screen, cc->next)) - if(cfactor_parentrow(cgeo, cc->frame_geo, RPOS(p)) - && _split_check_row(cc->frame_geo, g->frame_geo, p)) + if(CFACTOR_PARENTROW(cgeo, cc->frame_geo, RPOS(p)) + && SPLIT_CHECK_ROW(cc->frame_geo, g->frame_geo, p)) { s += (LDIR(p) ? cc->frame_geo.height : cc->frame_geo.width); @@ -181,9 +175,9 @@ split_arrange_closed(Client *ghost) * | | C | -> C -> | |v v v| * |_____|_____| -> -> |_____|_____| */ - for(p = Right; p < Bottom + 1; ++p) + for(p = Right; p < Bottom; ++p) if((c = client_get_next_with_direction(ghost, p))) - if(cfactor_check_2pc(ghost->frame_geo, c->frame_geo, p)) + if(CFACTOR_CHECK2(ghost->frame_geo, c->frame_geo, p)) { _split_arrange_size(ghost->wrgeo, &c->wrgeo, p); cfactor_clean(c); @@ -200,13 +194,13 @@ split_arrange_closed(Client *ghost) * | | C | -> A -> | << C | * |_____|_____| -> -> |___________| */ - for(p = Right; p < Bottom + 1 && !b; ++p) + for(p = Right; p < Bottom && !b; ++p) if((c = client_get_next_with_direction(ghost, p)) && _split_check_row_dir(c, ghost, p)) { for(cgeo = c->frame_geo, cc = tiled_client(c->screen, clients); cc; cc = tiled_client(c->screen, cc->next)) - if(cfactor_parentrow(cgeo, cc->frame_geo, RPOS(p)) && - _split_check_row(cc->frame_geo, ghost->frame_geo, p)) + if(CFACTOR_PARENTROW(cgeo, cc->frame_geo, RPOS(p)) + && SPLIT_CHECK_ROW(cc->frame_geo, ghost->frame_geo, p)) { _split_arrange_size(ghost->wrgeo, &cc->wrgeo, p); cfactor_clean(cc); diff --git a/src/tag.c b/src/tag.c index f55e053..bfbc96a 100644 --- a/src/tag.c +++ b/src/tag.c @@ -224,9 +224,9 @@ uicb_tag_prev(uicb_t cmd) void uicb_tag_next_visible(uicb_t cmd) { - int i, tag; + int tag; Client *c; - bool is_occupied[MAXTAG]; + uint occupied = 0; (void)cmd; screen_get_sel(); @@ -237,15 +237,11 @@ uicb_tag_next_visible(uicb_t cmd) return; } - for(i = 0; i < MAXTAG; i++) - is_occupied[i] = False; - for(c = clients; c; c = c->next) - if(c->screen == selscreen) - is_occupied[c->tag] = True; + occupied |= TagFlag(c->tag); for(tag = seltag[selscreen] + 1; tag < conf.ntag[selscreen] + 1; ++tag) - if(is_occupied[tag]) + if(occupied & TagFlag(tag)) { tag_set(tag); return; @@ -253,7 +249,7 @@ uicb_tag_next_visible(uicb_t cmd) if(conf.tag_round) for(tag = 0; tag < seltag[selscreen]; ++tag) - if(is_occupied[tag]) + if(occupied & TagFlag(tag)) { tag_set(tag); return; @@ -268,9 +264,9 @@ uicb_tag_next_visible(uicb_t cmd) void uicb_tag_prev_visible(uicb_t cmd) { - int i, tag; + int tag; Client *c; - bool is_occupied[MAXTAG]; + uint occupied; (void)cmd; screen_get_sel(); @@ -281,15 +277,11 @@ uicb_tag_prev_visible(uicb_t cmd) return; } - for(i = 0; i < MAXTAG; i++) - is_occupied[i] = False; - for(c = clients; c; c = c->next) - if(c->screen == selscreen) - is_occupied[c->tag] = True; + occupied |= TagFlag(c->tag); for(tag = seltag[selscreen] - 1; tag >= 0; --tag) - if(is_occupied[tag]) + if(occupied & TagFlag(tag)) { tag_set(tag); return; @@ -297,7 +289,7 @@ uicb_tag_prev_visible(uicb_t cmd) if(conf.tag_round) for(tag = conf.ntag[selscreen]; tag > seltag[selscreen]; --tag) - if(is_occupied[tag]) + if(occupied & TagFlag(tag)) { tag_set(tag); return; diff --git a/src/wmfs.h b/src/wmfs.h index 68ee1f9..8967910 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -115,6 +115,13 @@ #define LDIR(x) (x < Top) #define FLAGAPPLY(v, b, f) ((b) ? (v |= (f)) : (v &= ~(f))) +/* Cfactor define */ +#define CFACTOR_CHECK2(g1, g2, p) (LDIR(p) ? (g1.height == g2.height) : (g1.width == g2.width)) +#define CFACTOR_PARENTROW(g1, g2, p) \ + (LDIR(p) \ + ? (p == Left ? (g1.x == g2.x) : (g1.x + g1.width == g2.x + g2.width)) \ + : (p == Top ? (g1.y == g2.y) : (g1.y + g1.height == g2.y + g2.height))) \ + /* barwin.c */ BarWindow *barwin_create(Window parent, int x, int y, @@ -161,8 +168,6 @@ void uicb_toggle_tagautohide(uicb_t); /* cfactor.c */ void cfactor_clean(Client *c); Geo cfactor_geo(Geo geo, int fact[4], int *err); -bool cfactor_check_2pc(Geo g1, Geo g2, Position p); -bool cfactor_parentrow(Geo cg, Geo ccg, Position p); void cfactor_set(Client *c, Position p, int fac); void cfactor_multi_set(Client *c, int fac[4]); /* Generated with macro {{{ */