[gnome-panel/gtk3] panel: Use gnome_bg_get_surface_from_root() from libgnome-desktop



commit 74b4a5232480f62bb72234367a4cc80ace13d518
Author: Vincent Untz <vuntz gnome org>
Date:   Mon Jan 31 17:27:34 2011 +0100

    panel: Use gnome_bg_get_surface_from_root() from libgnome-desktop
    
    The code was duplicated in the background monitor.
    
    Also, fix a bug where cairo_image_surface_get_width() was used instead
    of cairo_xlib_surface_get_width().

 gnome-panel/Makefile.am                |    3 +-
 gnome-panel/panel-background-monitor.c |  117 +++-----------------------------
 gnome-panel/panel-run-dialog.c         |    1 -
 3 files changed, 11 insertions(+), 110 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index a283b50..f942714 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -126,7 +126,8 @@ gnome_panel_CPPFLAGS = 				\
 	$(AM_CPPFLAGS)				\
 	$(XRANDR_CFLAGS)			\
 	-DPANEL_MODULES_DIR=\"$(modulesdir)\"	\
-	-DGMENU_I_KNOW_THIS_IS_UNSTABLE
+	-DGMENU_I_KNOW_THIS_IS_UNSTABLE		\
+	-DGNOME_DESKTOP_USE_UNSTABLE_API
 
 gnome_panel_LDADD =		\
 	$(top_builddir)/gnome-panel/libegg/libegg.la					\
diff --git a/gnome-panel/panel-background-monitor.c b/gnome-panel/panel-background-monitor.c
index 5d2612c..38bb8ce 100644
--- a/gnome-panel/panel-background-monitor.c
+++ b/gnome-panel/panel-background-monitor.c
@@ -32,6 +32,8 @@
 #include <X11/Xatom.h>
 #include <cairo-xlib.h>
 
+#include <libgnome-desktop/gnome-bg.h>
+
 #include "panel-background-monitor.h"
 #include "panel-util.h"
 
@@ -63,7 +65,7 @@ struct _PanelBackgroundMonitor {
 	GdkAtom    gdkatom;
 
         cairo_surface_t *surface;
-        GdkPixbuf *gdkpixbuf; // FIXMEchpe this is insane!!!
+        GdkPixbuf *gdkpixbuf;
 
 	int        width;
 	int        height;
@@ -235,104 +237,6 @@ panel_background_monitor_xevent_filter (GdkXEvent *xevent,
 	return GDK_FILTER_CONTINUE;
 }
 
-/* copied from gnome-desktop. FIXMEchpe: switch panel-background{,-monitor} over to libgnome-desktop! */
-static cairo_surface_t *
-gnome_bg_get_surface_from_root (GdkScreen *screen,
-                                int *widthptr,
-                                int *heightptr)
-{
-        int result;
-        gint format;
-        gulong nitems;
-        gulong bytes_after;
-        guchar *data;
-        Atom type;
-        Display *display;
-        int screen_num;
-        cairo_surface_t *surface;
-        cairo_surface_t *source_pixmap;
-        int width, height;
-        cairo_t *cr;
-
-        display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
-        screen_num = gdk_screen_get_number (screen);
-
-        result = XGetWindowProperty (display,
-                                     RootWindow (display, screen_num),
-                                     gdk_x11_get_xatom_by_name ("_XROOTPMAP_ID"),
-                                     0L, 1L, False, XA_PIXMAP,
-                                     &type, &format, &nitems, &bytes_after,
-                                     &data);
-        surface = NULL;
-        source_pixmap = NULL;
-
-        if (result != Success || type != XA_PIXMAP ||
-            format != 32 || nitems != 1) {
-                XFree (data);
-                data = NULL;
-        }
-
-        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 ();
-                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);
-                }
-
-                gdk_error_trap_pop_ignored ();
-        }
-
-        width = gdk_screen_get_width (screen);
-        height = gdk_screen_get_height (screen);
-
-        if (source_pixmap) {
-                surface = cairo_surface_create_similar (source_pixmap,
-                                                        CAIRO_CONTENT_COLOR,
-                                                        width, height);
-
-                cr = cairo_create (surface);
-                cairo_set_source_surface (cr, source_pixmap, 0, 0);
-                cairo_paint (cr);
-
-                if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
-                        cairo_surface_destroy (surface);
-                        surface = NULL;
-                }
-
-                cairo_destroy (cr);
-        }
-
-#if 0
-        /* We don't need this fallback here */
-        if (surface == NULL) {
-                surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
-                                                             CAIRO_CONTENT_COLOR,
-                                                             width, height);
-        }
-#endif
-
-        if (source_pixmap != NULL)
-                cairo_surface_destroy (source_pixmap);
-
-        if (data != NULL)
-                XFree (data);
-
-        *widthptr = width;
-        *heightptr = height;
-
-        return surface;
-}
-
 static GdkPixbuf *
 panel_background_monitor_tile_background (PanelBackgroundMonitor *monitor,
 					  int                     width,
@@ -410,22 +314,19 @@ panel_background_monitor_setup_pixbuf (PanelBackgroundMonitor *monitor)
 	gdk_x11_display_grab (display);
 	monitor->display_grabbed = TRUE;
 
-	if (!monitor->surface) {
-              monitor->surface = gnome_bg_get_surface_from_root (monitor->screen,
-                                                                 &pwidth, &pheight);
-              if (!monitor->surface)
-                      g_warning ("couldn't get background pixmap\n");
-        } else {
-                pwidth = cairo_image_surface_get_width (monitor->surface);
-                pheight = cairo_image_surface_get_height (monitor->surface);
-        }
+	if (!monitor->surface)
+              monitor->surface = gnome_bg_get_surface_from_root (monitor->screen);
 
 	if (!monitor->surface) {
+		g_warning ("couldn't get background pixmap\n");
 		gdk_x11_display_ungrab (display);
 		monitor->display_grabbed = FALSE;
 		return;
 	}
 
+	pwidth = cairo_xlib_surface_get_width (monitor->surface);
+	pheight = cairo_xlib_surface_get_height (monitor->surface);
+
 	gdk_window_get_geometry (monitor->gdkwindow,
 				 NULL, NULL, &rwidth, &rheight);
 
diff --git a/gnome-panel/panel-run-dialog.c b/gnome-panel/panel-run-dialog.c
index 1105bba..a16ee92 100644
--- a/gnome-panel/panel-run-dialog.c
+++ b/gnome-panel/panel-run-dialog.c
@@ -43,7 +43,6 @@
 #include <gconf/gconf-client.h>
 #include <gmenu-tree.h>
 
-#define GNOME_DESKTOP_USE_UNSTABLE_API
 #include <libgnome-desktop/gnome-desktop-utils.h>
 
 #include <libpanel-util/panel-error.h>



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