diff -u gtk+-3.18.5/gdk/x11/gdkxid.c gtk+-3.18.5-ID-581526/gdk/x11/gdkxid.c
--- gtk+-3.18.5/gdk/x11/gdkxid.c	2015-11-16 20:30:14.000000000 +0200
+++ gtk+-3.18.5-ID-581526/gdk/x11/gdkxid.c	2015-11-24 19:51:57.000000000 +0200
@@ -41,12 +41,20 @@
   return (*a == *b);
 }
 
+/* node for singly-linked list */
+typedef struct GdkWindow_Node {
+  GdkWindow *data;
+  struct GdkWindow_Node *next;
+} GdkWindow_Node;
+
 void
 _gdk_x11_display_add_window (GdkDisplay *display,
                              XID        *xid,
                              GdkWindow  *data)
 {
   GdkX11Display *display_x11;
+  GdkWindow_Node *new_node;
+  GdkWindow_Node *existing_node;
 
   g_return_if_fail (xid != NULL);
   g_return_if_fail (GDK_IS_DISPLAY (display));
@@ -57,10 +65,19 @@
     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");
-
-  g_hash_table_insert (display_x11->xid_ht, xid, data);
+  existing_node = g_hash_table_lookup (display_x11->xid_ht, xid);
+  new_node = g_malloc (sizeof (GdkWindow_Node));
+  new_node->data = data;
+
+  if (existing_node) {
+    /* add the node to the head of the list */
+    new_node->next = existing_node;
+    g_hash_table_replace (display_x11->xid_ht, xid, new_node);
+
+  } else {
+    new_node->next = NULL;
+    g_hash_table_insert (display_x11->xid_ht, xid, new_node);
+  }
 }
 
 void
@@ -68,13 +85,32 @@
                                 XID         xid)
 {
   GdkX11Display *display_x11;
+  GdkWindow_Node *current_node;
+  GdkWindow_Node *prev_node;
 
   g_return_if_fail (GDK_IS_DISPLAY (display));
 
   display_x11 = GDK_X11_DISPLAY (display);
 
-  if (display_x11->xid_ht)
-    g_hash_table_remove (display_x11->xid_ht, &xid);
+  if (display_x11->xid_ht) {
+    /* delete oldest node, from tail */
+    current_node = g_hash_table_lookup (display_x11->xid_ht, &xid);
+    if (current_node) {
+      /* look for the last node */
+      prev_node = current_node;
+      while (current_node->next) {
+        prev_node = current_node;
+        current_node = current_node->next;
+      }
+
+      if (prev_node == current_node)
+        g_hash_table_remove (display_x11->xid_ht, &xid);
+      else
+        prev_node->next = NULL;
+
+      g_free (current_node);
+    }
+  }
 }
 
 /**
@@ -95,14 +131,18 @@
                                    Window      window)
 {
   GdkX11Display *display_x11;
-  GdkWindow *data = NULL;
+  GdkWindow_Node *node;
 
   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
 
   display_x11 = GDK_X11_DISPLAY (display);
 
   if (display_x11->xid_ht)
-    data = g_hash_table_lookup (display_x11->xid_ht, &window);
+    node = g_hash_table_lookup (display_x11->xid_ht, &window);
 
-  return data;
+  /* return the newest GdkWindow, from the head of the list */
+  if (node)
+    return node->data;
+  else
+    return NULL;
 }
