[gnome-shell/wip/gcampax/background: 6/7] Util: add an accessor for the root background pixmap



commit d457073c10c90d31b879fe814cb5dddfa7a8762f
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Dec 24 15:20:39 2012 +0100

    Util: add an accessor for the root background pixmap
    
    The background of the root window is accessible as the _XROOTPMAP_ID
    property on the root window. Given that the root window is always
    fully covered by the Composite Overlay Window, we use that as temporary
    storage while the COW is not mapped, that is, before the GDM greeter
    is started and between killing the greeter and starting GDM from the
    session.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682429

 src/Makefile.am  |    2 +-
 src/shell-util.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/shell-util.h |    3 ++
 3 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4dbff69..4364d15 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -292,7 +292,7 @@ libgnome_shell_la_LIBADD =		\
 libgnome_shell_la_CPPFLAGS = $(gnome_shell_cflags)
 
 Shell-0.1.gir: libgnome-shell.la St-1.0.gir
-Shell_0_1_gir_INCLUDES = Clutter-1.0 ClutterX11-1.0 Meta-3.0 TelepathyGLib-0.12 TelepathyLogger-0.2 Soup-2.4 GMenu-3.0 NetworkManager-1.0 NMClient-1.0
+Shell_0_1_gir_INCLUDES = Clutter-1.0 ClutterX11-1.0 Meta-3.0 TelepathyGLib-0.12 TelepathyLogger-0.2 Soup-2.4 GMenu-3.0 NetworkManager-1.0 NMClient-1.0 xlib-2.0
 Shell_0_1_gir_CFLAGS = $(libgnome_shell_la_CPPFLAGS) -I $(srcdir)
 Shell_0_1_gir_LIBS = libgnome-shell.la
 Shell_0_1_gir_FILES = $(libgnome_shell_la_gir_sources)
diff --git a/src/shell-util.c b/src/shell-util.c
index 3821b3a..abd026f 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -9,6 +9,8 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdkx.h>
+#include <X11/Xatom.h>
 
 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
 #include <langinfo.h>
@@ -430,3 +432,56 @@ shell_util_create_pixbuf_from_data (const guchar      *data,
                                    bits_per_sample, width, height, rowstride,
                                    (GdkPixbufDestroyNotify) g_free, NULL);
 }
+
+Pixmap
+shell_util_get_root_background (void)
+{
+  Display *display;
+  Pixmap pixmap;
+  Window rootwin;
+  Atom xrootpmap;
+  Atom actual_type;
+  int actual_format;
+  unsigned long n_items;
+  unsigned long bytes_after;
+  unsigned char *buffer;
+
+  display = gdk_x11_get_default_xdisplay ();
+
+  xrootpmap = gdk_x11_atom_to_xatom (gdk_atom_intern_static_string ("_XROOTPMAP_ID"));
+  rootwin = gdk_x11_get_default_root_xwindow ();
+
+  gdk_error_trap_push ();
+  actual_type = None;
+  buffer = NULL;
+  if (XGetWindowProperty (display, rootwin, xrootpmap,
+                          0, G_MAXLONG,
+                          False, XA_PIXMAP, &actual_type, &actual_format,
+                          &n_items,
+                          &bytes_after,
+                          &buffer) != Success ||
+      actual_type == None)
+    {
+      if (buffer)
+        XFree (buffer);
+      gdk_error_trap_pop_ignored ();
+      return FALSE;
+    }
+
+  if (gdk_error_trap_pop () != Success ||
+      n_items == 0 ||
+      actual_type != XA_PIXMAP ||
+      actual_format != 32)
+    {
+      if (buffer)
+        XFree (buffer);
+      return FALSE;
+    }
+
+  pixmap = *((Pixmap*) buffer);
+
+  XFree (buffer);
+  return pixmap;
+}
+
+
diff --git a/src/shell-util.h b/src/shell-util.h
index 41ba96f..0b23dff 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -7,6 +7,7 @@
 #include <clutter/clutter.h>
 #include <libsoup/soup.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdkx.h>
 
 G_BEGIN_DECLS
 
@@ -46,6 +47,8 @@ GdkPixbuf *shell_util_create_pixbuf_from_data (const guchar      *data,
                                                int                height,
                                                int                rowstride);
 
+Pixmap  shell_util_get_root_background        (void);
+
 G_END_DECLS
 
 #endif /* __SHELL_UTIL_H__ */



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