Index: group.c
===================================================================
RCS file: /cvs/gnome/metacity/src/group.c,v
retrieving revision 1.10
diff -u -5 -r1.10 group.c
--- group.c	27 Feb 2006 22:19:11 -0000	1.10
+++ group.c	27 Mar 2006 12:18:54 -0000
@@ -110,59 +110,66 @@
   g_assert (window->group != NULL);
 
   return window->group;
 }
 
-void
-meta_window_compute_group (MetaWindow* window)
+/**
+ * meta_display_get_group_for_xwindow() tries to find the MetaGroup
+ * that contains the Window 'xwindow'. It first checks in the
+ * display->groups_by_leader hash to see if 'xwindow' is the leader of
+ * any group. If it is, then that is the group we want. If not, use
+ * meta_display_lookup_x_window() to check if 'xwindow' is a
+ * non-leader member of a group.
+ **/
+static MetaGroup*
+meta_display_get_group_for_xwindow (MetaDisplay *display,
+                                    Window       xwindow)
 {
-  MetaGroup *group;
+  MetaGroup *group = g_hash_table_lookup (display->groups_by_leader,
+                                          &xwindow);
+  MetaWindow *window = meta_display_lookup_x_window (display, xwindow);
 
+  if (window && group == NULL)
+    group = window->group;
+  
+  return group;
+}
+
+static Window
+meta_window_get_grouping_xwindow (MetaWindow *window)
+{
   /* use window->xwindow if no window->xgroup_leader */
-      
-  group = NULL;
-      
+  if (window->xtransient_for != None)
+    return window->xtransient_for;
+  if (window->xgroup_leader != None)
+    return window->xgroup_leader;
+  return window->xwindow;
+}
+
+void
+meta_window_compute_group (MetaWindow* window)
+{
+  MetaGroup *group = NULL;
+  Window grouping_xwindow = meta_window_get_grouping_xwindow (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);
-      else if (window->xgroup_leader != None)
-        group = g_hash_table_lookup (window->display->groups_by_leader,
-                                     &window->xgroup_leader);
-      else
-        group = g_hash_table_lookup (window->display->groups_by_leader,
-                                     &window->xwindow);
-    }
-      
+    group = meta_display_get_group_for_xwindow (window->display,
+                                                grouping_xwindow);
+
   if (group != NULL)
     {
       window->group = group;
       group->refcount += 1;
     }
   else
-    {
-      if (window->xtransient_for != None)
-        group = meta_group_new (window->display,
-                                window->xtransient_for);
-      else if (window->xgroup_leader != None)
-        group = meta_group_new (window->display,
-                                window->xgroup_leader);
-      else
-        group = meta_group_new (window->display,
-                                window->xwindow);
-          
-      window->group = group;
-    }
+    window->group = meta_group_new (window->display, grouping_xwindow);
 
-  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",
-              window->desc, group->group_leader);
-
+              window->desc, window->group->group_leader);
 }
 
 static void
 remove_window_from_group (MetaWindow *window)
 {
