From b4684e246ceb43db42a82db98882c44534538ab5 Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Fri, 29 Dec 2023 16:11:53 +0100 Subject: [PATCH] display loaded image in notification --- plugins/notify/notify.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/plugins/notify/notify.c b/plugins/notify/notify.c index b2e4cba644..178a384bc9 100644 --- a/plugins/notify/notify.c +++ b/plugins/notify/notify.c @@ -324,7 +324,7 @@ show_notification (DB_playItem_t *track, char *image_filename, dbus_uint32_t rep bool should_wait_for_cover = !image_filename && deadbeef->conf_get_int ("notify.albumart", 0) && artwork_plugin; bool should_apply_kde_fix = deadbeef->conf_get_int ("notify.fix_kde_5_23_5", 0) ? true : false; - // KDE won't re-display notification via reuse, + // KDE won't re-display notification via reuse, // so don't show it now and wait for cover callback. if (!(should_wait_for_cover && should_apply_kde_fix)) { char *v_iconname = ""; // image_filename ?: "deadbeef"; @@ -333,19 +333,8 @@ show_notification (DB_playItem_t *track, char *image_filename, dbus_uint32_t rep dbus_int32_t v_timeout = -1; GdkPixbuf *img = _load_image (image_filename); - - dbus_int32_t width = 64; - dbus_int32_t height = 64; - dbus_int32_t stride = width * 4; - dbus_bool_t has_alpha = 1; // has to be 1, otherwise channels=4 is ignored and interpreted as 3. - dbus_int32_t bits_per_sample = 8; - dbus_int32_t channels = 4; - - uint32_t *image_bytes = malloc (width * width * sizeof (uint32_t)); - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - image_bytes[y * width + x] = 0xff0000ff; - } + if (!img) { + v_iconname = "deadbeef"; } DBusMessageIter iter, sub; @@ -372,7 +361,15 @@ show_notification (DB_playItem_t *track, char *image_filename, dbus_uint32_t rep // hints dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}", &sub); - { + if (img != NULL) { + dbus_int32_t width = gdk_pixbuf_get_width (img); + dbus_int32_t height = gdk_pixbuf_get_height (img); + dbus_int32_t stride = gdk_pixbuf_get_rowstride (img); + dbus_bool_t has_alpha = gdk_pixbuf_get_has_alpha (img); + dbus_int32_t bits_per_sample = gdk_pixbuf_get_bits_per_sample (img); + dbus_int32_t channels = gdk_pixbuf_get_n_channels (img); + guchar *image_bytes = gdk_pixbuf_get_pixels(img); + g_object_unref(img); DBusMessageIter dict_entry_sub; dbus_message_iter_open_container (&sub, DBUS_TYPE_DICT_ENTRY, 0, &dict_entry_sub); @@ -416,7 +413,7 @@ show_notification (DB_playItem_t *track, char *image_filename, dbus_uint32_t rep &data_sub, DBUS_TYPE_BYTE, &image_bytes, - width * height * 4); + stride * height); } dbus_message_iter_close_container (&image_sub, &data_sub); @@ -436,8 +433,6 @@ show_notification (DB_playItem_t *track, char *image_filename, dbus_uint32_t rep dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &v_timeout); replaces_id = notify_send (msg, replaces_id); - - free (image_bytes); } if (should_wait_for_cover) {