wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit fca197fdb342c4faf1faf553e5745280f88dae5c
parent b36bee30fb199427c572d50067ffde168fd117ea
Author: Sander van Dijk <sander@wmii.de>
Date:   Wed,  3 May 2006 21:11:14 +0000

a little restructuring, moves the MIN_COLWIDTH/min_height handling into scale_* (where it belongs). The way it's done now is safer than before.


Diffstat:
cmd/wm/area.c | 14+-------------
cmd/wm/column.c | 25+++++++++++++++++--------
cmd/wm/view.c | 22++++++++++++++++------
3 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -18,8 +18,7 @@ Area * create_area(View *v) { static unsigned short id = 1; - unsigned int w, i, xoff = 0; - int wdiff; + unsigned int w; Area *a = nil; if(v->area.size > 1) { @@ -36,17 +35,6 @@ create_area(View *v) if(v->area.size > 1) scale_view(v, rect.width - w); - for(i = 1; i < v->area.size; i++) { - Area *b = v->area.data[i]; - b->rect.x = xoff; - b->rect.y = 0; - b->rect.height = rect.height - brect.height; - if(b->rect.width < MIN_COLWIDTH) - b->rect.width = MIN_COLWIDTH; - else if((wdiff = b->rect.x + b->rect.width - (rect.width - w) + (v->area.size - 1 - i) * MIN_COLWIDTH) > 0) - b->rect.width -= wdiff; - xoff += b->rect.width; - } a = cext_emallocz(sizeof(Area)); a->view = v; a->id = id++; diff --git a/cmd/wm/column.c b/cmd/wm/column.c @@ -110,8 +110,10 @@ relax_column(Area *a) void scale_column(Area *a, float h) { - unsigned int i; + unsigned int i, yoff = 0; + unsigned int min_height = 2 * height_of_bar(); float scale, dy = 0; + int hdiff; if(!a->frame.size) return; @@ -123,6 +125,20 @@ scale_column(Area *a, float h) Frame *f = a->frame.data[i]; f->rect.height *= scale; } + + /* min_height can only be respected when there is enough space; the caller should guarantee this */ + if(a->frame.size * min_height > h) + return; + for(i = 0; i < a->frame.size; i++) { + Frame *f = a->frame.data[i]; + if(f->rect.height < min_height) + f->rect.height = min_height; + else if((hdiff = yoff + f->rect.height - h + (a->frame.size - i) * min_height) > 0) + f->rect.height -= hdiff; + if(i == a->frame.size - 1) + f->rect.height = h - yoff; + yoff += f->rect.height; + } } void @@ -130,7 +146,6 @@ arrange_column(Area *a, Bool dirty) { unsigned int i, yoff = a->rect.y, h; unsigned int min_height = 2 * height_of_bar(); - int hdiff; if(!a->frame.size) return; @@ -150,12 +165,6 @@ arrange_column(Area *a, Bool dirty) f->rect.x = a->rect.x; f->rect.y = yoff; f->rect.width = a->rect.width; - if(f->rect.height < min_height) - f->rect.height = min_height; - else if((hdiff = yoff + f->rect.height - a->rect.height + (a->frame.size - i) * min_height) > 0) - f->rect.height -= hdiff; - if(i == a->frame.size - 1) - f->rect.height = a->rect.height - yoff; yoff += f->rect.height; resize_client(f->client, &f->rect, True); } diff --git a/cmd/wm/view.c b/cmd/wm/view.c @@ -271,8 +271,9 @@ restack_view(View *v) void scale_view(View *v, float w) { - unsigned int i; + unsigned int i, xoff = 0; float scale, dx = 0; + int wdiff = 0; if(v->area.size == 1) return; @@ -284,13 +285,26 @@ scale_view(View *v, float w) Area *a = v->area.data[i]; a->rect.width *= scale; } + + /* MIN_COLWIDTH can only be respected when there is enough space; the caller should guarantee this */ + if((v->area.size - 1) * MIN_COLWIDTH > w) + return; + for(i = 1; i < v->area.size; i++) { + Area *a = v->area.data[i]; + if(a->rect.width < MIN_COLWIDTH) + a->rect.width = MIN_COLWIDTH; + else if((wdiff = xoff + a->rect.width - w + (v->area.size - 1 - i) * MIN_COLWIDTH) > 0) + a->rect.width -= wdiff; + if(i == v->area.size - 1) + a->rect.width = w - xoff; + xoff += a->rect.width; + } } void arrange_view(View *v) { unsigned int i, xoff = 0; - int wdiff = 0; if(v->area.size == 1) return; @@ -301,10 +315,6 @@ arrange_view(View *v) a->rect.x = xoff; a->rect.y = 0; a->rect.height = rect.height - brect.height; - if(a->rect.width < MIN_COLWIDTH) - a->rect.width = MIN_COLWIDTH; - else if((wdiff = a->rect.x + a->rect.width - rect.width + (v->area.size - 1 - i) * MIN_COLWIDTH) > 0) - a->rect.width -= wdiff; xoff += a->rect.width; arrange_column(a, False); }