diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
index 44abed2..9eb6516 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -250,9 +250,29 @@ gdk_screen_get_root_window (GdkScreen *screen)
 GdkColormap *
 gdk_screen_get_default_colormap (GdkScreen *screen)
 {
+  GdkScreenX11 *screen_x11;
+  GdkColormap *colormap;
+
   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
 
-  return GDK_SCREEN_X11 (screen)->default_colormap;
+  screen_x11 = GDK_SCREEN_X11 (screen);
+
+  if (!screen_x11->default_colormap)
+    {
+      if (!screen_x11->rgba_visual)
+        {
+          colormap = g_object_ref (gdk_screen_get_system_colormap (screen));
+        }
+      else
+        {
+          colormap = gdk_colormap_new (screen_x11->rgba_visual,
+                                       FALSE);
+        }
+
+      screen_x11->default_colormap = colormap;
+    }
+
+  return screen_x11->default_colormap;
 }
 
 /**
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index aff986a..17e3de3 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -430,9 +430,6 @@ _gdk_windowing_window_init (GdkScreen * screen)
 
   g_assert (screen_x11->root_window == NULL);
 
-  gdk_screen_set_default_colormap (screen,
-				   gdk_screen_get_system_colormap (screen));
-
   screen_x11->root_window = g_object_new (GDK_TYPE_WINDOW, NULL);
 
   private = (GdkWindowObject *) screen_x11->root_window;
@@ -679,7 +676,8 @@ _gdk_window_impl_new (GdkWindow     *window,
   
   unsigned int class;
   const char *title;
-  
+  gint error;
+
   private = (GdkWindowObject *) window;
   
   screen_x11 = GDK_SCREEN_X11 (screen);
@@ -791,13 +789,38 @@ _gdk_window_impl_new (GdkWindow     *window,
       if (private->height > 65535)
 	private->height = 65535;
     }
-  
+
+  xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
+
+  gdk_error_trap_push ();
   xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
 					private->x + private->parent->abs_x,
 					private->y + private->parent->abs_y,
 					private->width, private->height,
 					0, private->depth, class, xvisual,
 					xattributes_mask, &xattributes);
+  gdk_flush ();
+  error = gdk_error_trap_pop ();
+  if (error == BadMatch)
+    {
+      g_warning ("BadMatch detected when creating window, attempting to revert to system visual and colormap.  To avoid this, try setting the widget's colormap to the default colormap for this screen.");
+
+      g_object_unref (draw_impl->colormap);
+      draw_impl->colormap = gdk_screen_get_system_colormap (screen);
+      g_object_ref (draw_impl->colormap);
+
+      visual = gdk_screen_get_system_visual (screen);
+      xvisual = ((GdkVisualPrivate*) visual)->xvisual;
+
+      xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap);
+
+      xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
+                                            private->x + private->parent->abs_x,
+                                            private->y + private->parent->abs_y,
+                                            private->width, private->height,
+                                            0, private->depth, class, xvisual,
+                                            xattributes_mask, &xattributes);
+    }
 
   g_object_ref (window);
   _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
@@ -3394,6 +3417,7 @@ do_shape_combine_region (GdkWindow       *window,
 	  _gdk_x11_window_tmp_unset_parent_bg (window);
 	  _gdk_x11_window_tmp_unset_bg (window, TRUE);
 	}
+
       XShapeCombineRectangles (GDK_WINDOW_XDISPLAY (window),
                                GDK_WINDOW_XID (window),
                                shape,
