# Calculate format=diff merge(gnome-base/gdm)>=2.20&&merge(gnome-base/gdm)<=3
diff --git a/gui/gdmuser.c b/gui/gdmuser.c
index 2dff3f6..27a169f 100644
--- a/gui/gdmuser.c
+++ b/gui/gdmuser.c
@@ -232,13 +232,32 @@ gdm_sort_func (gpointer d1, gpointer d2)
 {
     GdmUser *a = d1;
     GdmUser *b = d2;
+    char *astr;
+    char *bstr;
 
     if (!d1 || !d2)
         return (0);
 
-    return (strcmp (a->login, b->login));
+    astr = (a->gecos && strcmp(a->gecos, "") != 0 ) ? a->gecos : a->login;
+    bstr = (b->gecos && strcmp(b->gecos, "") != 0 ) ? b->gecos : b->login;
+    if(astr == a->gecos && bstr == b->gecos && !strcmp(astr,bstr)) {
+	return (strcmp (a->login, b->login));
+    }
+
+    return (strcmp (astr, bstr));
 }
 
+static gint
+gdm_sort_login_func (gpointer d1, gpointer d2)
+{
+    GdmUser *a = d1;
+    GdmUser *b = d2;
+
+    if (!d1 || !d2)
+        return (0);
+
+    return (strcmp (a->login, b->login));
+}
 
 static gboolean
 setup_user (struct passwd *pwent,
@@ -267,7 +286,7 @@ setup_user (struct passwd *pwent,
 				   defface, read_faces);
 
 	    if ((user) &&
-		(! g_list_find_custom (*users, user, (GCompareFunc) gdm_sort_func))) {
+		(! g_list_find_custom (*users, user, (GCompareFunc) gdm_sort_login_func))) {
 		cnt++;
 		*users = g_list_insert_sorted (*users, user,
 		     (GCompareFunc) gdm_sort_func);
diff --git a/gui/greeter/greeter_item_ulist.c b/gui/greeter/greeter_item_ulist.c
index 574a10b..d9f2628 100644
--- a/gui/greeter/greeter_item_ulist.c
+++ b/gui/greeter/greeter_item_ulist.c
@@ -187,14 +187,23 @@ greeter_populate_user_list (GtkTreeModel *tm)
 		GdmUser    *usr = li->data;
 		GtkTreeIter iter = {0};
 		char       *label;
+		char       *gecos;
+		char       *login;
 		char       *name;
 		gboolean    active;
 
+		login = gdm_common_text_to_escaped_utf8 (usr->login);
+
 		if (usr->gecos && strcmp (usr->gecos, "") != 0) {
-			name = gdm_common_text_to_escaped_utf8 (usr->gecos);
-		} else {
-			name = gdm_common_text_to_escaped_utf8 (usr->login);
+			gecos = gdm_common_text_to_escaped_utf8 (usr->gecos);
+			name = g_strdup_printf ("%s\n%s",gecos,login);
+			g_free (gecos);
 		}
+		else {
+			name = g_strdup (login);
+		}
+
+		g_free (login);
 
 		if (g_hash_table_lookup (displays_hash, usr->login))
 			active = TRUE;
@@ -202,12 +211,11 @@ greeter_populate_user_list (GtkTreeModel *tm)
 			active = FALSE;
 
 		if (active) {
-			label = g_strdup_printf ("<b>%s</b>\n    <i><small>%s</small></i>",
+			label = g_strdup_printf ("%s  <i><small>%s</small></i>",
 						 name,
 						 _("Already logged in"));
 		} else {
-			label = g_strdup_printf ("<b>%s</b>\n",
-						 name);
+			label = g_strdup (name);
 		}
 
 		g_free (name);
