Index: libwnck/tasklist.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/tasklist.c,v
retrieving revision 1.75
diff -u -p -r1.75 tasklist.c
--- libwnck/tasklist.c	20 Feb 2005 23:30:35 -0000	1.75
+++ libwnck/tasklist.c	25 Feb 2005 11:29:23 -0000
@@ -60,7 +60,9 @@ typedef struct _WnckTaskClass   WnckTask
 #define DEFAULT_GROUPING_LIMIT 80
 
 #define DEFAULT_WIDTH 1
-#define DEFAULT_HEIGHT 48
+#define DEFAULT_HEIGHT 1
+
+#define DEFAULT_LABEL_CHARS 15
 
 #define N_SCREEN_CONNECTIONS 5
 
@@ -217,12 +219,18 @@ static void     wnck_tasklist_remove	   
 					     GtkWidget	    *widget);
 static void     wnck_tasklist_free_tasks    (WnckTasklist   *tasklist);
 static void     wnck_tasklist_update_lists  (WnckTasklist   *tasklist);
-static int      wnck_tasklist_layout        (GtkAllocation  *allocation,
-					     int             max_width,
-					     int             max_height,
-					     int             n_buttons,
-					     int            *n_cols_out,
-					     int            *n_rows_out);
+static void     wnck_tasklist_request_layout (int             min_height,
+                                              int             button_max_width,
+                                              int             button_max_height,
+                                              int             n_buttons,
+                                              GtkRequisition *requisition,
+                                              int            *n_cols_out,
+                                              int            *n_rows_out);
+static int      wnck_tasklist_allocate_layout (GtkAllocation *allocation,
+                                               int            button_height,
+                                               int            n_buttons,
+                                               int           *n_cols_out,
+                                               int           *n_rows_out);
 
 static void     wnck_tasklist_active_window_changed    (WnckScreen   *screen,
 							WnckTasklist *tasklist);
@@ -733,21 +741,57 @@ wnck_tasklist_set_icon_loader (WnckTaskl
   tasklist->priv->free_icon_loader_data = free_data_func;  
 }
 
+/* determines the maximum size the tasklist can be, and sets n_cols_out
+ * n_rows_out respectively.  note this is far from ideal, as we cannot
+ * know the required geometry until we know the height (and thus how
+ * many rows to use.) (or can we--anyone know more than me?) */
+static void
+wnck_tasklist_request_layout (int             min_height,
+                              int             button_width,
+                              int             button_height,
+                              int             n_buttons,
+                              GtkRequisition *requisition,
+                              int            *n_cols_out,
+                              int            *n_rows_out)
+{
+  int n_cols, n_rows;
+
+  /* How many rows fit in the allocation */
+  n_rows = min_height / button_height;
+
+  /* Don't have more rows than buttons */
+  n_rows = MIN (n_rows, n_buttons);
+
+  /* At least one row */
+  n_rows = MAX (n_rows, 1);
+  
+  /* We want to use as many rows as possible to limit the width */
+  n_cols = (n_buttons + n_rows - 1) / n_rows;
+
+  /* At least one column */
+  n_cols = MAX (n_cols, 1);
+
+  *n_cols_out = n_cols;
+  *n_rows_out = n_rows;
+  
+  requisition->height = n_rows * button_height;
+  requisition->width = n_cols * button_width;
+}
+
 /* returns the maximal possible button width (i.e. if you
  * don't want to stretch the buttons to fill the alloctions
  * the width can be smaller) */
 static int
-wnck_tasklist_layout (GtkAllocation *allocation,
-		      int            max_width,
-		      int            max_height,
-		      int            n_buttons,
-		      int           *n_cols_out,
-		      int           *n_rows_out)
+wnck_tasklist_allocate_layout (GtkAllocation *allocation,
+                               int            button_height,
+                               int            n_buttons,
+                               int           *n_cols_out,
+                               int           *n_rows_out)
 {
   int n_cols, n_rows;
 
   /* How many rows fit in the allocation */
-  n_rows = allocation->height / max_height;
+  n_rows = allocation->height / button_height;
 
   /* Don't have more rows than buttons */
   n_rows = MIN (n_rows, n_buttons);
@@ -852,10 +896,9 @@ wnck_tasklist_size_request  (GtkWidget  
 {
   WnckTasklist *tasklist;
   GtkRequisition child_req;
-  GtkAllocation  fake_allocation;
   int max_height = 1;
   int max_width = 1;
-  /* int u_width, u_height; */
+  int u_width, u_height;
   GList *l;
   GArray *array;
   GList *ungrouped_class_groups;
@@ -920,34 +963,12 @@ wnck_tasklist_size_request  (GtkWidget  
   
   tasklist->priv->max_button_width = max_width;
   tasklist->priv->max_button_height = max_height;
-
-
-  /* this snippet of code seems to want to allocate at least
-   * four buttons' worth of height for the widget.  I think this isn't
-   * necessary any more now that we have the minimum_size option, so
-   * I'm commenting this out - thomasvs */
-  /*
+  
   gtk_widget_get_size_request (widget, &u_width, &u_height);
-
-  if (u_height != -1)
-    {
-      requisition->height = u_height;
-    }
-  else if (u_width != -1)
-    {
-      requisition->width = u_width;
-      requisition->height = 4 * max_height;
-    }
   
-  requisition->width = MAX(requisition->width, tasklist->priv->minimum_width);
-  requisition->height = MAX(requisition->height, tasklist->priv->minimum_height);
-  */
-  requisition->width = tasklist->priv->minimum_width;
-  requisition->height = tasklist->priv->minimum_height;
+  tasklist->priv->minimum_width = MAX(tasklist->priv->minimum_width, u_width);
+  tasklist->priv->minimum_height = MAX(tasklist->priv->minimum_height, u_height);
   
-  fake_allocation.width = requisition->width;
-  fake_allocation.height = requisition->height;
-
   array = g_array_new (FALSE, FALSE, sizeof (int));
 
   /* Calculate size_hints list */
@@ -962,12 +983,12 @@ wnck_tasklist_size_request  (GtkWidget  
 			tasklist->priv->max_button_width);
   
   /* Try ungrouped mode */
-  wnck_tasklist_layout (&fake_allocation,
+  wnck_tasklist_request_layout (tasklist->priv->minimum_height,
 			tasklist->priv->max_button_width,
 			tasklist->priv->max_button_height,
 			n_windows + n_startup_sequences,
-			&n_cols, &n_rows);
-
+			requisition, &n_cols, &n_rows);
+  
   last_n_cols = G_MAXINT;
   lowest_range = G_MAXINT;
   if (tasklist->priv->grouping != WNCK_TASKLIST_ALWAYS_GROUP)
@@ -982,7 +1003,7 @@ wnck_tasklist_size_request  (GtkWidget  
     }
 
   while (ungrouped_class_groups != NULL &&
-	 tasklist->priv->grouping != WNCK_TASKLIST_NEVER_GROUP)
+	 tasklist->priv->grouping == WNCK_TASKLIST_ALWAYS_GROUP)
     {
       if (!score_set)
 	{
@@ -994,14 +1015,12 @@ wnck_tasklist_size_request  (GtkWidget  
 
       n_grouped_buttons += g_list_length (class_group_task->windows) - 1;
 
-      wnck_tasklist_layout (&fake_allocation,
+      wnck_tasklist_request_layout (tasklist->priv->minimum_height,
 			    tasklist->priv->max_button_width,
 			    tasklist->priv->max_button_height,
 			    n_startup_sequences + n_windows - n_grouped_buttons,
-			    &n_cols, &n_rows);
-      if (n_cols != last_n_cols &&
-	  (tasklist->priv->grouping == WNCK_TASKLIST_AUTO_GROUP ||
-	   ungrouped_class_groups == NULL))
+			    requisition, &n_cols, &n_rows);
+      if (n_cols != last_n_cols && ungrouped_class_groups == NULL)
 	{
 	  val = n_cols * tasklist->priv->max_button_width;
 	  if (val >= lowest_range)
@@ -1024,6 +1043,23 @@ wnck_tasklist_size_request  (GtkWidget  
 	  last_n_cols = n_cols;
 	}
     }
+  
+  if (ungrouped_class_groups != NULL &&
+	 tasklist->priv->grouping == WNCK_TASKLIST_AUTO_GROUP)
+    {
+      wnck_tasklist_request_layout (tasklist->priv->minimum_height,
+			    tasklist->priv->max_button_width,
+			    tasklist->priv->max_button_height,
+			    n_startup_sequences + n_windows,
+			    requisition, &n_cols, &n_rows);
+      
+      val = n_cols * tasklist->priv->max_button_width;
+      
+      g_array_insert_val (array, array->len, val);
+      val = n_cols * grouping_limit;
+      g_array_insert_val (array, array->len, val);
+      lowest_range = val;
+    }  
 
   /* Always let you go down to a zero size: */
   if (array->len > 0)
@@ -1084,8 +1120,7 @@ wnck_tasklist_size_allocate (GtkWidget  
 			tasklist->priv->max_button_width);
 
   /* Try ungrouped mode */
-  button_width = wnck_tasklist_layout (allocation,
-				       tasklist->priv->max_button_width,
+  button_width = wnck_tasklist_allocate_layout (allocation,
 				       tasklist->priv->max_button_height,
 				       n_startup_sequences + n_windows,
 				       &n_cols, &n_rows);
@@ -1124,8 +1159,7 @@ wnck_tasklist_size_allocate (GtkWidget  
 	  gtk_widget_set_child_visible (GTK_WIDGET (class_group_task->button), FALSE);
 	}
       
-      button_width = wnck_tasklist_layout (allocation,
-					   tasklist->priv->max_button_width,
+      button_width = wnck_tasklist_allocate_layout (allocation,
 					   tasklist->priv->max_button_height,
 					   n_startup_sequences + n_windows - n_grouped_buttons,
 					   &n_cols, &n_rows);
@@ -1151,9 +1185,10 @@ wnck_tasklist_size_allocate (GtkWidget  
   /* Allocate children */
   l = visible_tasks;
   i = 0;
+
   total_width = tasklist->priv->max_button_width * n_cols;
   total_width = MIN (total_width, allocation->width);
-  total_width = allocation->width;
+
   while (l != NULL)
     {
       WnckTask *task = WNCK_TASK (l->data);
@@ -2665,6 +2700,7 @@ wnck_task_create_widgets (WnckTask *task
   gtk_misc_set_alignment (GTK_MISC (task->label), 0.0, 0.5);
   gtk_label_set_ellipsize (GTK_LABEL (task->label),
                           PANGO_ELLIPSIZE_END);
+  gtk_label_set_width_chars (GTK_LABEL (task->label), DEFAULT_LABEL_CHARS);
 
   if (wnck_task_get_demands_attention (task))
     make_gtk_label_bold ((GTK_LABEL (task->label)));
