--- orig/libwnck-2.27.5/libwnck/tasklist.c	2009-04-19 11:40:32.000000000 -0600
+++ clean/libwnck-2.27.5/libwnck/tasklist.c	2009-08-10 03:33:54.000000000 -0600
@@ -1148,17 +1148,18 @@
 {
   int n_cols, n_rows;
 
+  /* For our purposes, assume we always have a button */
+  n_buttons = MAX(1, n_buttons);
+
   /* How many rows fit in the allocation */
   n_rows = allocation->height / max_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);
+  /* Don't have more rows than buttons, but have at least one row */
+/*  n_rows = MIN(n_rows, n_buttons);*/
+  n_rows = MAX(1, n_rows);
   
-  /* We want to use as many rows as possible to limit the width */
-  n_cols = (n_buttons + n_rows - 1) / n_rows;
+  /* And how many columns are needed */
+  n_cols = ((n_buttons - 1) / n_rows) + 1;
 
   /* At least one column */
   n_cols = MAX (n_cols, 1);
@@ -1364,10 +1365,20 @@
   lowest_range = G_MAXINT;
   if (tasklist->priv->grouping != WNCK_TASKLIST_ALWAYS_GROUP)
     {
+      if (fake_allocation.height < fake_allocation.width)
+        {
       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);
+        }
+      else
+        {
+          val = n_rows * tasklist->priv->max_button_height;
+          g_array_insert_val (array, array->len, val);
+          val = n_rows * grouping_limit;
+          g_array_insert_val (array, array->len, val);
+        }        
 
       last_n_cols = n_cols;
       lowest_range = val;
@@ -1395,6 +1406,8 @@
 	  (tasklist->priv->grouping == WNCK_TASKLIST_AUTO_GROUP ||
 	   ungrouped_class_groups == NULL))
 	{
+          if (fake_allocation.height < fake_allocation.width)
+            {
 	  val = n_cols * tasklist->priv->max_button_width;
 	  if (val >= lowest_range)
 	    { /* Overlaps old range */
@@ -1410,7 +1423,25 @@
 	      g_array_insert_val (array, array->len, val);
 	      lowest_range = val;
 	    }
-
+            }
+          else
+            {
+              val = n_rows * tasklist->priv->max_button_height;
+              if (val >= lowest_range)
+                { /* Overlaps old range */
+                   g_assert (array->len > 0);
+                  lowest_range = n_rows * grouping_limit;
+                   g_array_index(array, int, array->len-1) = lowest_range;
+                }
+              else
+                {
+                  /* Full new range */
+                  g_array_insert_val (array, array->len, val);
+                  val = n_rows * grouping_limit;
+                  g_array_insert_val (array, array->len, val);
+                  lowest_range = val;
+                }
+            }  
 	  last_n_cols = n_cols;
 	}
     }
@@ -1434,8 +1465,14 @@
     
   tasklist->priv->size_hints = (int *)g_array_free (array, FALSE);
 
+  if (fake_allocation.height < fake_allocation.width) 
+    { 
   requisition->width = tasklist->priv->size_hints[0];
   requisition->height = fake_allocation.height;
+    } else {
+      requisition->width = fake_allocation.width;
+      requisition->height =  tasklist->priv->size_hints[0];
+    }  
 }
 
 /**
@@ -1628,6 +1665,8 @@
       int row = i % n_rows;
       int col = i / n_rows;
       
+      if (allocation->width > allocation->height) 
+        {
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
         col = n_cols - col - 1;
 
@@ -1635,6 +1674,14 @@
       child_allocation.y = allocation->height*row / n_rows;
       child_allocation.width = total_width*(col + 1) / n_cols - child_allocation.x;
       child_allocation.height = allocation->height*(row + 1) / n_rows - child_allocation.y;
+        } 
+      else 
+        {
+          child_allocation.x = total_width*col / n_cols;
+          child_allocation.y = MIN(row * tasklist->priv->max_button_height, allocation->height / n_rows * row);
+          child_allocation.width = allocation->width / n_cols;
+          child_allocation.height = MIN(tasklist->priv->max_button_height, allocation->height / n_rows);
+        }
       child_allocation.x += allocation->x;
       child_allocation.y += allocation->y;
 