--- src/compositor.c.orig	2005-06-28 23:40:21.000000000 +0100
+++ src/compositor.c	2005-07-15 18:54:16.000000000 +0100
@@ -27,6 +27,8 @@
 #include "window.h"
 #include "frame.h"
 
+#include <string.h>
+
 #ifdef HAVE_COMPOSITE_EXTENSIONS
 #include <X11/extensions/Xcomposite.h>
 #include <X11/extensions/Xdamage.h>
@@ -105,6 +107,12 @@
 #endif
 };
 
+static char *background_props[] = {
+    "_XROOTPMAP_ID",
+    "_XSETROOT_ID",
+    0,
+};
+
 #ifdef HAVE_COMPOSITE_EXTENSIONS
 static void
 meta_compositor_window_free (MetaCompositorWindow *cwindow)
@@ -310,13 +318,69 @@
     }
 }
 
+#ifdef HAVE_COMPOSITE_EXTENSIONS
+static Picture
+get_root_tile (Display *dpy, MetaScreen *screen)
+{
+  Picture picture;
+  Atom actual_type;
+  Pixmap pixmap;
+  int actual_format;
+  unsigned long nitems;
+  unsigned long bytes_after;
+  unsigned char *prop;
+  Bool fill;
+  XRenderPictureAttributes pa;
+  int p;
+
+  pixmap = None;
+  for (p = 0; background_props[p]; p++)
+    {
+      if (XGetWindowProperty (dpy, screen->xroot, XInternAtom (dpy, background_props[p], False),
+            0, 4, False, AnyPropertyType,
+            &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success &&
+          actual_type == XInternAtom (dpy, "PIXMAP", False) && actual_format == 32 && nitems == 1)
+        {
+           memcpy (&pixmap, prop, 4);
+           XFree (prop);
+           fill = False;
+           break;
+        }
+    }
+
+  if (!pixmap)
+    {
+      pixmap = XCreatePixmap (dpy, screen->xroot, 1, 1, DefaultDepth (dpy, screen->number));
+      fill = True;
+    }
+
+  pa.repeat = True;
+  picture = XRenderCreatePicture (dpy, pixmap,
+      XRenderFindVisualFormat (dpy,
+        DefaultVisual (dpy, screen->number)),
+      CPRepeat, &pa);
+
+  if (fill)
+    {
+      XRenderColor    c;
+
+      c.red = c.green = c.blue = 0x8080;
+      c.alpha = 0xffff;
+      XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 
+          0, 0, 1, 1);
+    }
+
+  return picture;
+}
+#endif /* HAVE_COMPOSITE_EXTENSIONS */
+
+
 static void
 paint_screen (MetaCompositor *compositor,
               MetaScreen     *screen,
               XserverRegion   damage_region)
 {
   XserverRegion region;
-  Picture buffer_picture;
   Pixmap buffer_pixmap;
   Display *xdisplay;
   XRenderPictFormat *format;
@@ -350,32 +414,47 @@
                         damage_region);
     }
 
-  buffer_pixmap = XCreatePixmap (xdisplay, screen->xroot,
-                                 screen->width,
-                                 screen->height,
-                                 DefaultDepth (xdisplay,
-                                               screen->number));
-
-  gc = XCreateGC (xdisplay, buffer_pixmap, 0, NULL);
-  XSetForeground (xdisplay, gc, WhitePixel (xdisplay, screen->number));
-  XFixesSetGCClipRegion (xdisplay, gc, 0, 0, region);
-  XFillRectangle (xdisplay, buffer_pixmap, gc, 0, 0,
-                  screen->width, screen->height);
-  
-  format = XRenderFindVisualFormat (xdisplay,
-                                    DefaultVisual (xdisplay,
+  if (screen->buffer_picture == None)
+    {
+      buffer_pixmap = XCreatePixmap (xdisplay, screen->xroot,
+                                     screen->width,
+                                     screen->height,
+                                     DefaultDepth (xdisplay,
                                                    screen->number));
-  
-  buffer_picture = XRenderCreatePicture (xdisplay,
-                                         buffer_pixmap,
-                                         format,
-                                         0, 0);
+
+      gc = XCreateGC (xdisplay, buffer_pixmap, 0, NULL);
+      XSetForeground (xdisplay, gc, WhitePixel (xdisplay, screen->number));
+      XFixesSetGCClipRegion (xdisplay, gc, 0, 0, region);
+      XFillRectangle (xdisplay, buffer_pixmap, gc, 0, 0,
+                      screen->width, screen->height);
+      
+      format = XRenderFindVisualFormat (xdisplay,
+                                        DefaultVisual (xdisplay,
+                                                       screen->number));
+      
+      screen->buffer_picture = XRenderCreatePicture (xdisplay,
+                                             buffer_pixmap,
+                                             format,
+                                             0, 0);
+      
+      XFreePixmap (xdisplay, buffer_pixmap);
+      XFreeGC (xdisplay, gc);
+    }
 
   /* set clip */          
   XFixesSetPictureClipRegion (xdisplay,
-                              buffer_picture, 0, 0,
+                              screen->buffer_picture, 0, 0,
                               region);
 
+  if (screen->root_tile == None)
+    screen->root_tile = get_root_tile (compositor->display->xdisplay, screen);
+
+  XRenderComposite (compositor->display->xdisplay,
+                    PictOpSrc,
+                    screen->root_tile, None, screen->buffer_picture,
+                    0, 0, 0, 0,
+                    0, 0, screen->width, screen->height);
+
   /* draw windows from bottom to top */
   
   meta_error_trap_push (compositor->display);
@@ -427,7 +506,7 @@
                             PictOpOver, /* PictOpOver for alpha, PictOpSrc without */
                             cwindow->picture,
                             screen->trans_picture,
-                            buffer_picture,
+                            screen->buffer_picture,
                             0, 0, 0, 0,
                             x, y, w, h);
         }
@@ -440,7 +519,7 @@
           
           /* superlame drop shadow */
           XRenderFillRectangle (xdisplay, PictOpOver,
-                                buffer_picture,
+                                screen->buffer_picture,
                                 &shadow_color,
                                 cwindow->x + SHADOW_OFFSET,
                                 cwindow->y + SHADOW_OFFSET,
@@ -450,7 +529,7 @@
                             PictOpSrc, /* PictOpOver for alpha, PictOpSrc without */
                             cwindow->picture,
                             None,
-                            buffer_picture,
+                            screen->buffer_picture,
                             0, 0, 0, 0,
                             x, y, w, h);
         }
@@ -470,16 +549,13 @@
                               0, 0, region);
 #endif
   
-  /* XFixesSetPictureClipRegion (xdisplay, buffer_picture, 0, 0, None); */
-  XRenderComposite (xdisplay, PictOpSrc, buffer_picture, None,
+  /* XFixesSetPictureClipRegion (xdisplay, screen->buffer_picture, 0, 0, None); */
+  XRenderComposite (xdisplay, PictOpSrc, screen->buffer_picture, None,
                     screen->root_picture,
                     0, 0, 0, 0, 0, 0,
                     screen->width, screen->height);
   
   XFixesDestroyRegion (xdisplay, region);
-  XFreePixmap (xdisplay, buffer_pixmap);
-  XRenderFreePicture (xdisplay, buffer_picture);
-  XFreeGC (xdisplay, gc);
 
   /* meta_display_ungrab (screen->display); */
 
@@ -671,13 +747,32 @@
   MetaCompositorWindow *cwindow;
   MetaScreen *screen;
   GList *link;
+  GSList *tmp;
   Window above;
   XserverRegion region;
   
   cwindow = g_hash_table_lookup (compositor->window_hash,
                                  &event->window);
   if (cwindow == NULL)
-    return;
+    {
+      tmp = compositor->display->screens;
+      while (tmp != NULL)
+        {
+          screen = tmp->data;
+          if (event->window == screen->xroot)
+            {
+              if (screen->buffer_picture != None)
+                {
+                   XRenderFreePicture (compositor->display->xdisplay,
+                                       screen->buffer_picture);
+                   screen->buffer_picture = None;
+                }
+              return;
+            }
+          tmp = tmp->next;
+        }
+      return;
+    }
 
   screen = meta_compositor_window_get_screen (cwindow);
 
@@ -942,6 +1037,37 @@
 }
 #endif /* HAVE_COMPOSITE_EXTENSIONS */
 
+#ifdef HAVE_COMPOSITE_EXTENSIONS
+static void
+process_property (MetaCompositor      *compositor,
+                  XPropertyEvent      *event)
+
+{
+  MetaScreen *screen;
+  int p;
+
+  screen = meta_display_screen_for_root (compositor->display,
+                                         event->window);
+  if (!screen)
+    return;
+
+  if (screen->root_tile)
+    {
+      for (p = 0; background_props[p]; p++)
+        {
+          if (event->atom == XInternAtom (compositor->display->xdisplay,
+                                          background_props[p], False))
+            {
+              XClearArea (compositor->display->xdisplay, screen->xroot, 0, 0, 0, 0, True);
+              XRenderFreePicture (compositor->display->xdisplay, screen->root_tile);
+              screen->root_tile = None;
+              break;
+            }
+        }
+    }
+}
+#endif /* HAVE_COMPOSITE_EXTENSIONS */
+
 
 #ifdef HAVE_COMPOSITE_EXTENSIONS
 static void
@@ -1067,6 +1193,11 @@
       process_destroy (compositor,
                        (XDestroyWindowEvent*) event);
     }
+  else if (event->type == PropertyNotify)
+    {
+      process_property (compositor,
+                        (XPropertyEvent *) event);
+    }
   
 #endif /* HAVE_COMPOSITE_EXTENSIONS */
 }
--- src/screen.c.orig	2005-02-28 21:30:10.000000000 +0000
+++ src/screen.c	2005-07-15 18:39:01.000000000 +0100
@@ -544,6 +544,8 @@
   screen->root_picture = None;
   screen->trans_pixmap = None;
   screen->trans_picture = None;
+  screen->buffer_picture = None;
+  screen->root_tile = None;
   
   {
     XGCValues gc_values;
--- src/screen.h.orig	2005-01-17 20:25:09.000000000 +0000
+++ src/screen.h	2005-07-15 18:39:14.000000000 +0100
@@ -120,6 +120,8 @@
   XID damage_region;
   XID trans_pixmap;
   XID trans_picture;
+  XID buffer_picture;
+  XID root_tile;
 };
 
 MetaScreen*   meta_screen_new                 (MetaDisplay                *display,
