Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/metacity/ChangeLog,v
retrieving revision 1.772
diff -u -p -u -r1.772 ChangeLog
--- ChangeLog	13 Dec 2003 03:58:53 -0000	1.772
+++ ChangeLog	14 Dec 2003 15:26:31 -0000
@@ -1,3 +1,15 @@
+2003-12-13  Rob Adams  <readams@readams.net>
+
+	* src/window.c (meta_window_new_with_attrs): set on_all_workspaces
+	in all cases _before_ adding to the workspaces, so that windows
+	initially on all workspaces are added correctly to the MRU lists.
+	Fix for #120907.
+
+	* src/workspace.c (meta_workspace_add_window): handle sticky
+	windows so that we add to add mru lists if needed
+	(meta_workspace_remove_window): handle sticky windows so that they
+	are removed from all mru lists if needed.
+
 2003-12-12  Havoc Pennington  <hp@redhat.com>
 
 	* src/window.c (meta_window_free): unstick window to get it out of
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.317
diff -u -p -u -r1.317 window.c
--- src/window.c	13 Dec 2003 23:00:06 -0000	1.317
+++ src/window.c	14 Dec 2003 15:26:32 -0000
@@ -581,6 +581,17 @@ meta_window_new_with_attrs (MetaDisplay 
   meta_window_grab_keys (window);
   meta_display_grab_window_buttons (window->display, window->xwindow);
   meta_display_grab_focus_window_button (window->display, window);
+
+  if (window->type == META_WINDOW_DESKTOP ||
+      window->type == META_WINDOW_DOCK)
+    {
+      /* Change the default, but don't enforce this if the user
+       * focuses the dock/desktop and unsticks it using key shortcuts.
+       * Need to set this before adding to the workspaces so the MRU
+       * lists will be updated.
+       */
+      window->on_all_workspaces = TRUE;
+    }
   
   /* For the workspace, first honor hints,
    * if that fails put transients with parents,
@@ -595,8 +606,11 @@ meta_window_new_with_attrs (MetaDisplay 
                       "Window %s is initially on all spaces\n",
                       window->desc);
           
-          meta_workspace_add_window (window->screen->active_workspace, window);
+	  /* need to set on_all_workspaces first so that it will be
+	   * added to all the MRU lists
+	   */
           window->on_all_workspaces = TRUE;
+          meta_workspace_add_window (window->screen->active_workspace, window);
         }
       else
         {
@@ -636,6 +650,8 @@ meta_window_new_with_attrs (MetaDisplay 
           tmp_list = parent->workspaces;
           while (tmp_list != NULL)
             {
+	      /* this will implicitly add to the appropriate MRU lists
+	       */
               meta_workspace_add_window (tmp_list->data, window);
               
               tmp_list = tmp_list->next;
@@ -654,16 +670,6 @@ meta_window_new_with_attrs (MetaDisplay 
       meta_workspace_add_window (space, window);
     }
   
-  if (window->type == META_WINDOW_DESKTOP ||
-      window->type == META_WINDOW_DOCK)
-    {
-      /* Change the default, but don't enforce this if
-       * the user focuses the dock/desktop and unsticks it
-       * using key shortcuts
-       */
-      window->on_all_workspaces = TRUE;
-    }
-
   /* for the various on_all_workspaces = TRUE possible above */
   meta_window_set_current_workspace_hint (window);
   
@@ -944,12 +950,6 @@ meta_window_free (MetaWindow  *window)
   meta_window_unqueue_move_resize (window);
   meta_window_unqueue_update_icon (window);
   meta_window_free_delete_dialog (window);
-
-  /* We need to unstick to remove the window from
-   * any workspace->mru_list for workspaces not
-   * in window->workspaces
-   */
-  meta_window_unstick (window);
   
   tmp = window->workspaces;
   while (tmp != NULL)
Index: src/workspace.c
===================================================================
RCS file: /cvs/gnome/metacity/src/workspace.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 workspace.c
--- src/workspace.c	13 Dec 2003 23:00:06 -0000	1.50
+++ src/workspace.c	14 Dec 2003 15:26:33 -0000
@@ -112,11 +112,33 @@ meta_workspace_add_window (MetaWorkspace
 {
   g_return_if_fail (!meta_workspace_contains_window (workspace, window));
   
+  /* If the window is on all workspaces, we want to add it to all mru
+   * lists, otherwise just add it to this workspaces mru list
+   */
+  if (window->on_all_workspaces) 
+    {
+      if (window->workspaces == NULL)
+        {
+          GList* tmp = window->screen->workspaces;
+          while (tmp)
+            {
+              MetaWorkspace* work = (MetaWorkspace*) tmp->data;
+              if (!g_list_find (work->mru_list, window))
+                work->mru_list = g_list_append (work->mru_list, window);
+
+              tmp = tmp->next;
+            }
+        }
+    }
+  else
+    {
+      g_assert (g_list_find (workspace->mru_list, window) == NULL);
+      workspace->mru_list = g_list_append (workspace->mru_list, window);
+    }
+
   workspace->windows = g_list_prepend (workspace->windows, window);
   window->workspaces = g_list_prepend (window->workspaces, workspace);
 
-  workspace->mru_list = g_list_append (workspace->mru_list, window);
-
   meta_window_set_current_workspace_hint (window);
   
   meta_window_queue_calc_showing (window);
@@ -142,7 +164,30 @@ meta_workspace_remove_window (MetaWorksp
 
   workspace->windows = g_list_remove (workspace->windows, window);
   window->workspaces = g_list_remove (window->workspaces, workspace);
-  workspace->mru_list = g_list_remove (workspace->mru_list, window);
+
+  /* If the window is on all workspaces, we don't want to remove it
+   * from the MRU list unless this causes it to be removed from all 
+   * workspaces
+   */
+  if (window->on_all_workspaces) 
+    {
+      if (window->workspaces == NULL)
+        {
+          GList* tmp = window->screen->workspaces;
+          while (tmp)
+            {
+              MetaWorkspace* work = (MetaWorkspace*) tmp->data;
+              work->mru_list = g_list_remove (work->mru_list, window);
+
+              tmp = tmp->next;
+            }
+        }
+    }
+  else
+    {
+      workspace->mru_list = g_list_remove (workspace->mru_list, window);
+      g_assert (g_list_find (workspace->mru_list, window) == NULL);
+    }
 
   meta_window_set_current_workspace_hint (window);
   
