Index: src/group.c
===================================================================
RCS file: /cvs/gnome/metacity/src/group.c,v
retrieving revision 1.10
diff -p -u -r1.10 group.c
--- src/group.c	27 Feb 2006 22:19:11 -0000	1.10
+++ src/group.c	30 Mar 2006 19:00:33 -0000
@@ -116,16 +116,21 @@ void
 meta_window_compute_group (MetaWindow* window)
 {
   MetaGroup *group;
+  MetaWindow *ancestor;
 
   /* use window->xwindow if no window->xgroup_leader */
       
   group = NULL;
       
+  /* Determine the ancestor of the window; its group setting will override the
+   * normal grouping rules; see bug 328211.
+   */
+  ancestor = meta_window_find_root_ancestor (window);
+
   if (window->display->groups_by_leader)
     {
-      if (window->xtransient_for != None)
-        group = g_hash_table_lookup (window->display->groups_by_leader,
-                                     &window->xtransient_for);
+      if (ancestor != window)
+        group = ancestor->group;
       else if (window->xgroup_leader != None)
         group = g_hash_table_lookup (window->display->groups_by_leader,
                                      &window->xgroup_leader);
@@ -141,9 +146,9 @@ meta_window_compute_group (MetaWindow* w
     }
   else
     {
-      if (window->xtransient_for != None)
+      if (ancestor != window && ancestor->xgroup_leader != None)
         group = meta_group_new (window->display,
-                                window->xtransient_for);
+                                ancestor->xgroup_leader);
       else if (window->xgroup_leader != None)
         group = meta_group_new (window->display,
                                 window->xgroup_leader);
@@ -154,8 +159,7 @@ meta_window_compute_group (MetaWindow* w
       window->group = group;
     }
 
-  window->group->windows = g_slist_prepend (window->group->windows,
-                                                   window);
+  window->group->windows = g_slist_prepend (window->group->windows, window);
 
   meta_topic (META_DEBUG_GROUPS,
               "Adding %s to group with leader 0x%lx\n",
Index: src/window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.429
diff -p -u -r1.429 window.c
--- src/window.c	29 Mar 2006 18:43:22 -0000	1.429
+++ src/window.c	30 Mar 2006 19:00:33 -0000
@@ -3993,12 +3993,20 @@ find_root_ancestor (MetaWindow *window,
   return TRUE;
 }
 
-void
-meta_window_raise (MetaWindow  *window)
+MetaWindow *
+meta_window_find_root_ancestor (MetaWindow *window)
 {
   MetaWindow *ancestor;
   ancestor = window;
   meta_window_foreach_ancestor (window, find_root_ancestor, &ancestor);
+  return ancestor;
+}
+
+void
+meta_window_raise (MetaWindow  *window)
+{
+  MetaWindow *ancestor;
+  ancestor = meta_window_find_root_ancestor (window);
 
   meta_topic (META_DEBUG_WINDOW_OPS,
               "Raising window %s, ancestor of %s\n", 
Index: src/window.h
===================================================================
RCS file: /cvs/gnome/metacity/src/window.h,v
retrieving revision 1.125
diff -p -u -r1.125 window.h
--- src/window.h	29 Mar 2006 18:43:22 -0000	1.125
+++ src/window.h	30 Mar 2006 19:00:33 -0000
@@ -555,6 +555,8 @@ gboolean meta_window_is_ancestor_of_tran
 void     meta_window_foreach_ancestor         (MetaWindow            *window,
                                                MetaWindowForeachFunc  func,
                                                void                  *data);
+MetaWindow* meta_window_find_root_ancestor    (MetaWindow *window);
+
 
 void meta_window_begin_grab_op (MetaWindow *window,
                                 MetaGrabOp  op,
