Index: src/group.c
===================================================================
RCS file: /cvs/gnome/metacity/src/group.c,v
retrieving revision 1.9.16.1
diff -p -u -r1.9.16.1 group.c
--- src/group.c	27 Feb 2006 22:17:58 -0000	1.9.16.1
+++ src/group.c	28 Mar 2006 22:31:32 -0000
@@ -116,16 +116,24 @@ 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 = window;
+  while (ancestor && ancestor->xtransient_for != None)
+    ancestor = meta_display_lookup_x_window (window->display,
+                                             ancestor->xtransient_for);
+
   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 && 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 +149,9 @@ meta_window_compute_group (MetaWindow* w
     }
   else
     {
-      if (window->xtransient_for != None)
+      if (ancestor && 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);
