--- gnome-python-extras-2.25.3/egg/tray/eggtrayicon.c.orig	2009-12-26 00:34:47.276889481 +0900
+++ gnome-python-extras-2.25.3/egg/tray/eggtrayicon.c	2009-12-30 01:08:10.694650865 +0900
@@ -107,7 +107,10 @@ egg_tray_icon_init (EggTrayIcon *icon)
 {
   icon->stamp = 1;
   icon->orientation = GTK_ORIENTATION_HORIZONTAL;
+  icon->manager_visual = NULL;
+  icon->manager_visual_rgba = FALSE;
   
+  gtk_widget_set_app_paintable (GTK_WIDGET (icon), TRUE);
   gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
 }
 
@@ -218,6 +221,59 @@ egg_tray_icon_get_orientation_property (
     XFree (prop.prop);
 }
 
+static void
+egg_tray_icon_get_visual_property (EggTrayIcon *icon)
+{
+  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (icon));
+  GdkDisplay *display = gdk_screen_get_display (screen);
+  Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
+
+  Atom type;
+  int format;
+  union {
+        gulong *prop;
+        guchar *prop_ch;
+  } prop = { NULL };
+  gulong nitems;
+  gulong bytes_after;
+  int error, result;
+  GdkVisual *visual;
+
+  g_assert (icon->manager_window != None);
+
+  gdk_error_trap_push ();
+  type = None;
+  result = XGetWindowProperty (xdisplay,
+                               icon->manager_window,
+                               icon->visual_atom,
+                               0, G_MAXLONG, FALSE,
+                               XA_VISUALID,
+                               &type, &format, &nitems,
+                               &bytes_after, &(prop.prop_ch));
+  error = gdk_error_trap_pop ();
+
+  visual = NULL;
+
+  if (!error && result == Success &&
+      type == XA_VISUALID && nitems == 1 && format == 32)
+    {
+      VisualID visual_id = prop.prop[0];
+      visual = gdk_x11_screen_lookup_visual (screen, visual_id);
+    }
+
+  icon->manager_visual = visual;
+  icon->manager_visual_rgba = visual != NULL &&
+    (visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth);
+
+  /* For the background-relative hack we use when we aren't using a real RGBA
+   * visual, we can't be double-buffered */
+  gtk_widget_set_double_buffered (GTK_WIDGET (icon), icon->manager_visual_rgba);
+
+  if (type != None)
+    XFree (prop.prop);
+}
+
+
 static GdkFilterReturn
 egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data)
 {
@@ -320,6 +376,7 @@ egg_tray_icon_update_manager_window (Egg
 				     gboolean     dock_if_realized)
 {
   Display *xdisplay;
+  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (icon));
   
   if (icon->manager_window != None)
     return;
@@ -347,10 +404,24 @@ egg_tray_icon_update_manager_window (Egg
       
       gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
 
-      if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
-	egg_tray_icon_send_dock_request (icon);
-
       egg_tray_icon_get_orientation_property (icon);
+      egg_tray_icon_get_visual_property (icon);
+
+      if (GTK_WIDGET_REALIZED (icon))
+        {
+	  if ((icon->manager_visual == NULL &&
+	       gtk_widget_get_visual (GTK_WIDGET (icon)) == gdk_screen_get_system_visual (screen)) ||
+	      (icon->manager_visual == gtk_widget_get_visual (GTK_WIDGET (icon))))
+	    {
+	      egg_tray_icon_send_dock_request (icon);
+	    }
+	  else
+	    {
+	      gtk_widget_hide (GTK_WIDGET (icon));
+	      gtk_widget_unrealize (GTK_WIDGET (icon));
+	      gtk_widget_show (GTK_WIDGET (icon));
+	    }
+        }
     }
 }
 
@@ -373,30 +444,103 @@ egg_tray_icon_manager_window_destroyed (
 
 #endif
 
+static void
+egg_tray_icon_set_colormap (EggTrayIcon *icon)
+{
+  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (icon));
+  GdkColormap *colormap;
+  GdkVisual *visual = icon->manager_visual;
+  gboolean new_colormap = FALSE;
+
+  /* To avoid uncertainty about colormaps, _NET_SYSTEM_TRAY_VISUAL is supposed
+   * to be either the screen default visual or a TrueColor visual; ignore it
+   * if it is something else
+   */
+  if (visual && visual->type != GDK_VISUAL_TRUE_COLOR)
+    visual = NULL;
+
+  if (visual == NULL || visual == gdk_screen_get_system_visual (screen))
+    colormap = gdk_screen_get_system_colormap (screen);
+  else if (visual == gdk_screen_get_rgb_visual (screen))
+    colormap = gdk_screen_get_rgb_colormap (screen);
+  else if (visual == gdk_screen_get_rgba_visual (screen))
+    colormap = gdk_screen_get_rgba_colormap (screen);
+  else
+    {
+      colormap = gdk_colormap_new (visual, FALSE);
+      new_colormap = TRUE;
+    }
+
+  gtk_widget_set_colormap (GTK_WIDGET (icon), colormap);
+
+  if (new_colormap)
+    g_object_unref (colormap);
+}
+
 static gboolean
 transparent_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 {
-  gdk_window_clear_area (widget->window, event->area.x, event->area.y,
-			 event->area.width, event->area.height);
-  return FALSE;
+  EggTrayIcon *icon = EGG_TRAY_ICON (widget);
+  gboolean retval = FALSE;
+
+  if (icon->manager_visual_rgba)
+    {
+      /* Clear to transparent */
+      cairo_t *cr = gdk_cairo_create (widget->window);
+      cairo_set_source_rgba (cr, 0, 0, 0, 0);
+      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+      gdk_cairo_region (cr, event->region);
+      cairo_fill (cr);
+      cairo_destroy (cr);
+    }
+  else
+    {
+      gdk_window_clear_area (widget->window, event->area.x, event->area.y,
+			     event->area.width, event->area.height);
+    }
+
+  if (GTK_WIDGET_CLASS (parent_class)->expose_event)
+    retval = GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+
+  return retval;
 }
 
 static void
 make_transparent_again (GtkWidget *widget, GtkStyle *previous_style,
 			gpointer user_data)
 {
-  gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+  EggTrayIcon *icon = EGG_TRAY_ICON (widget);
+  if (icon->manager_visual_rgba)
+    {
+      /* Set a transparent background */
+      GdkColor transparent = { 0, 0, 0, 0 }; /* Only pixel=0 matters */
+      gdk_window_set_background (widget->window, &transparent);
+    }
+  else
+    {
+      gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+    }
 }
 
 static void
 make_transparent (GtkWidget *widget, gpointer user_data)
 {
-  if (GTK_WIDGET_NO_WINDOW (widget) || GTK_WIDGET_APP_PAINTABLE (widget))
+  EggTrayIcon *icon;
+
+  if (GTK_WIDGET_NO_WINDOW (widget))
     return;
 
-  gtk_widget_set_app_paintable (widget, TRUE);
-  gtk_widget_set_double_buffered (widget, FALSE);
-  gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+  icon = EGG_TRAY_ICON (widget);
+  if (icon->manager_visual_rgba)
+    {
+      /* Set a transparent background */
+      GdkColor transparent = { 0, 0, 0, 0 }; /* Only pixel=0 matters */
+      gdk_window_set_background (widget->window, &transparent);
+    }
+  else
+    {
+      gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
+    }
   g_signal_connect (widget, "expose_event",
 		    G_CALLBACK (transparent_expose_event), NULL);
   g_signal_connect_after (widget, "style_set",
@@ -414,11 +558,6 @@ egg_tray_icon_realize (GtkWidget *widget
   char buffer[256];
   GdkWindow *root_window;
 
-  if (GTK_WIDGET_CLASS (parent_class)->realize)
-    GTK_WIDGET_CLASS (parent_class)->realize (widget);
-
-  make_transparent (widget, NULL);
-
   screen = gtk_widget_get_screen (widget);
   display = gdk_screen_get_display (screen);
   xdisplay = gdk_x11_display_get_xdisplay (display);
@@ -440,8 +579,22 @@ egg_tray_icon_realize (GtkWidget *widget
 					"_NET_SYSTEM_TRAY_ORIENTATION",
 					False);
 
+  icon->visual_atom = XInternAtom (xdisplay,
+                                   "_NET_SYSTEM_TRAY_VISUAL",
+                                   False);
+
   egg_tray_icon_update_manager_window (icon, FALSE);
-  egg_tray_icon_send_dock_request (icon);
+
+  /* Set our colormap before realizing */
+  egg_tray_icon_set_colormap (icon);
+
+  if (GTK_WIDGET_CLASS (parent_class)->realize)
+    GTK_WIDGET_CLASS (parent_class)->realize (widget);
+
+  make_transparent (widget, NULL);
+
+  if (icon->manager_window != None)
+    egg_tray_icon_send_dock_request (icon);
 
   root_window = gdk_screen_get_root_window (screen);
   
--- gnome-python-extras-2.25.3/egg/tray/eggtrayicon.h.orig	2009-12-26 00:40:41.597913903 +0900
+++ gnome-python-extras-2.25.3/egg/tray/eggtrayicon.h	2009-12-26 01:05:24.705644736 +0900
@@ -49,8 +49,11 @@ struct _EggTrayIcon
   Atom manager_atom;
   Atom system_tray_opcode_atom;
   Atom orientation_atom;
+  Atom visual_atom;
   Window manager_window;
 #endif
+  GdkVisual *manager_visual;
+  gboolean manager_visual_rgba;
   GtkOrientation orientation;
 };
 
