From 88b2718c75f6d624d8748f802e8609b45a635b95 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sat, 19 Jul 2014 21:42:33 +0200 Subject: [PATCH] Replace dbus-glib dependent sources --- plugins/notify/Makefile.am | 1 - plugins/notify/NotifyServer.vala | 35 ++++++++++++++----- plugins/notify/pixbuf-dbus-util.c | 58 ------------------------------- 3 files changed, 26 insertions(+), 68 deletions(-) delete mode 100644 plugins/notify/pixbuf-dbus-util.c diff --git a/plugins/notify/Makefile.am b/plugins/notify/Makefile.am index f455121f..084a9b08 100644 --- a/plugins/notify/Makefile.am +++ b/plugins/notify/Makefile.am @@ -44,7 +44,6 @@ libgala_notify_la_VALASOURCES = \ nodist_libgala_notify_la_SOURCES = \ $(BUILT_SOURCES) \ $(libgala_notify_la_VALASOURCES:.vala=.c) \ - pixbuf-dbus-util.c \ $(NULL) libgala_notify_la_vala.stamp: $(libgala_notify_la_VALASOURCES) diff --git a/plugins/notify/NotifyServer.vala b/plugins/notify/NotifyServer.vala index bde84e46..f6f25459 100644 --- a/plugins/notify/NotifyServer.vala +++ b/plugins/notify/NotifyServer.vala @@ -19,9 +19,6 @@ using Meta; namespace Gala.Plugins.Notify { - [CCode (cname = "get_pixbuf_from_dbus_variant")] - public extern Gdk.Pixbuf get_pixbuf_from_dbus_variant (Variant variant); - public enum NotificationUrgency { LOW = 0, NORMAL = 1, @@ -179,12 +176,9 @@ namespace Gala.Plugins.Notify if (hints.contains ("image_data") || hints.contains ("image-data")) { - var image = hints.contains ("image_data") ? + var data = hints.contains ("image_data") ? hints.lookup ("image_data") : hints.lookup ("image-data"); - - pixbuf = get_pixbuf_from_dbus_variant (image); - - pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.HYPER); + pixbuf = load_from_variant_at_size (data, size); } else if (hints.contains ("image-path") || hints.contains ("image_path")) { @@ -210,7 +204,10 @@ namespace Gala.Plugins.Notify } catch (Error e) { warning (e.message); } } else if (hints.contains ("icon_data")) { - warning ("icon data is not supported"); + + var data = hints.lookup ("icon_data"); + pixbuf = load_from_variant_at_size (data, size); + } if (pixbuf == null) { @@ -227,6 +224,26 @@ namespace Gala.Plugins.Notify return pixbuf; } + + static Gdk.Pixbuf? load_from_variant_at_size (Variant variant, int size) + { + if (!variant.is_of_type (new VariantType ("(iiibiiay)"))) { + critical ("notify icon/image-data format invalid"); + return null; + } + + int width, height, rowstride, bits_per_sample, n_channels; + bool has_alpha; + + variant.get ("(iiibiiay)", out width, out height, out rowstride, + out has_alpha, out bits_per_sample, out n_channels, null); + + var data = variant.get_child_value (6); + unowned uint8[] pixel_data = (uint8[]) data.get_data (); + + var pixbuf = new Gdk.Pixbuf.with_unowned_data (pixel_data, Gdk.Colorspace.RGB, has_alpha, bits_per_sample, width, height, rowstride, null); + return pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR); + } } } diff --git a/plugins/notify/pixbuf-dbus-util.c b/plugins/notify/pixbuf-dbus-util.c deleted file mode 100644 index f08fbae3..00000000 --- a/plugins/notify/pixbuf-dbus-util.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -// copied from notify-osd /src/stack.c with some minor changes - -GdkPixbuf * -get_pixbuf_from_dbus_variant (GVariant *variant) -{ - GValue data = G_VALUE_INIT; - GType dbus_icon_t; - GArray *pixels; - int width, height, rowstride, bits_per_sample, n_channels, size; - gboolean has_alpha; - guchar *copy; - GdkPixbuf *pixbuf = NULL; - - g_return_val_if_fail (variant != NULL, NULL); - - dbus_icon_t = dbus_g_type_get_struct ("GValueArray", - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_BOOLEAN, - G_TYPE_INT, - G_TYPE_INT, - dbus_g_type_get_collection ("GArray", G_TYPE_UCHAR), - G_TYPE_INVALID); - - dbus_g_value_parse_g_variant (variant, &data); - - if (G_VALUE_HOLDS (&data, dbus_icon_t)) { - dbus_g_type_struct_get (&data, - 0, &width, - 1, &height, - 2, &rowstride, - 3, &has_alpha, - 4, &bits_per_sample, - 5, &n_channels, - 6, &pixels, - G_MAXUINT); - - size = (height - 1) * rowstride + width * - ((n_channels * bits_per_sample + 7) / 8); - copy = (guchar *) g_memdup (pixels->data, size); - - pixbuf = gdk_pixbuf_new_from_data(copy, GDK_COLORSPACE_RGB, - has_alpha, - bits_per_sample, - width, height, - rowstride, - (GdkPixbufDestroyNotify)g_free, - NULL); - } - - return pixbuf; -} -