--- gtk+2.0-2.16.6.old/gdk/x11/gdkxid.c	2009-08-29 04:07:54.000000000 +0200
+++ gtk+2.0-2.16.6/gdk/x11/gdkxid.c	2009-09-24 19:56:46.951189557 +0200
@@ -56,9 +56,31 @@
   if (!display_x11->xid_ht)
     display_x11->xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash,
 					    (GEqualFunc) gdk_xid_equal);
-
-  if (g_hash_table_lookup (display_x11->xid_ht, xid))
-    g_warning ("XID collision, trouble ahead");
+  GdkWindow *window;
+  if ((window = g_hash_table_lookup (display_x11->xid_ht, xid)) != NULL) {
+    /* Matthias Clasen [gtk+ developer] 2009-07-06 01:24:03 UTC
+     * use XCheckWindowEvent at the time of the collision and
+     * process the pending DestroyNotify out-of-order, but that
+     * might have other issues...
+     */
+    Display *xdisplay = GDK_WINDOW_XDISPLAY (window);
+    Window xwindow = GDK_WINDOW_XWINDOW (window);
+    XEvent delete_event;
+    int i = 0;
+    g_warning ("XID collision, try to do something useful.");
+    //FIXME: we want ony DestroyNotify events, or do we?
+    //Maybe in fact remove every xevent for this window
+    //because after that the xid will be wrong
+    while (XCheckWindowEvent(xdisplay,
+			     xwindow,
+			     StructureNotifyMask|SubstructureNotifyMask,
+			     &delete_event)) {
+      //TODO: do something to manage this destroy event...like handle the event
+      i++;
+      g_warning ("XID collision - but %d,%d event removed", i, delete_event.type);
+    }
+    g_warning ("XID collision -- found %d event(s)", i);
+  }
 
   g_hash_table_insert (display_x11->xid_ht, xid, data);
 }
