diff -ru gtk+-2.10.12/gdk/gdkaliasdef.c gtk+-2.10.12-xdisplay/gdk/gdkaliasdef.c
--- gtk+-2.10.12/gdk/gdkaliasdef.c	2007-05-02 17:29:54.000000000 +0100
+++ gtk+-2.10.12-xdisplay/gdk/gdkaliasdef.c	2007-05-29 15:19:47.000000000 +0100
@@ -2360,6 +2360,9 @@
 #undef gdk_x11_lookup_xdisplay 
 extern __typeof (gdk_x11_lookup_xdisplay) gdk_x11_lookup_xdisplay __attribute((alias("IA__gdk_x11_lookup_xdisplay"), visibility("default")));
 
+#undef gdk_x11_foreign_new_xdisplay 
+extern __typeof (gdk_x11_foreign_new_xdisplay) gdk_x11_foreign_new_xdisplay __attribute((alias("IA__gdk_x11_foreign_new_xdisplay"), visibility("default")));
+
 #endif
 #if IN_FILE(__GDK_DRAWABLE_X11_C__)
 #undef gdk_x11_drawable_get_xdisplay 
diff -ru gtk+-2.10.12/gdk/gdkalias.h gtk+-2.10.12-xdisplay/gdk/gdkalias.h
--- gtk+-2.10.12/gdk/gdkalias.h	2007-05-02 17:29:54.000000000 +0100
+++ gtk+-2.10.12-xdisplay/gdk/gdkalias.h	2007-05-29 15:20:28.000000000 +0100
@@ -2357,6 +2357,9 @@
 extern __typeof (gdk_x11_lookup_xdisplay) IA__gdk_x11_lookup_xdisplay __attribute((visibility("hidden")));
 #define gdk_x11_lookup_xdisplay IA__gdk_x11_lookup_xdisplay
 
+extern __typeof (gdk_x11_foreign_new_xdisplay) IA__gdk_x11_foreign_new_xdisplay __attribute((visibility("hidden")));
+#define gdk_x11_foreign_new_xdisplay IA__gdk_x11_foreign_new_xdisplay
+
 #endif
 #if IN_FILE(__GDK_DRAWABLE_X11_C__)
 extern __typeof (gdk_x11_drawable_get_xdisplay) IA__gdk_x11_drawable_get_xdisplay __attribute((visibility("hidden")));
diff -ru gtk+-2.10.12/gdk/x11/gdkdisplay-x11.c gtk+-2.10.12-xdisplay/gdk/x11/gdkdisplay-x11.c
--- gtk+-2.10.12/gdk/x11/gdkdisplay-x11.c	2007-05-02 17:27:36.000000000 +0100
+++ gtk+-2.10.12-xdisplay/gdk/x11/gdkdisplay-x11.c	2007-05-29 15:35:21.000000000 +0100
@@ -113,20 +113,13 @@
 {
 }
 
-/**
- * gdk_display_open:
- * @display_name: the name of the display to open
- * @returns: a #GdkDisplay, or %NULL if the display
- *  could not be opened.
- *
- * Opens a display.
- *
- * Since: 2.2
- */
-GdkDisplay *
-gdk_display_open (const gchar *display_name)
+/* Not to be used publicaly. Use foreign_new() or open().
+   Creates a GdkDisplay our of a XDisplay.
+   handle_display specifies if GDK should install event handlers
+   and proprities on the display. */
+static GdkDisplay *
+_gdk_display_new (Display *xdisplay, gboolean handle_display)
 {
-  Display *xdisplay;
   GdkDisplay *display;
   GdkDisplayX11 *display_x11;
   GdkWindowAttr attr;
@@ -142,10 +135,6 @@
   gint maj, min;
 #endif
 
-  xdisplay = XOpenDisplay (display_name);
-  if (!xdisplay)
-    return NULL;
-  
   display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
   display_x11 = GDK_DISPLAY_X11 (display);
 
@@ -341,6 +330,55 @@
   return display;
 }
 
+/**
+ * gdk_display_open:
+ * @display_name: the name of the display to open
+ * @returns: a #GdkDisplay, or %NULL if the display
+ *  could not be opened.
+ *
+ * Opens a display.
+ *
+ * Since: 2.2
+ */
+GdkDisplay *
+gdk_display_open (const gchar *display_name)
+{
+  Display *xdisplay;
+  GdkDisplay *display;
+  GdkDisplayX11 *display_x11;
+
+  xdisplay = XOpenDisplay (display_name);
+  display = _gdk_display_new (xdisplay, TRUE);
+
+  display_x11 = GDK_DISPLAY_X11 (display);
+  display_x11->is_foreign = FALSE;
+  return display;
+}
+
+/**
+ * gdk_x11_foreign_new_xdisplay:
+ * @xdisplay: the XDisplay to wrap.
+ * @handle_display: if GDK should handle the display. That is,
+ * install event handlers and proprities on it.
+ * @returns: a #GdkDisplay.
+ *
+ * Wraps the given XDisplay into a GdkDisplay.
+ *
+ * Since:
+ */
+GdkDisplay *
+gdk_x11_foreign_new_xdisplay (Display *xdisplay, gboolean handle_display)
+{
+  GdkDisplay *display;
+  GdkDisplayX11 *display_x11;
+
+  display = _gdk_display_new (xdisplay, handle_display);
+
+  display_x11 = GDK_DISPLAY_X11 (display);
+  display_x11->is_foreign = TRUE;
+  return display;
+}
+
 #ifdef HAVE_X11R6
 /*
  * XLib internal connection handling
@@ -798,7 +836,8 @@
   /* X ID hashtable */
   g_hash_table_destroy (display_x11->xid_ht);
 
-  XCloseDisplay (display_x11->xdisplay);
+  if (!display_x11->is_foreign)
+    XCloseDisplay (display_x11->xdisplay);
 
   G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
 }
diff -ru gtk+-2.10.12/gdk/x11/gdkdisplay-x11.h gtk+-2.10.12-xdisplay/gdk/x11/gdkdisplay-x11.h
--- gtk+-2.10.12/gdk/x11/gdkdisplay-x11.h	2007-05-02 17:27:36.000000000 +0100
+++ gtk+-2.10.12-xdisplay/gdk/x11/gdkdisplay-x11.h	2007-05-29 15:28:44.000000000 +0100
@@ -162,6 +162,10 @@
 
   /* Alpha mask picture format */
   XRenderPictFormat *mask_format;
+
+  /* When wrapping an already existing Display. Flags if
+     it is up to us to close the display or not. */
+  guint is_foreign : 1;
 };
 
 struct _GdkDisplayX11Class
@@ -173,6 +177,9 @@
 GdkScreen *_gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
 						 Window      xrootwin);
 
+GdkDisplay   *gdk_x11_foreign_new_xdisplay (Display *xdisplay,
+                                            gboolean handle_display);
+
 G_END_DECLS
 
 #endif				/* __GDK_DISPLAY_X11__ */
diff -ru gtk+-2.10.12/gdk/x11/gdkx.h gtk+-2.10.12-xdisplay/gdk/x11/gdkx.h
--- gtk+-2.10.12/gdk/x11/gdkx.h	2007-05-02 17:27:36.000000000 +0100
+++ gtk+-2.10.12-xdisplay/gdk/x11/gdkx.h	2007-05-29 15:46:33.000000000 +0100
@@ -159,6 +159,8 @@
 
 GdkDisplay   *gdk_x11_lookup_xdisplay (Display *xdisplay);
 
+GdkDisplay   *gdk_x11_foreign_new_xdisplay (Display *xdisplay,
+                                            gboolean handle_display);
 
 /* Functions to get the X Atom equivalent to the GdkAtom */
 Atom	              gdk_x11_atom_to_xatom_for_display (GdkDisplay  *display,
