From d457073c10c90d31b879fe814cb5dddfa7a8762f Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 24 Dec 2012 15:20:39 +0100 Subject: [PATCH] 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 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4dbff6988..4364d15a6 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 3821b3aff..abd026f69 100644 --- a/src/shell-util.c +++ b/src/shell-util.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #ifdef HAVE__NL_TIME_FIRST_WEEKDAY #include @@ -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 41ba96f4a..0b23dff66 100644 --- a/src/shell-util.h +++ b/src/shell-util.h @@ -7,6 +7,7 @@ #include #include #include +#include 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__ */