From a44505c1a9e06a95f4308db3ff1e32e0ffdb801f Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sat, 21 May 2011 17:14:52 +0200 Subject: [PATCH] Split: Improve arrange_closed with _split_check_row --- src/cfactor.c | 2 +- src/client.c | 8 ++++---- src/split.c | 47 +++++++++++++++++++++++++++++++++++++++-------- src/wmfs.h | 1 + 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/cfactor.c b/src/cfactor.c index 56ad7e4..fcae7a1 100644 --- a/src/cfactor.c +++ b/src/cfactor.c @@ -199,7 +199,7 @@ cfactor_arrange_two(Client *c1, Client *c2, Position p, int fac) Bool cfactor_check_2pc(XRectangle g1, XRectangle g2, Position p) { - if(p < Top) + if(LDIR(p)) return (g1.height == g2.height); else return (g1.width == g2.width); diff --git a/src/client.c b/src/client.c index 7e8adb4..653c53d 100644 --- a/src/client.c +++ b/src/client.c @@ -151,10 +151,10 @@ client_get_next_with_direction(Client *bc, Position pos) return NULL; /* Start place of pointer for faster scanning */ - x = bc->geo.x + ((pos == Right) ? bc->geo.width : 0); - y = bc->geo.y + ((pos == Bottom) ? bc->geo.height : 0); - y += ((pos < Top) ? bc->geo.height / 2 : 0); - x += ((pos > Left) ? bc->geo.width / 2 : 0); + x = bc->frame_geo.x + ((pos == Right) ? bc->frame_geo.width : 0); + y = bc->frame_geo.y + ((pos == Bottom) ? bc->frame_geo.height : 0); + y += ((pos < Top) ? bc->frame_geo.height / 2 : 0); + x += ((pos > Left) ? bc->frame_geo.width / 2 : 0); /* Scan in right direction to next(p) physical client */ for(; (c = client_gb_pos(bc, x, y)) == bc; x += scanfac[pos][0], y += scanfac[pos][1]); diff --git a/src/split.c b/src/split.c index 08f4bd9..d77eb22 100644 --- a/src/split.c +++ b/src/split.c @@ -37,7 +37,7 @@ static void _split_arrange_size(XRectangle g, XRectangle *cg, Position p) { - if(p < Top) + if(LDIR(p)) cg->width += FRAMEW(g.width); else cg->height += FRAMEH(g.height); @@ -56,12 +56,43 @@ _split_arrange_size(XRectangle g, XRectangle *cg, Position p) static Bool _split_check_row(XRectangle g1, XRectangle g2, Position p) { - if(p < Top) + 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)); } +/** Check if row direction is available to resize from it + *\param c Client pointer + *\param g Client pointer + *\param p Position + *\return True if available +*/ +static Bool +_split_check_row_dir(Client *c, Client *g, Position p) +{ + int s, cs; + XRectangle cgeo; + Client *cc; + + cs = (LDIR(p) ? g->frame_geo.height : g->frame_geo.width); + + 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)) + { + s += (LDIR(p) ? cc->frame_geo.height : cc->frame_geo.width); + + if(s == cs) + return True; + if(s > cs) + return False; + } + + return False; +} + /** Arrange clients after a client close *\param ghost Ghost client */ @@ -77,7 +108,7 @@ split_arrange_closed(Client *ghost) if(tags[screen][seltag[screen]].layout.func != split) return; - /* Use ghost client to fix holes in tile + /* Use ghost client properties to fix holes in tile * .--. ~ ~ * /xx \ ~ ~ * ~~\O _ (____ ~ @@ -116,19 +147,19 @@ split_arrange_closed(Client *ghost) * |_____|_____| -> -> |___________| */ for(p = Right; p < Bottom + 1 && !b; ++p) - if((c = client_get_next_with_direction(ghost, 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); client_moveresize(cc, (cc->pgeo = cc->wrgeo), tags[screen][cc->tag].resizehint); b = True; } - } + } return; } diff --git a/src/wmfs.h b/src/wmfs.h index 58b576f..136b4ef 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -110,6 +110,7 @@ #define LEN(x) (sizeof(x) / sizeof((x)[0])) #define MAXCLIST (64) #define RPOS(x) (x % 2 ? x - 1 : x + 1) +#define LDIR(x) (x < Top) /* barwin.c */ BarWindow *barwin_create(Window parent,