diff -uNrp gnome-panel-2.22.2.orig/applets/notification_area/na-tray.c gnome-panel-2.22.2.new/applets/notification_area/na-tray.c
--- gnome-panel-2.22.2.orig/applets/notification_area/na-tray.c	2008-08-09 20:21:23.000000000 +0930
+++ gnome-panel-2.22.2.new/applets/notification_area/na-tray.c	2008-08-10 18:58:32.000000000 +0930
@@ -37,6 +37,7 @@
 
 #define ICON_SPACING 1
 #define MIN_BOX_SIZE 3
+#define MIN_ICON_SIZE 22
 
 typedef struct
 {
@@ -51,6 +52,7 @@ struct _NaTrayPrivate
   GdkScreen   *screen;
   TraysScreen *trays_screen;
 
+  GtkWidget *table;
   GtkWidget *box;
   GtkWidget *frame;
 
@@ -99,6 +101,89 @@ get_tray (TraysScreen *trays_screen)
   return trays_screen->all_trays->data;
 }
 
+typedef struct _PackData {
+	GtkOrientation orient;
+	guint n_rows;
+	guint n_cols;
+	guint index;
+} PackData;
+
+static void repack_icon_with_data(GtkWidget *icon,
+																	NaTray *tray,
+																	PackData *data)
+{
+	NaTrayPrivate *priv;
+	priv = tray->priv;
+	guint row, col;
+	guint left, right, top, bottom;
+
+	if (data->orient == GTK_ORIENTATION_HORIZONTAL) {
+		col = data->index / data->n_rows;
+		row = data->index %  data->n_rows;
+	} else {
+		row = data->index / data->n_cols;
+		col = data->index %  data->n_cols;
+	}
+	gtk_container_child_get (GTK_TABLE (priv->table),
+													 icon,
+													 "left-attach", &left, 
+													 "right-attach", &right,
+													 "top-attach", &top, 
+													 "bottom-attach", &bottom,
+													 NULL);
+	if (left != col || right != col + 1 ||
+			 top != row || bottom != row + 1)
+	{
+		gtk_container_child_set (GTK_TABLE (priv->table),
+														 icon,
+														 "left-attach", col, 
+														 "right-attach", col + 1,
+														 "top-attach", row, 
+														 "bottom-attach", row + 1,
+														 NULL);
+	}
+	data->index++;
+}
+
+static void
+repack_icon_table(TraysScreen *trays_screen)
+{
+	NaTray *tray;
+	NaTrayPrivate *priv;
+	guint rows, cols;
+	PackData pack_data;
+
+	tray = get_tray (trays_screen);
+	if (tray == NULL)
+		return;
+
+	priv = tray->priv;
+
+	if (trays_screen->icon_table)
+	{
+		if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) {
+			rows = MAX (1, GTK_WIDGET(tray)->allocation.height / MIN_ICON_SIZE);
+			cols = MAX (1, g_hash_table_size (trays_screen->icon_table) / rows);
+			if (g_hash_table_size (trays_screen->icon_table) % rows)
+				cols++;
+		} else {
+			cols = MAX (1, GTK_WIDGET (tray)->allocation.width / MIN_ICON_SIZE);
+			rows = MAX (1, g_hash_table_size (trays_screen->icon_table) / cols);
+			if (g_hash_table_size (trays_screen->icon_table) % cols)
+				rows++;
+		}
+		gtk_table_resize( GTK_TABLE (priv->table), rows, cols);
+		pack_data.n_rows = rows;
+		pack_data.n_cols = cols;
+		pack_data.orient = priv->orientation;
+		pack_data.index = 0;
+
+		g_hash_table_foreach(trays_screen->icon_table,
+												 (GHFunc)repack_icon_with_data,
+												 &pack_data);
+	}
+}
+
 static void
 tray_added (NaTrayManager *manager,
             GtkWidget     *icon,
@@ -106,6 +191,7 @@ tray_added (NaTrayManager *manager,
 {
   NaTray *tray;
   NaTrayPrivate *priv;
+	guint rows, cols;
 
   tray = get_tray (trays_screen);
   if (tray == NULL)
@@ -117,8 +203,22 @@ tray_added (NaTrayManager *manager,
   
   g_hash_table_insert (trays_screen->icon_table, icon, tray);
 
-  gtk_box_pack_end (GTK_BOX (priv->box), icon, FALSE, FALSE, 0);
-
+	// add to end of table
+	if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) {
+		rows = MAX (1, GTK_WIDGET(tray)->allocation.height / MIN_ICON_SIZE);
+		cols = MAX (1, g_hash_table_size (trays_screen->icon_table) / rows);
+		if (g_hash_table_size (trays_screen->icon_table) % rows)
+			cols++;
+	} else {
+		cols = MAX (1, GTK_WIDGET (tray)->allocation.width / MIN_ICON_SIZE);
+		rows = MAX (1, g_hash_table_size (trays_screen->icon_table) / cols);
+		if (g_hash_table_size (trays_screen->icon_table) % cols)
+			rows++;
+	}
+	gtk_table_attach_defaults (GTK_TABLE (priv->table),
+														 icon,
+														 cols - 1, cols,
+														 rows - 1, rows);
   gtk_widget_show (icon);
   na_tray_force_redraw (tray);
 }
@@ -129,16 +229,20 @@ tray_removed (NaTrayManager *manager,
               TraysScreen   *trays_screen)
 {
   NaTray *tray;
+  NaTrayPrivate *priv;
 
   tray = g_hash_table_lookup (trays_screen->icon_table, icon);
   if (tray == NULL)
     return;
 
+  priv = tray->priv;
   g_assert (tray->priv->trays_screen == trays_screen);
 
+  g_hash_table_remove (trays_screen->icon_table, icon);
+	repack_icon_table (trays_screen);
+	gtk_container_remove (GTK_CONTAINER (priv->table), icon);
   na_tray_force_redraw (tray);
 
-  g_hash_table_remove (trays_screen->icon_table, icon);
   /* this will also destroy the tip associated to this icon */
   g_hash_table_remove (trays_screen->tip_table, icon);
 }
@@ -405,6 +509,7 @@ update_size_and_orientation (NaTray *tra
       break;
     }
 
+	repack_icon_table (priv->trays_screen);
   na_tray_force_redraw (tray);
 }
 
@@ -426,6 +531,11 @@ na_tray_init (NaTray *tray)
   gtk_box_set_spacing (GTK_BOX (priv->box), ICON_SPACING);
   gtk_container_add (GTK_CONTAINER (priv->frame), priv->box);
   gtk_widget_show (priv->box);
+
+  priv->table = gtk_table_new (0, 0, TRUE);
+	gtk_table_set_row_spacings (GTK_TABLE (priv->table), ICON_SPACING);
+	gtk_table_set_col_spacings (GTK_TABLE (priv->table), ICON_SPACING);
+  gtk_box_pack_start (GTK_BOX (priv->box), priv->table, TRUE, TRUE, 0);
 }
 
 static GObject *
@@ -586,7 +696,11 @@ static void
 na_tray_size_allocate (GtkWidget        *widget,
                        GtkAllocation    *allocation)
 {
+  NaTray *tray = NA_TRAY (widget);
+  
+	widget->allocation = *allocation;
   gtk_widget_size_allocate (gtk_bin_get_child (GTK_BIN (widget)), allocation);
+	repack_icon_table (tray->priv->trays_screen);
 }
 
 static void
Binary files gnome-panel-2.22.2.orig/applets/notification_area/.na-tray.c.swp and gnome-panel-2.22.2.new/applets/notification_area/.na-tray.c.swp differ
