Index: group.c
===================================================================
RCS file: /cvs/gnome/metacity/src/group.c,v
retrieving revision 1.4
diff -p -u -r1.4 group.c
--- group.c	1 Dec 2002 03:58:04 -0000	1.4
+++ group.c	4 Jun 2003 05:52:39 -0000
@@ -106,66 +106,68 @@ meta_window_get_group (MetaWindow *windo
   if (window->unmanaging)
     return NULL;
   
-  if (window->cached_group == NULL)
-    {
-      MetaGroup *group;
+  return window->group;
+}
+
+void
+meta_window_compute_group (MetaWindow* window)
+{
+  MetaGroup *group;
 
-      /* use window->xwindow if no window->xgroup_leader */
+  /* use window->xwindow if no window->xgroup_leader */
       
-      group = NULL;
+  group = NULL;
       
-      if (window->display->groups_by_leader)
-        {
-          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);
-        }
+  if (window->display->groups_by_leader)
+    {
+      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);
+    }
       
-      if (group != NULL)
-        {
-          window->cached_group = group;
-          group->refcount += 1;
-        }
+  if (group != NULL)
+    {
+      window->group = group;
+      group->refcount += 1;
+    }
+  else
+    {
+      if (window->xgroup_leader != None)
+        group = meta_group_new (window->display,
+                                window->xgroup_leader);
       else
-        {
-          if (window->xgroup_leader != None)
-            group = meta_group_new (window->display,
-                                    window->xgroup_leader);
-          else
-            group = meta_group_new (window->display,
-                                    window->xwindow);
+        group = meta_group_new (window->display,
+                                window->xwindow);
           
-          window->cached_group = group;
-        }
+      window->group = group;
+    }
 
-      window->cached_group->windows = g_slist_prepend (window->cached_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);
-    }
+  meta_topic (META_DEBUG_GROUPS,
+              "Adding %s to group with leader 0x%lx\n",
+              window->desc, group->group_leader);
 
-  return window->cached_group;
 }
 
 static void
 remove_window_from_group (MetaWindow *window)
 {
-  if (window->cached_group != NULL)
+  if (window->group != NULL)
     {
       meta_topic (META_DEBUG_GROUPS,
                   "Removing %s from group with leader 0x%lx\n",
-                  window->desc, window->cached_group->group_leader);
+                  window->desc, window->group->group_leader);
       
-      window->cached_group->windows =
-        g_slist_remove (window->cached_group->windows,
+      window->group->windows =
+        g_slist_remove (window->group->windows,
                         window);
-      meta_group_unref (window->cached_group);
-      window->cached_group = NULL;
+      meta_group_unref (window->group);
+      window->group = NULL;
     }
 }
 
Index: group.h
===================================================================
RCS file: /cvs/gnome/metacity/src/group.h,v
retrieving revision 1.2
diff -p -u -r1.2 group.h
--- group.h	1 Dec 2002 03:58:04 -0000	1.2
+++ group.h	4 Jun 2003 05:52:39 -0000
@@ -26,6 +26,7 @@
 
 /* note, can return NULL */
 MetaGroup* meta_window_get_group       (MetaWindow *window);
+void       meta_window_compute_group   (MetaWindow* window);
 void       meta_window_shutdown_group  (MetaWindow *window);
 
 void       meta_window_group_leader_changed (MetaWindow *window);
Index: window.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window.c,v
retrieving revision 1.278
diff -p -u -r1.278 window.c
--- window.c	30 May 2003 20:24:00 -0000	1.278
+++ window.c	4 Jun 2003 05:52:44 -0000
@@ -490,7 +490,7 @@ meta_window_new (MetaDisplay *display,
   window->top_strut = 0;
   window->bottom_strut = 0;
 
-  window->cached_group = NULL;
+  window->group = NULL;
 
   window->using_net_wm_name = FALSE;
   window->using_net_wm_icon_name = FALSE;
@@ -692,6 +692,10 @@ meta_window_new (MetaDisplay *display,
       }
   }
   
+  /* assign the window to its group, or create a new group if needed
+   */
+  meta_window_compute_group (window);
+
   /* Maximize windows if they are too big for their work
    * area (bit of a hack here). Assume undecorated windows
    * probably don't intend to be maximized.
Index: window.h
===================================================================
RCS file: /cvs/gnome/metacity/src/window.h,v
retrieving revision 1.86
diff -p -u -r1.86 window.h
--- window.h	17 Mar 2003 06:36:39 -0000	1.86
+++ window.h	4 Jun 2003 05:52:45 -0000
@@ -284,7 +284,7 @@ struct _MetaWindow
   int dialog_pipe;
 
   /* maintained by group.c */
-  MetaGroup *cached_group;
+  MetaGroup *group;
 };
 
 #define META_WINDOW_ALLOWS_MOVE(w)     ((w)->has_move_func && !(w)->maximized && !(w)->fullscreen)
