From 0adf0d0cb345f7a2231c5e68b6de2049d479c5fc Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 5 Feb 2007 07:47:12 -0500 Subject: [PATCH] Fixed sizing bug in create_area with 1 column --- area.c | 13 ++++++++++--- view.c | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/area.c b/area.c index 868f8b9a..307c9061 100644 --- a/area.c +++ b/area.c @@ -7,7 +7,14 @@ #include #include -Client * +static int +max(int a, int b) { + if(a > b) + return a; + return b; +} + +Client * sel_client_of_area(Area *a) { return a && a->sel ? a->sel->client : nil; } @@ -28,7 +35,7 @@ create_area(View *v, Area *pos, unsigned int w) { area_num++, i++; for(; a; a = a->next) area_num++; - col_num = area_num ? area_num - 1 : 0; + col_num = max((area_num - 1), 0); if(!w) { if(area_num) w = screen->rect.width / (col_num + 1); @@ -39,7 +46,7 @@ create_area(View *v, Area *pos, unsigned int w) { w = min_width; if(col_num && col_num * min_width + w > screen->rect.width) return nil; - if(i > 1) + if(i) scale_view(v, screen->rect.width - w); a = ixp_emallocz(sizeof(Area)); diff --git a/view.c b/view.c index 1cbdd695..9e4fcebb 100644 --- a/view.c +++ b/view.c @@ -209,16 +209,21 @@ restack_view(View *v) { void scale_view(View *v, float w) { - unsigned int xoff, col_size = 0; - unsigned int min_width = screen->rect.width/NCOL; + unsigned int xoff, num_col; + unsigned int min_width; Area *a; float scale, dx = 0; int wdiff = 0; + min_width = screen->rect.width/NCOL; + if(!v->area->next) return; - for(a=v->area->next; a; a=a->next, col_size++) - dx += a->rect.width; + + num_col = 0; + for(a=v->area->next; a; a=a->next) + num_col++, dx += a->rect.width; + scale = w / dx; xoff = 0; for(a=v->area->next; a; a=a->next) { @@ -227,14 +232,15 @@ scale_view(View *v, float w) { a->rect.width = w - xoff; xoff += a->rect.width; } - /* min_width can only be respected when there is enough space; the caller should guarantee this */ - if(col_size * min_width > w) + /* min_width can only be respected when there is enough space; + * the caller should guarantee this */ + if(num_col * min_width > w) return; xoff = 0; - for(a=v->area->next, col_size--; a; a=a->next, col_size--) { + for(a=v->area->next, num_col--; a; a=a->next, num_col--) { if(a->rect.width < min_width) a->rect.width = min_width; - else if((wdiff = xoff + a->rect.width - w + col_size * min_width) > 0) + else if((wdiff = xoff + a->rect.width - w + num_col * min_width) > 0) a->rect.width -= wdiff; if(!a->next) a->rect.width = w - xoff;