Index: libwnck/private.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/private.h,v
retrieving revision 1.17
diff -p -u -r1.17 private.h
--- libwnck/private.h	6 Jan 2005 20:09:23 -0000	1.17
+++ libwnck/private.h	22 Jan 2005 20:02:37 -0000
@@ -50,7 +50,8 @@ void _wnck_screen_process_property_notif
 void _wnck_window_process_configure_notify (WnckWindow *window,
                                             XEvent     *xevent);
 WnckWindow* _wnck_window_create  (Window      xwindow,
-                                  WnckScreen *screen);
+                                  WnckScreen *screen,
+                                  gint        sort_order);
 void        _wnck_window_destroy (WnckWindow *window);
 
 const char* _wnck_window_get_startup_id (WnckWindow *window);
Index: libwnck/screen.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/screen.c,v
retrieving revision 1.25
diff -p -u -r1.25 screen.c
--- libwnck/screen.c	16 Aug 2004 03:15:30 -0000	1.25
+++ libwnck/screen.c	22 Jan 2005 20:02:37 -0000
@@ -55,6 +55,11 @@ struct _WnckScreenPrivate
   WnckWindow *previously_active_window;
   WnckWorkspace *active_workspace;
 
+  /* Provides the sorting order number for the next window, to make
+   * sure windows remain sorted in the order they appear.
+   */
+  gint window_order;
+
   Pixmap bg_pixmap;
   
   guint update_handler;  
@@ -384,6 +389,7 @@ wnck_screen_construct (WnckScreen *scree
   screen->priv->xroot = RootWindow (gdk_display, number);
   screen->priv->xscreen = ScreenOfDisplay (gdk_display, number);
   screen->priv->number = number;
+  screen->priv->window_order = 0;
 
 #ifdef HAVE_STARTUP_NOTIFICATION
   screen->priv->sn_display = sn_display_new (gdk_display,
@@ -891,13 +897,13 @@ update_client_list (WnckScreen *screen)
 
   new_hash = g_hash_table_new (NULL, NULL);
   
-  new_stack_list = NULL;
+  new_list = NULL;
   i = 0;
-  while (i < stack_length)
+  while (i < mapping_length)
     {
       WnckWindow *window;
 
-      window = wnck_window_get (stack[i]);
+      window = wnck_window_get (mapping[i]);
 
       if (window == NULL)
         {
@@ -906,7 +912,10 @@ update_client_list (WnckScreen *screen)
 	  const char *res_class;
 	  WnckClassGroup *class_group;
           
-          window = _wnck_window_create (stack[i], screen);
+          window = _wnck_window_create (mapping[i], 
+                                        screen,
+                                        screen->priv->window_order++);
+
           created = g_list_prepend (created, window);
 
 	  /* Application */
@@ -936,7 +945,7 @@ update_client_list (WnckScreen *screen)
 	  _wnck_class_group_add_window (class_group, window);
         }
 
-      new_stack_list = g_list_prepend (new_stack_list, window);
+      new_list = g_list_prepend (new_list, window);
 
       g_hash_table_insert (new_hash, window, window);
       
@@ -944,12 +953,12 @@ update_client_list (WnckScreen *screen)
     }
       
   /* put list back in order */
-  new_stack_list = g_list_reverse (new_stack_list);
+  new_list = g_list_reverse (new_list);
 
   /* Now we need to find windows in the old list that aren't
    * in this new list
    */
-  tmp = screen->priv->stacked_windows;
+  tmp = screen->priv->mapped_windows;
   while (tmp != NULL)
     {
       WnckWindow *window = tmp->data;
@@ -984,17 +993,17 @@ update_client_list (WnckScreen *screen)
   g_hash_table_destroy (new_hash);
 
   /* Now get the mapping in list form */
-  new_list = NULL;
+  new_stack_list = NULL;
   i = 0;
-  while (i < mapping_length)
+  while (i < stack_length)
     {
       WnckWindow *window;
 
-      window = wnck_window_get (mapping[i]);
+      window = wnck_window_get (stack[i]);
 
       g_assert (window != NULL);
 
-      new_list = g_list_prepend (new_list, window);
+      new_stack_list = g_list_prepend (new_stack_list, window);
       
       ++i;
     }
@@ -1003,7 +1012,7 @@ update_client_list (WnckScreen *screen)
   g_free (mapping);
       
   /* put list back in order */
-  new_list = g_list_reverse (new_list);
+  new_stack_list = g_list_reverse (new_stack_list);
   
   /* Now new_stack_list becomes screen->priv->stack_windows, new_list
    * becomes screen->priv->mapped_windows, and we emit the opened/closed
Index: libwnck/tasklist.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/tasklist.c,v
retrieving revision 1.71
diff -p -u -r1.71 tasklist.c
--- libwnck/tasklist.c	18 Jan 2005 21:08:11 -0000	1.71
+++ libwnck/tasklist.c	22 Jan 2005 20:02:37 -0000
@@ -1154,8 +1154,8 @@ wnck_tasklist_size_allocate (GtkWidget  
   while (l != NULL)
     {
       WnckTask *task = WNCK_TASK (l->data);
-      int col = i % n_cols;
-      int row = i / n_cols;
+      int row = i % n_rows;
+      int col = i / n_rows;
       
       child_allocation.x = total_width*col / n_cols;
       child_allocation.y = allocation->height*row / n_rows;
@@ -2774,11 +2774,10 @@ wnck_task_compare (gconstpointer  a,
 {
   WnckTask *task1 = WNCK_TASK (a);
   WnckTask *task2 = WNCK_TASK (b);
-  gulong xid1_1, xid1_2;
-  gulong xid2_1, xid2_2;
-  
-  xid1_1 = xid1_2 = xid2_1 = xid2_2 = 0;   /* silence compiler */
-  
+  gint pos1, pos2;
+
+  pos1 = pos2 = 0;  /* silence the compiler */
+
   switch (task1->type)
     {
     case WNCK_TASK_CLASS_GROUP:
@@ -2788,11 +2787,10 @@ wnck_task_compare (gconstpointer  a,
 	return -1; /* Sort groups before everything else */
 
     case WNCK_TASK_WINDOW:
-      xid1_1 = wnck_window_get_group_leader (task1->window);
-      xid1_2 = wnck_window_get_xid (task1->window);
+      pos1 = wnck_window_get_sort_order (task1->window);
       break;
     case WNCK_TASK_STARTUP_SEQUENCE:
-      xid1_1 = xid1_2 = G_MAXULONG;
+      pos1 = G_MAXINT;
       break;
     }
 
@@ -2805,20 +2803,20 @@ wnck_task_compare (gconstpointer  a,
 	return 1; /* Sort groups before everything else */
 
     case WNCK_TASK_WINDOW:
-      xid2_1 = wnck_window_get_group_leader (task2->window);
-      xid2_2 = wnck_window_get_xid (task2->window);
+      pos2 = wnck_window_get_sort_order (task2->window);
       break;
     case WNCK_TASK_STARTUP_SEQUENCE:
-      xid2_1 = xid2_2 = G_MAXULONG;
+      pos2 = G_MAXINT;
       break;
     }
       
-  if ((xid1_1 < xid2_1) || ((xid1_1 == xid2_1) && (xid1_2 < xid2_2)))
+  if (pos1 < pos2)
     return -1;
-  else if ((xid1_1 == xid2_1) && (xid1_2 == xid2_2))
-    return 0;
-  else
+  else if (pos1 > pos2)
     return 1;
+  else
+    return 0; /* should only happen if there's multiple processes being
+               * started, and then who cares about sort order... */
 }
 
 static void
Index: libwnck/window.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.c,v
retrieving revision 1.49
diff -p -u -r1.49 window.c
--- libwnck/window.c	11 Jan 2005 19:58:23 -0000	1.49
+++ libwnck/window.c	22 Jan 2005 20:02:37 -0000
@@ -63,6 +63,7 @@ struct _WnckWindowPrivate
   char *session_id_utf8;
   int pid;
   int workspace;
+  gint sort_order;
 
   WnckWindowType wintype;
   
@@ -346,7 +347,8 @@ wnck_window_get_screen (WnckWindow *wind
 
 WnckWindow*
 _wnck_window_create (Window      xwindow,
-                     WnckScreen *screen)
+                     WnckScreen *screen,
+                     gint        sort_order)
 {
   WnckWindow *window;
 
@@ -386,6 +388,8 @@ _wnck_window_create (Window      xwindow
                              &window->priv->y,
                              &window->priv->width,
                              &window->priv->height);
+
+  window->priv->sort_order = sort_order;
   
   window->priv->need_update_name = TRUE;
   window->priv->need_update_state = TRUE;
@@ -550,6 +554,23 @@ wnck_window_get_pid (WnckWindow *window)
   g_return_val_if_fail (WNCK_IS_WINDOW (window), 0);
 
   return window->priv->pid;
+}
+
+/**
+ * wnck_window_get_sort_order:
+ * @window: a #WnckWindow
+ *
+ * Gets the sort order of @window; used for ordering of the window in
+ * the tasklist.  This is defined when the window is created.
+ *
+ * Return value: sort order of @window, or G_MAXINT if none available
+ **/
+gint
+wnck_window_get_sort_order (WnckWindow *window)
+{
+  g_return_val_if_fail (WNCK_IS_WINDOW (window), G_MAXINT);
+
+  return window->priv->sort_order;
 }
 
 /**
Index: libwnck/window.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.h,v
retrieving revision 1.28
diff -p -u -r1.28 window.h
--- libwnck/window.h	11 Jan 2005 19:58:23 -0000	1.28
+++ libwnck/window.h	22 Jan 2005 20:02:37 -0000
@@ -144,6 +144,7 @@ WnckClassGroup *wnck_window_get_class_gr
 const char* wnck_window_get_session_id        (WnckWindow *window);
 const char* wnck_window_get_session_id_utf8   (WnckWindow *window);
 int         wnck_window_get_pid               (WnckWindow *window);
+gint        wnck_window_get_sort_order        (WnckWindow *window);
 
 WnckWindowType wnck_window_get_window_type    (WnckWindow *window);
 
