Index: libegg/tray/eggtrayicon.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/tray/eggtrayicon.c,v
retrieving revision 1.8
diff -u -r1.8 eggtrayicon.c
--- libegg/tray/eggtrayicon.c	16 Jun 2005 13:27:40 -0000	1.8
+++ libegg/tray/eggtrayicon.c	16 Mar 2006 21:57:33 -0000
@@ -64,8 +64,10 @@
 					GValue     *value,
 					GParamSpec *pspec);
 
-static void egg_tray_icon_realize   (GtkWidget *widget);
-static void egg_tray_icon_unrealize (GtkWidget *widget);
+static void     egg_tray_icon_realize   (GtkWidget   *widget);
+static void     egg_tray_icon_unrealize (GtkWidget   *widget);
+static gboolean egg_tray_icon_delete    (GtkWidget   *wigdet,
+					 GdkEventAny *event);
 
 #ifdef GDK_WINDOWING_X11
 static void egg_tray_icon_update_manager_window    (EggTrayIcon *icon,
@@ -120,6 +122,8 @@
 
   widget_class->realize   = egg_tray_icon_realize;
   widget_class->unrealize = egg_tray_icon_unrealize;
+  widget_class->delete_event = egg_tray_icon_delete;
+  widget_class->destroy_event = egg_tray_icon_delete;
 
   g_object_class_install_property (gobject_class,
 				   PROP_ORIENTATION,
@@ -366,6 +370,41 @@
 }
 
 #endif
+
+static gboolean 
+egg_tray_icon_delete (GtkWidget   *widget,
+		      GdkEventAny *event)
+{
+#ifdef GDK_WINDOWING_X11
+  EggTrayIcon *icon = EGG_TRAY_ICON (widget);
+  GdkWindow *gdkwin;
+
+  if (icon->manager_window != None)
+    {  
+      gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
+					      icon->manager_window);
+      
+      gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
+      
+      icon->manager_window = None;
+    }
+
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      gboolean visible = GTK_WIDGET_VISIBLE (widget);
+
+      if (visible)
+	gtk_widget_hide (widget);
+      gtk_widget_unrealize (widget);
+      if (visible)
+	gtk_widget_show (widget);
+    }
+
+  egg_tray_icon_update_manager_window (icon, TRUE);  
+
+#endif
+  return TRUE;
+}
 
 static void
 egg_tray_icon_realize (GtkWidget *widget)
