[hackers] wmii: new tip (= 1748)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Mon, 05 Feb 2007 13:50:05 +0100

changeset: 1748:7b5332765a92
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Feb 05 07:47:12 2007 -0500
files: area.c view.c
description:
Fixed sizing bug in create_area with 1 column

diff -r 331303bc9ca6 -r 7b5332765a92 area.c
--- a/area.c Mon Feb 05 06:46:50 2007 -0500
+++ b/area.c Mon Feb 05 07:47:12 2007 -0500
@@ -7,7 +7,14 @@
 #include <stdio.h>
 #include <string.h>
 
-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
                 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
                 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 -r 331303bc9ca6 -r 7b5332765a92 view.c
--- a/view.c Mon Feb 05 06:46:50 2007 -0500
+++ b/view.c Mon Feb 05 07:47:12 2007 -0500
@@ -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;
Received on Mon Feb 05 2007 - 13:50:05 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:54 UTC