[gnome-desktop] gnome-bg: Update for GTK3 changes



commit 28f2b06f50e3f1adf19389c2c3a1f63872539fa9
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 30 16:17:28 2010 +0200

    gnome-bg: Update for GTK3 changes
    
    Includes a renaming of all "pixmap" anems in APIs to "surface", because
    that's what they actually use.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=630724

 libgnome-desktop/gnome-bg-crossfade.c            |  184 ++++++++++++----------
 libgnome-desktop/gnome-bg.c                      |  189 ++++++++++++----------
 libgnome-desktop/libgnomeui/gnome-bg-crossfade.h |   10 +-
 libgnome-desktop/libgnomeui/gnome-bg.h           |   16 +-
 4 files changed, 213 insertions(+), 186 deletions(-)
---
diff --git a/libgnome-desktop/gnome-bg-crossfade.c b/libgnome-desktop/gnome-bg-crossfade.c
index d57fea6..2c4d351 100644
--- a/libgnome-desktop/gnome-bg-crossfade.c
+++ b/libgnome-desktop/gnome-bg-crossfade.c
@@ -1,4 +1,4 @@
-/* gnome-bg-crossfade.h - fade window background between two pixmaps
+/* gnome-bg-crossfade.h - fade window background between two surfaces
  *
  * Copyright (C) 2008 Red Hat, Inc.
  *
@@ -41,15 +41,15 @@
 
 struct _GnomeBGCrossfadePrivate
 {
-	GdkWindow *window;
-	int        width;
-	int        height;
-	GdkPixmap *fading_pixmap;
-	GdkPixmap *end_pixmap;
-	gdouble    start_time;
-	gdouble    total_duration;
-	guint      timeout_id;
-	guint      is_first_frame : 1;
+	GdkWindow       *window;
+	int              width;
+	int              height;
+	cairo_surface_t *fading_surface;
+	cairo_surface_t *end_surface;
+	gdouble          start_time;
+	gdouble          total_duration;
+	guint            timeout_id;
+	guint            is_first_frame : 1;
 };
 
 enum {
@@ -132,14 +132,14 @@ gnome_bg_crossfade_finalize (GObject *object)
 
 	gnome_bg_crossfade_stop (fade);
 
-	if (fade->priv->fading_pixmap != NULL) {
-		g_object_unref (fade->priv->fading_pixmap);
-		fade->priv->fading_pixmap = NULL;
+	if (fade->priv->fading_surface != NULL) {
+		cairo_surface_destroy (fade->priv->fading_surface);
+		fade->priv->fading_surface = NULL;
 	}
 
-	if (fade->priv->end_pixmap != NULL) {
-		g_object_unref (fade->priv->end_pixmap);
-		fade->priv->end_pixmap = NULL;
+	if (fade->priv->end_surface != NULL) {
+		g_object_unref (fade->priv->end_surface);
+		fade->priv->end_surface = NULL;
 	}
 }
 
@@ -158,7 +158,7 @@ gnome_bg_crossfade_class_init (GnomeBGCrossfadeClass *fade_class)
 	 * GnomeBGCrossfade:width:
 	 *
 	 * When a crossfade is running, this is width of the fading
-	 * pixmap.
+	 * surface.
 	 */
 	g_object_class_install_property (gobject_class,
 					 PROP_WIDTH,
@@ -172,7 +172,7 @@ gnome_bg_crossfade_class_init (GnomeBGCrossfadeClass *fade_class)
 	 * GnomeBGCrossfade:height:
 	 *
 	 * When a crossfade is running, this is height of the fading
-	 * pixmap.
+	 * surface.
 	 */
 	g_object_class_install_property (gobject_class,
 					 PROP_HEIGHT,
@@ -187,7 +187,7 @@ gnome_bg_crossfade_class_init (GnomeBGCrossfadeClass *fade_class)
 	 * @window: the #GdkWindow the crossfade happend on.
 	 *
 	 * When a crossfade finishes, @window will have a copy
-	 * of the end pixmap as its background, and this signal will
+	 * of the end surface as its background, and this signal will
 	 * get emitted.
 	 */
 	signals[FINISHED] = g_signal_new ("finished",
@@ -204,8 +204,8 @@ gnome_bg_crossfade_init (GnomeBGCrossfade *fade)
 {
 	fade->priv = GNOME_BG_CROSSFADE_GET_PRIVATE (fade);
 
-	fade->priv->fading_pixmap = NULL;
-	fade->priv->end_pixmap = NULL;
+	fade->priv->fading_surface = NULL;
+	fade->priv->end_surface = NULL;
 	fade->priv->timeout_id = 0;
 }
 
@@ -215,7 +215,7 @@ gnome_bg_crossfade_init (GnomeBGCrossfade *fade)
  * @height: The height of the crossfading window
  *
  * Creates a new object to manage crossfading a
- * window background between two #GdkPixmap drawables.
+ * window background between two #cairo_surface_ts.
  *
  * Return value: the new #GnomeBGCrossfade
  **/
@@ -232,21 +232,29 @@ gnome_bg_crossfade_new (int width,
 	return (GnomeBGCrossfade *) object;
 }
 
-static GdkPixmap *
-tile_pixmap (GdkPixmap *pixmap,
-	     int        width,
-	     int        height)
+static cairo_surface_t *
+tile_surface (cairo_surface_t *surface,
+	      int              width,
+	      int              height)
 {
-	GdkPixmap *copy;
+	cairo_surface_t *copy;
 	cairo_t *cr;
 
-	copy = gdk_pixmap_new (pixmap, width, height, pixmap == NULL? 24 : -1);
+        if (surface == NULL) {
+                copy = gdk_window_create_similar_surface (gdk_get_default_root_window (),
+                                                          CAIRO_CONTENT_COLOR,
+                                                          width, height);
+        } else {
+                copy = cairo_surface_create_similar (surface,
+                                                     cairo_surface_get_content (surface),
+                                                     width, height);
+        }
 
-	cr = gdk_cairo_create (copy);
+	cr = cairo_create (copy);
 
-	if (pixmap != NULL) {
+	if (surface != NULL) {
 		cairo_pattern_t *pattern;
-		gdk_cairo_set_source_pixmap (cr, pixmap, 0.0, 0.0);
+		cairo_set_source_surface (cr, surface, 0.0, 0.0);
 		pattern = cairo_get_source (cr);
 		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
 	} else {
@@ -258,7 +266,7 @@ tile_pixmap (GdkPixmap *pixmap,
 	cairo_paint (cr);
 
 	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
-		g_object_unref (copy);
+		cairo_surface_destroy (copy);
 		copy = NULL;
 	}
 	cairo_destroy (cr);
@@ -267,33 +275,33 @@ tile_pixmap (GdkPixmap *pixmap,
 }
 
 /**
- * gnome_bg_crossfade_set_start_pixmap:
+ * gnome_bg_crossfade_set_start_surface:
  * @fade: a #GnomeBGCrossfade
- * @pixmap: The #GdkPixmap to fade from
+ * @surface: The cairo surface to fade from
  *
  * Before initiating a crossfade with gnome_bg_crossfade_start()
- * a start and end pixmap have to be set.  This function sets
- * the pixmap shown at the beginning of the crossfade effect.
+ * a start and end surface have to be set.  This function sets
+ * the surface shown at the beginning of the crossfade effect.
  *
- * Return value: %TRUE if successful, or %FALSE if the pixmap
+ * Return value: %TRUE if successful, or %FALSE if the surface
  * could not be copied.
  **/
 gboolean
-gnome_bg_crossfade_set_start_pixmap (GnomeBGCrossfade *fade,
-				     GdkPixmap        *pixmap)
+gnome_bg_crossfade_set_start_surface (GnomeBGCrossfade *fade,
+				      cairo_surface_t  *surface)
 {
 	g_return_val_if_fail (GNOME_IS_BG_CROSSFADE (fade), FALSE);
 
-	if (fade->priv->fading_pixmap != NULL) {
-		g_object_unref (fade->priv->fading_pixmap);
-		fade->priv->fading_pixmap = NULL;
+	if (fade->priv->fading_surface != NULL) {
+		cairo_surface_destroy (fade->priv->fading_surface);
+		fade->priv->fading_surface = NULL;
 	}
 
-	fade->priv->fading_pixmap = tile_pixmap (pixmap,
-						 fade->priv->width,
-						 fade->priv->height);
+	fade->priv->fading_surface = tile_surface (surface,
+						   fade->priv->width,
+						   fade->priv->height);
 
-	return fade->priv->fading_pixmap != NULL;
+	return fade->priv->fading_surface != NULL;
 }
 
 static gdouble
@@ -312,36 +320,36 @@ get_current_time (void)
 }
 
 /**
- * gnome_bg_crossfade_set_end_pixmap:
+ * gnome_bg_crossfade_set_end_surface:
  * @fade: a #GnomeBGCrossfade
- * @pixmap: The #GdkPixmap to fade to
+ * @surface: The cairo surface to fade to
  *
  * Before initiating a crossfade with gnome_bg_crossfade_start()
- * a start and end pixmap have to be set.  This function sets
- * the pixmap shown at the end of the crossfade effect.
+ * a start and end surface have to be set.  This function sets
+ * the surface shown at the end of the crossfade effect.
  *
- * Return value: %TRUE if successful, or %FALSE if the pixmap
+ * Return value: %TRUE if successful, or %FALSE if the surface
  * could not be copied.
  **/
 gboolean
-gnome_bg_crossfade_set_end_pixmap (GnomeBGCrossfade *fade,
-				   GdkPixmap        *pixmap)
+gnome_bg_crossfade_set_end_surface (GnomeBGCrossfade *fade,
+				    cairo_surface_t  *surface)
 {
 	g_return_val_if_fail (GNOME_IS_BG_CROSSFADE (fade), FALSE);
 
-	if (fade->priv->end_pixmap != NULL) {
-		g_object_unref (fade->priv->end_pixmap);
-		fade->priv->end_pixmap = NULL;
+	if (fade->priv->end_surface != NULL) {
+		cairo_surface_destroy (fade->priv->end_surface);
+		fade->priv->end_surface = NULL;
 	}
 
-	fade->priv->end_pixmap = tile_pixmap (pixmap,
-					      fade->priv->width,
-					      fade->priv->height);
+	fade->priv->end_surface = tile_surface (surface,
+					        fade->priv->width,
+					        fade->priv->height);
 
 	/* Reset timer in case we're called while animating
 	 */
 	fade->priv->start_time = get_current_time ();
-	return fade->priv->end_pixmap != NULL;
+	return fade->priv->end_surface != NULL;
 }
 
 static gboolean
@@ -353,7 +361,7 @@ animations_are_disabled (GnomeBGCrossfade *fade)
 
 	g_assert (fade->priv->window != NULL);
 
-	screen = gdk_drawable_get_screen (fade->priv->window);
+	screen = gdk_window_get_screen (fade->priv->window);
 
 	settings = gtk_settings_get_for_screen (screen);
 
@@ -366,9 +374,12 @@ static void
 draw_background (GnomeBGCrossfade *fade)
 {
 	if (GDK_WINDOW_TYPE (fade->priv->window) == GDK_WINDOW_ROOT) {
-		GdkDisplay *display;
-		display = gdk_drawable_get_display (fade->priv->window);
-		gdk_window_clear (fade->priv->window);
+                XClearArea (GDK_WINDOW_XDISPLAY (fade->priv->window),
+                            GDK_WINDOW_XID (fade->priv->window),
+                            0, 0,
+                            gdk_window_get_width (fade->priv->window),
+                            gdk_window_get_height (fade->priv->window),
+                            False);
 		gdk_flush ();
 	} else {
 		gdk_window_invalidate_rect (fade->priv->window, NULL, FALSE);
@@ -400,7 +411,7 @@ on_tick (GnomeBGCrossfade *fade)
 		return on_tick (fade);
 	}
 
-	if (fade->priv->fading_pixmap == NULL) {
+	if (fade->priv->fading_surface == NULL) {
 		return FALSE;
 	}
 
@@ -416,10 +427,10 @@ on_tick (GnomeBGCrossfade *fade)
 	 * even the fastest machines will get *some* fade because the framerate
 	 * is capped.
 	 */
-	cr = gdk_cairo_create (fade->priv->fading_pixmap);
+	cr = cairo_create (fade->priv->fading_surface);
 
-	gdk_cairo_set_source_pixmap (cr, fade->priv->end_pixmap,
-				     0.0, 0.0);
+	cairo_set_source_surface (cr, fade->priv->end_surface,
+				  0.0, 0.0);
 	cairo_paint_with_alpha (cr, percent_done);
 
 	status = cairo_status (cr);
@@ -434,23 +445,26 @@ on_tick (GnomeBGCrossfade *fade)
 static void
 on_finished (GnomeBGCrossfade *fade)
 {
+        cairo_pattern_t *pattern;
+
 	if (fade->priv->timeout_id == 0)
 		return;
 
-	g_assert (fade->priv->end_pixmap != NULL);
+	g_assert (fade->priv->end_surface != NULL);
+
+        pattern = cairo_pattern_create_for_surface (fade->priv->end_surface);
+	gdk_window_set_background_pattern (fade->priv->window, pattern);
+        cairo_pattern_destroy (pattern);
 
-	gdk_window_set_back_pixmap (fade->priv->window,
-				    fade->priv->end_pixmap,
-				    FALSE);
 	draw_background (fade);
 
-	g_object_unref (fade->priv->end_pixmap);
-	fade->priv->end_pixmap = NULL;
+	cairo_surface_destroy (fade->priv->end_surface);
+	fade->priv->end_surface = NULL;
 
-	g_assert (fade->priv->fading_pixmap != NULL);
+	g_assert (fade->priv->fading_surface != NULL);
 
-	g_object_unref (fade->priv->fading_pixmap);
-	fade->priv->fading_pixmap = NULL;
+	cairo_surface_destroy (fade->priv->fading_surface);
+	fade->priv->fading_surface = NULL;
 
 	fade->priv->timeout_id = 0;
 	g_signal_emit (fade, signals[FINISHED], 0, fade->priv->window);
@@ -461,11 +475,11 @@ on_finished (GnomeBGCrossfade *fade)
  * @fade: a #GnomeBGCrossfade
  * @window: The #GdkWindow to draw crossfade on
  *
- * This function initiates a quick crossfade between two pixmaps on
+ * This function initiates a quick crossfade between two surfaces on
  * the background of @window.  Before initiating the crossfade both
  * gnome_bg_crossfade_start() and gnome_bg_crossfade_end() need to
  * be called. If animations are disabled, the crossfade is skipped,
- * and the window background is set immediately to the end pixmap.
+ * and the window background is set immediately to the end surface.
  **/
 void
 gnome_bg_crossfade_start (GnomeBGCrossfade *fade,
@@ -473,11 +487,12 @@ gnome_bg_crossfade_start (GnomeBGCrossfade *fade,
 {
 	GSource *source;
 	GMainContext *context;
+        cairo_pattern_t *pattern;
 
 	g_return_if_fail (GNOME_IS_BG_CROSSFADE (fade));
 	g_return_if_fail (window != NULL);
-	g_return_if_fail (fade->priv->fading_pixmap != NULL);
-	g_return_if_fail (fade->priv->end_pixmap != NULL);
+	g_return_if_fail (fade->priv->fading_surface != NULL);
+	g_return_if_fail (fade->priv->end_surface != NULL);
 	g_return_if_fail (!gnome_bg_crossfade_is_started (fade));
 	g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN);
 
@@ -491,9 +506,10 @@ gnome_bg_crossfade_start (GnomeBGCrossfade *fade,
 	g_source_unref (source);
 
 	fade->priv->window = window;
-	gdk_window_set_back_pixmap (fade->priv->window,
-				    fade->priv->fading_pixmap,
-				    FALSE);
+        pattern = cairo_pattern_create_for_surface (fade->priv->fading_surface);
+	gdk_window_set_background_pattern (fade->priv->window, pattern);
+        cairo_pattern_destroy (pattern);
+
 	draw_background (fade);
 
 	fade->priv->is_first_frame = TRUE;
diff --git a/libgnome-desktop/gnome-bg.c b/libgnome-desktop/gnome-bg.c
index 47493d2..8364052 100644
--- a/libgnome-desktop/gnome-bg.c
+++ b/libgnome-desktop/gnome-bg.c
@@ -39,6 +39,7 @@ Author: Soren Sandmann <sandmann redhat com>
 #include <X11/Xatom.h>
 
 #include <cairo.h>
+#include <cairo-xlib.h>
 
 #include <gconf/gconf-client.h>
 
@@ -132,9 +133,9 @@ static guint signals[N_SIGNALS] = { 0 };
 
 G_DEFINE_TYPE (GnomeBG, gnome_bg, G_TYPE_OBJECT)
 
-static GdkPixmap *make_root_pixmap     (GdkScreen  *screen,
-					gint        width,
-					gint        height);
+static cairo_surface_t *make_root_pixmap     (GdkScreen  *screen,
+                                              gint        width,
+                                              gint        height);
 
 /* Pixbuf utils */
 static guint32    pixbuf_average_value (GdkPixbuf  *pixbuf);
@@ -958,28 +959,27 @@ gnome_bg_get_pixmap_size (GnomeBG   *bg,
 }
 
 /**
- * gnome_bg_get_pixmap:
+ * gnome_bg_create_surface:
  * @bg: GnomeBG 
  * @window: 
  * @width: 
  * @height:
+ * @is_root:
  *
- * Create a pixmap that can be set as background for @window. If @root is TRUE,
- * the pixmap created will be created by a temporary X server connection so
- * that if someone calls XKillClient on it, it won't affect the application who
- * created it.
- *
- * Since: 2.20
+ * Create a surface that can be set as background for @window. If @is_root is
+ * TRUE, the surface created will be created by a temporary X server connection
+ * so that if someone calls XKillClient on it, it won't affect the application
+ * who created it.
  **/
-GdkPixmap *
-gnome_bg_create_pixmap (GnomeBG	    *bg,
-			GdkWindow   *window,
-			int	     width,
-			int	     height,
-			gboolean     is_root)
+cairo_surface_t *
+gnome_bg_create_surface (GnomeBG	    *bg,
+		 	 GdkWindow   *window,
+			 int	     width,
+			 int	     height,
+			 gboolean     is_root)
 {
 	int pm_width, pm_height;
-	GdkPixmap *pixmap;
+	cairo_surface_t *surface;
 	cairo_t *cr;
 	
 	g_return_val_if_fail (bg != NULL, NULL);
@@ -999,14 +999,16 @@ gnome_bg_create_pixmap (GnomeBG	    *bg,
 	gnome_bg_get_pixmap_size (bg, width, height, &pm_width, &pm_height);
 	
 	if (is_root) {
-		pixmap = make_root_pixmap (gdk_drawable_get_screen (window),
+		surface = make_root_pixmap (gdk_window_get_screen (window),
 					   pm_width, pm_height);
 	}
 	else {
-		pixmap = gdk_pixmap_new (window, pm_width, pm_height, -1);
+		surface = gdk_window_create_similar_surface (window,
+                                                             CAIRO_CONTENT_COLOR,
+                                                             pm_width, pm_height);
 	}
 	
-	cr = gdk_cairo_create (pixmap);
+	cr = cairo_create (surface);
 	if (!bg->filename && bg->color_type == GNOME_BG_COLOR_SOLID) {
 		gdk_cairo_set_source_color (cr, &(bg->primary));
 	}
@@ -1015,7 +1017,7 @@ gnome_bg_create_pixmap (GnomeBG	    *bg,
 		
 		pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
 					 width, height);
-		gnome_bg_draw (bg, pixbuf, gdk_drawable_get_screen (GDK_DRAWABLE (window)), is_root);
+		gnome_bg_draw (bg, pixbuf, gdk_window_get_screen (GDK_DRAWABLE (window)), is_root);
 		gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
 		g_object_unref (pixbuf);
 	}
@@ -1024,7 +1026,7 @@ gnome_bg_create_pixmap (GnomeBG	    *bg,
 	
 	cairo_destroy (cr);
 
-	return pixmap;
+	return surface;
 }
 
 
@@ -1074,13 +1076,13 @@ gnome_bg_is_dark (GnomeBG *bg,
  * Create a persistent pixmap. We create a separate display
  * and set the closedown mode on it to RetainPermanent.
  */
-static GdkPixmap *
+static cairo_surface_t *
 make_root_pixmap (GdkScreen *screen, gint width, gint height)
 {
 	Display *display;
         const char *display_name;
 	Pixmap result;
-	GdkPixmap *gdk_pixmap;
+        cairo_surface_t *surface;
 	int screen_num;
 	int depth;
 	
@@ -1113,14 +1115,12 @@ make_root_pixmap (GdkScreen *screen, gint width, gint height)
 	
 	XCloseDisplay (display);
 	
-	gdk_pixmap = gdk_pixmap_foreign_new_for_screen (screen, result,
-							width, height, depth);
+	surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen),
+                                             result,
+                                             GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)),
+					     width, height);
 
-	gdk_drawable_set_colormap (
-		GDK_DRAWABLE (gdk_pixmap),
-		gdk_drawable_get_colormap (gdk_screen_get_root_window (screen)));
-	
-	return gdk_pixmap;
+	return surface;
 }
 
 static gboolean
@@ -1228,19 +1228,19 @@ gnome_bg_create_thumbnail (GnomeBG               *bg,
 }
 
 /**
- * gnome_bg_get_pixmap_from_root:
+ * gnome_bg_get_surface_from_root:
  * @screen: a #GdkScreen
  *
  * This function queries the _XROOTPMAP_ID property from
  * the root window associated with @screen to determine
  * the current root window background pixmap and returns
  * a copy of it. If the _XROOTPMAP_ID is not set, then
- * a black pixmap is returned.
+ * a black surface is returned.
  *
- * Return value: a #GdkPixmap if successful or %NULL
+ * Return value: a #cairo_surface_t if successful or %NULL
  **/
-GdkPixmap *
-gnome_bg_get_pixmap_from_root (GdkScreen *screen)
+cairo_surface_t *
+gnome_bg_get_surface_from_root (GdkScreen *screen)
 {
 	int result;
 	gint format;
@@ -1250,11 +1250,10 @@ gnome_bg_get_pixmap_from_root (GdkScreen *screen)
 	Atom type;
 	Display *display;
 	int screen_num;
-	GdkPixmap *pixmap;
-	GdkPixmap *source_pixmap;
+	cairo_surface_t *surface;
+	cairo_surface_t *source_pixmap;
 	int width, height;
 	cairo_t *cr;
-	cairo_pattern_t *pattern;
 
 	display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
 	screen_num = gdk_screen_get_number (screen);
@@ -1265,7 +1264,7 @@ gnome_bg_get_pixmap_from_root (GdkScreen *screen)
 				     0L, 1L, False, XA_PIXMAP,
 				     &type, &format, &nitems, &bytes_after,
 				     &data);
-	pixmap = NULL;
+	surface = NULL;
 	source_pixmap = NULL;
 
 	if (result != Success || type != XA_PIXMAP ||
@@ -1275,51 +1274,63 @@ gnome_bg_get_pixmap_from_root (GdkScreen *screen)
 	}
 
 	if (data != NULL) {
+                Pixmap xpixmap = *(Pixmap *) data;
+                Window root_return;
+                int x_ret, y_ret;
+                unsigned int w_ret, h_ret, bw_ret, depth_ret;
+
 		gdk_error_trap_push ();
-		source_pixmap = gdk_pixmap_foreign_new (*(Pixmap *) data);
-		gdk_error_trap_pop ();
+                if (XGetGeometry (GDK_SCREEN_XDISPLAY (screen),
+                                  xpixmap,
+                                  &root_return,
+                                  &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret)) {
+                        source_pixmap = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen),
+                                                                   xpixmap,
+                                                                   GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (screen)),
+                                                                   w_ret, h_ret);
+                }
 
-		if (source_pixmap != NULL) {
-			gdk_drawable_set_colormap (source_pixmap,
-						   gdk_screen_get_default_colormap (screen));
-		}
+		gdk_error_trap_pop ();
 	}
 
 	width = gdk_screen_get_width (screen);
 	height = gdk_screen_get_height (screen);
 
-	pixmap = gdk_pixmap_new (source_pixmap != NULL? source_pixmap :
-				 gdk_screen_get_root_window (screen),
-				 width, height, -1);
+        if (source_pixmap) {
+                surface = cairo_surface_create_similar (source_pixmap,
+                                                        CAIRO_CONTENT_COLOR,
+                                                        width, height);
 
-	cr = gdk_cairo_create (pixmap);
-	if (source_pixmap != NULL) {
-		gdk_cairo_set_source_pixmap (cr, source_pixmap, 0, 0);
-		pattern = cairo_get_source (cr);
-		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
-	} else {
-		cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
-	}
-	cairo_paint (cr);
+                cr = cairo_create (surface);
+                cairo_set_source_surface (cr, source_pixmap, 0, 0);
+                cairo_paint (cr);
 
-	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
-		g_object_unref (pixmap);
-		pixmap = NULL;
-	}
-	cairo_destroy (cr);
+                if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
+                        cairo_surface_destroy (surface);
+                        surface = NULL;
+                }
+
+                cairo_destroy (cr);
+        }
+
+        if (surface == NULL) {
+	        surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
+                                                             CAIRO_CONTENT_COLOR,
+                                                             width, height);
+        }
 
 	if (source_pixmap != NULL)
-		g_object_unref (source_pixmap);
+		cairo_surface_destroy (source_pixmap);
 
 	if (data != NULL)
 		XFree (data);
 
-	return pixmap;
+	return surface;
 }
 
 static void
-gnome_bg_set_root_pixmap_id (GdkScreen *screen,
-			     GdkPixmap *pixmap)
+gnome_bg_set_root_pixmap_id (GdkScreen       *screen,
+			     cairo_surface_t *surface)
 {
 	int      result;
 	gint     format;
@@ -1356,7 +1367,7 @@ gnome_bg_set_root_pixmap_id (GdkScreen *screen,
 		XFree (data_esetroot);
 	}
 	
-	pixmap_id = GDK_WINDOW_XWINDOW (pixmap);
+	pixmap_id = cairo_xlib_surface_get_drawable (surface);
 	
 	XChangeProperty (display, RootWindow (display, screen_num),
 			 gdk_x11_get_xatom_by_name ("ESETROOT_PMAP_ID"),
@@ -1369,25 +1380,26 @@ gnome_bg_set_root_pixmap_id (GdkScreen *screen,
 }
 
 /**
- * gnome_bg_set_pixmap_as_root:
+ * gnome_bg_set_surface_as_root:
  * @screen: the #GdkScreen to change root background on
- * @pixmap: the #GdkPixmap to set root background from
+ * @surface: the #cairo_surface_t to set root background from.
+ *   Must be an xlib surface backing a pixmap.
  *
  * Set the root pixmap, and properties pointing to it. We
  * do this atomically with a server grab to make sure that
  * we won't leak the pixmap if somebody else it setting
  * it at the same time. (This assumes that they follow the
- * same conventions we do).  @pixmap should come from a call
- * to gnome_bg_create_pixmap().
+ * same conventions we do).  @surface should come from a call
+ * to gnome_bg_create_surface().
  **/
 void
-gnome_bg_set_pixmap_as_root (GdkScreen *screen, GdkPixmap *pixmap)
+gnome_bg_set_surface_as_root (GdkScreen *screen, cairo_surface_t *surface)
 {
 	Display *display;
 	int      screen_num;
 
 	g_return_if_fail (screen != NULL);
-	g_return_if_fail (pixmap != NULL);
+	g_return_if_fail (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB);
 
 	screen_num = gdk_screen_get_number (screen);
 
@@ -1395,10 +1407,10 @@ gnome_bg_set_pixmap_as_root (GdkScreen *screen, GdkPixmap *pixmap)
 
 	gdk_x11_display_grab (gdk_screen_get_display (screen));
 
-	gnome_bg_set_root_pixmap_id (screen, pixmap);
+	gnome_bg_set_root_pixmap_id (screen, surface);
 
 	XSetWindowBackgroundPixmap (display, RootWindow (display, screen_num),
-				    GDK_PIXMAP_XID (pixmap));
+				    cairo_xlib_surface_get_drawable (surface));
 	XClearWindow (display, RootWindow (display, screen_num));
 
 	gdk_display_flush (gdk_screen_get_display (screen));
@@ -1406,31 +1418,30 @@ gnome_bg_set_pixmap_as_root (GdkScreen *screen, GdkPixmap *pixmap)
 }
 
 /**
- * gnome_bg_set_pixmap_as_root_with_crossfade:
+ * gnome_bg_set_surface_as_root_with_crossfade:
  * @screen: the #GdkScreen to change root background on
- * @pixmap: the #GdkPixmap to set root background from
+ * @surface: the cairo xlib surface to set root background from
  * @context: a #GMainContext or %NULL
  *
  * Set the root pixmap, and properties pointing to it.
- * This function differs from gnome_bg_set_pixmap_as_root()
+ * This function differs from gnome_bg_set_surface_as_root()
  * in that it adds a subtle crossfade animation from the
  * current root pixmap to the new one.
- * same conventions we do).
  *
  * Return value: a #GnomeBGCrossfade object
  **/
 GnomeBGCrossfade *
-gnome_bg_set_pixmap_as_root_with_crossfade (GdkScreen    *screen,
-					    GdkPixmap    *pixmap)
+gnome_bg_set_surface_as_root_with_crossfade (GdkScreen       *screen,
+		 			     cairo_surface_t *surface)
 {
 	GdkDisplay *display;
 	GdkWindow *root_window;
-	GdkPixmap *old_pixmap;
+	cairo_surface_t *old_surface;
 	int      width, height;
 	GnomeBGCrossfade *fade;
 
 	g_return_val_if_fail (screen != NULL, NULL);
-	g_return_val_if_fail (pixmap != NULL, NULL);
+	g_return_val_if_fail (surface != NULL, NULL);
 
 	root_window = gdk_screen_get_root_window (screen);
 
@@ -1441,11 +1452,11 @@ gnome_bg_set_pixmap_as_root_with_crossfade (GdkScreen    *screen,
 
 	display = gdk_screen_get_display (screen);
 	gdk_x11_display_grab (display);
-	old_pixmap = gnome_bg_get_pixmap_from_root (screen);
-	gnome_bg_set_root_pixmap_id (screen, pixmap);
-	gnome_bg_crossfade_set_start_pixmap (fade, old_pixmap);
-	g_object_unref (old_pixmap);
-	gnome_bg_crossfade_set_end_pixmap (fade, pixmap);
+	old_surface = gnome_bg_get_surface_from_root (screen);
+	gnome_bg_set_root_pixmap_id (screen, surface);
+	gnome_bg_crossfade_set_start_surface (fade, old_surface);
+	cairo_surface_destroy (old_surface);
+	gnome_bg_crossfade_set_end_surface (fade, surface);
 	gdk_display_flush (display);
 	gdk_x11_display_ungrab (display);
 
diff --git a/libgnome-desktop/libgnomeui/gnome-bg-crossfade.h b/libgnome-desktop/libgnomeui/gnome-bg-crossfade.h
index b70dc89..6bd5886 100644
--- a/libgnome-desktop/libgnomeui/gnome-bg-crossfade.h
+++ b/libgnome-desktop/libgnomeui/gnome-bg-crossfade.h
@@ -1,4 +1,4 @@
-/* gnome-bg-crossfade.h - fade window background between two pixmaps
+/* gnome-bg-crossfade.h - fade window background between two surfaces
 
    Copyright 2008, Red Hat, Inc.
 
@@ -60,10 +60,10 @@ struct _GnomeBGCrossfadeClass
 
 GType             gnome_bg_crossfade_get_type              (void);
 GnomeBGCrossfade *gnome_bg_crossfade_new (int width, int height);
-gboolean          gnome_bg_crossfade_set_start_pixmap (GnomeBGCrossfade *fade,
-                                                      GdkPixmap *pixmap);
-gboolean          gnome_bg_crossfade_set_end_pixmap (GnomeBGCrossfade *fade,
-                                                    GdkPixmap *pixmap);
+gboolean          gnome_bg_crossfade_set_start_surface (GnomeBGCrossfade *fade,
+                                                        cairo_surface_t *surface);
+gboolean          gnome_bg_crossfade_set_end_surface (GnomeBGCrossfade *fade,
+                                                      cairo_surface_t *surface);
 void              gnome_bg_crossfade_start (GnomeBGCrossfade *fade,
                                             GdkWindow        *window);
 gboolean          gnome_bg_crossfade_is_started (GnomeBGCrossfade *fade);
diff --git a/libgnome-desktop/libgnomeui/gnome-bg.h b/libgnome-desktop/libgnomeui/gnome-bg.h
index 0d12b3b..308d972 100644
--- a/libgnome-desktop/libgnomeui/gnome-bg.h
+++ b/libgnome-desktop/libgnomeui/gnome-bg.h
@@ -91,7 +91,7 @@ void             gnome_bg_draw                  (GnomeBG               *bg,
 						 GdkPixbuf             *dest,
 						 GdkScreen	       *screen,
                                                  gboolean               is_root);
-GdkPixmap *      gnome_bg_create_pixmap         (GnomeBG               *bg,
+cairo_surface_t *gnome_bg_create_surface        (GnomeBG               *bg,
 						 GdkWindow             *window,
 						 int                    width,
 						 int                    height,
@@ -119,16 +119,16 @@ GdkPixbuf *      gnome_bg_create_frame_thumbnail (GnomeBG              *bg,
 						 int                    dest_height,
 						 int                    frame_num);
 
-/* Set a pixmap as root - not a GnomeBG method. At some point
+/* Set a surface as root - not a GnomeBG method. At some point
  * if we decide to stabilize the API then we may want to make
- * these object methods, drop gnome_bg_create_pixmap, etc.
+ * these object methods, drop gnome_bg_create_surface, etc.
  */
-void             gnome_bg_set_pixmap_as_root    (GdkScreen             *screen,
-						 GdkPixmap             *pixmap);
+void             gnome_bg_set_surface_as_root   (GdkScreen             *screen,
+						 cairo_surface_t       *surface);
 
-GnomeBGCrossfade *gnome_bg_set_pixmap_as_root_with_crossfade (GdkScreen *screen,
-                                                              GdkPixmap *pixmap);
-GdkPixmap *gnome_bg_get_pixmap_from_root (GdkScreen *screen);
+GnomeBGCrossfade *gnome_bg_set_surface_as_root_with_crossfade (GdkScreen *screen,
+                                                              cairo_surface_t *surface);
+cairo_surface_t *gnome_bg_get_surface_from_root (GdkScreen *screen);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]