Index: class-group.c
===================================================================
--- class-group.c	(révision 1237)
+++ class-group.c	(copie de travail)
@@ -261,7 +261,7 @@ get_name_from_applications (WnckClassGro
 
       if (!first_name)
 	{
-	  if (app)
+	  if (app && wnck_application_has_name (app))
 	    first_name = wnck_application_get_name (app);
 	}
       else
@@ -301,7 +301,7 @@ get_name_from_windows (WnckClassGroup *c
 
       window = WNCK_WINDOW (l->data);
 
-      if (!first_name)
+      if (!first_name && wnck_window_has_name (window))
 	first_name = wnck_window_get_name (window);
       else
 	if (strcmp (first_name, wnck_window_get_name (window)) != 0)
@@ -317,6 +317,43 @@ get_name_from_windows (WnckClassGroup *c
     return NULL;
 }
 
+static const char *
+get_res_name_from_windows (WnckClassGroup *class_group)
+{
+  WnckClassGroupPrivate *priv;
+  const char *first_name;
+  GList *l;
+
+  priv = class_group->priv;
+
+  /* Try to get the name from windows, following the same rationale as
+   * get_name_from_applications()
+   */
+
+  first_name = NULL;
+
+  for (l = priv->windows; l; l = l->next)
+    {
+      WnckWindow *window;
+
+      window = WNCK_WINDOW (l->data);
+
+      if (!first_name)
+	first_name = _wnck_window_get_resource_name (window);
+      else
+	if (!_wnck_window_get_resource_name (window) ||
+            strcmp (first_name, wnck_window_get_name (window)) != 0)
+	  break;
+    }
+
+  if (!l)
+    {
+      /* All names are the same, so use one of them */
+      return first_name;
+    }
+  else
+    return NULL;
+}
 
 /* Gets a sensible name for the class group from the application group leaders
  * or from individual windows.
@@ -329,12 +366,6 @@ set_name (WnckClassGroup *class_group)
 
   priv = class_group->priv;
 
-  if (priv->name)
-    {
-      g_free (priv->name);
-      priv->name = NULL;
-    }
-
   new_name = get_name_from_applications (class_group);
 
   if (!new_name)
@@ -342,7 +373,12 @@ set_name (WnckClassGroup *class_group)
       new_name = get_name_from_windows (class_group);
 
       if (!new_name)
-	new_name = priv->res_class;
+        {
+          new_name = get_res_name_from_windows (class_group);
+
+          if (!new_name)
+            new_name = priv->res_class;
+        }
     }
 
   g_assert (new_name != NULL);
Index: application.c
===================================================================
--- application.c	(révision 1237)
+++ application.c	(copie de travail)
@@ -217,6 +217,28 @@ wnck_application_get_n_windows (WnckAppl
 }
 
 /**
+ * wnck_application_has_name:
+ * @app: a #WnckApplication
+ *
+ * Checks whether or not @app has a name. wnck_application_get_name()
+ * will always return some value, even if the application hasn't set a
+ * name; wnck_application_has_name() can be used to tell if that name is
+ * real or not.
+ *
+ * For icons titles, use wnck_application_has_icon_name() instead.
+ *
+ * Return value: %TRUE if wnck_application_get_name() returns the application's
+ * real name, %FALSE if it returns a fallback name.
+ **/
+gboolean
+wnck_application_has_name (WnckApplication *app)
+{
+  g_return_val_if_fail (WNCK_IS_APPLICATION (app), FALSE);
+
+  return app->priv->name != NULL;
+}
+
+/**
  * wnck_application_get_name:
  * @app: a #WnckApplication
  * 
@@ -241,6 +263,35 @@ wnck_application_get_name (WnckApplicati
 }
 
 /**
+ * wnck_application_has_icon_name:
+ * @app: a #WnckApplication
+ *
+ * Checks whether or not @app has an icon name.
+ * wnck_application_get_icon_name() will always return some value, even if
+ * the application hasn't set an icon name; wnck_application_has_icon_name() can
+ * be used to tell if that name is real or not.
+ *
+ * (Note that if wnck_application_has_icon_name() returns %FALSE, but
+ * wnck_application_has_name() returns %TRUE, then the icon name returned by
+ * wnck_application_get_icon_name() is the application icon name. Only when
+ * both methods return %FALSE does wnck_application_get_icon_name() return a
+ * generic fallback icon name.)
+ *
+ * Return value: %TRUE if wnck_application_get_icon_name() returns the
+ * application's real icon name, %FALSE if it returns a fallback icon name.
+ **/
+gboolean
+wnck_application_has_icon_name (WnckApplication *app)
+{
+  g_return_val_if_fail (WNCK_IS_APPLICATION (app), FALSE);
+
+  /* FIXME this isn't actually implemented, should be different
+   * from regular name
+   */
+  return app->priv->name != NULL;
+}
+
+/**
  * wnck_application_get_icon_name:
  * @app: a #WnckApplication
  * 
Index: window.c
===================================================================
--- window.c	(révision 1237)
+++ window.c	(copie de travail)
@@ -496,16 +496,16 @@ wnck_window_get_name (WnckWindow *window
  * Checks whether or not @window has an icon name.
  * wnck_window_get_icon_name() will always return some value, even if
  * the window hasn't set an icon name; wnck_window_has_icon_name() can
- * be used to tell if that name is real or not.
+ * be used to tell if that icon name is real or not.
  *
  * (Note that if wnck_window_has_icon_name() returns %FALSE, but
- * wnck_window_has_name() returns %TRUE, then the name returned by
- * wnck_window_get_icon_name() is the window name. Only when both
+ * wnck_window_has_name() returns %TRUE, then the icon name returned by
+ * wnck_window_get_icon_name() is the window icon name. Only when both
  * methods return %FALSE does wnck_window_get_icon_name() return a
- * generic fallback name.)
+ * generic fallback icon name.)
  *
  * Return value: %TRUE if wnck_window_get_icon_name() returns the
- * window's real icon name, %FALSE if it returns a fallback name.
+ * window's real icon name, %FALSE if it returns a fallback icon name.
  **/
 gboolean
 wnck_window_has_icon_name (WnckWindow *window)
Index: application.h
===================================================================
--- application.h	(révision 1237)
+++ application.h	(copie de travail)
@@ -70,7 +70,9 @@ int    wnck_application_get_n_windows (W
  * prop is the same for all windows in the app, return the values for
  * the window. Failing that, they make stuff up.
  */
+gboolean    wnck_application_has_name      (WnckApplication *app);
 const char* wnck_application_get_name      (WnckApplication *app);
+gboolean    wnck_application_has_icon_name (WnckApplication *app);
 const char* wnck_application_get_icon_name (WnckApplication *app);
 int         wnck_application_get_pid       (WnckApplication *app);
 GdkPixbuf*  wnck_application_get_icon      (WnckApplication *app);
