From cd09d5a88e59b30356094af816d0adb72051ba08 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Fri, 28 Dec 2018 18:45:16 +0100 Subject: [PATCH] Cache GdkPixbuf in notification structure --- src/icon.c | 17 +---------------- src/notification.c | 17 +++++++++++++++++ src/notification.h | 2 ++ test/dbus.c | 4 ++++ test/queues.c | 4 ++++ 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/icon.c b/src/icon.c index 4fbb69b..f7acadd 100644 --- a/src/icon.c +++ b/src/icon.c @@ -224,22 +224,7 @@ GdkPixbuf *get_pixbuf_from_raw_image(const struct raw_image *raw_image) cairo_surface_t *icon_get_for_notification(const struct notification *n) { - GdkPixbuf *pixbuf; - - if (n->raw_icon) - pixbuf = get_pixbuf_from_raw_image(n->raw_icon); - else if (n->iconname) - pixbuf = get_pixbuf_from_icon(n->iconname); - else - return NULL; - - ASSERT_OR_RET(pixbuf, NULL); - - pixbuf = icon_pixbuf_scale(pixbuf); - - cairo_surface_t *ret = gdk_pixbuf_to_cairo_surface(pixbuf); - g_object_unref(pixbuf); - return ret; + return gdk_pixbuf_to_cairo_surface(n->icon); } /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/notification.c b/src/notification.c index 5b224bd..55b6d22 100644 --- a/src/notification.c +++ b/src/notification.c @@ -15,6 +15,7 @@ #include "dbus.h" #include "dunst.h" +#include "icon.h" #include "log.h" #include "markup.h" #include "menu.h" @@ -23,6 +24,7 @@ #include "settings.h" #include "utils.h" +static void notification_update_icon(struct notification *n); static void notification_extract_urls(struct notification *n); static void notification_format_message(struct notification *n); @@ -363,10 +365,25 @@ void notification_init(struct notification *n) rule_apply_all(n); /* UPDATE derived fields */ + notification_update_icon(n); notification_extract_urls(n); notification_format_message(n); } +static void notification_update_icon(struct notification *n) +{ + g_return_if_fail(n); + + g_clear_object(&n->icon); + + if (n->raw_icon) + n->icon = get_pixbuf_from_raw_image(n->raw_icon); + else if (n->iconname) + n->icon = get_pixbuf_from_icon(n->iconname); + + n->icon = icon_pixbuf_scale(n->icon); +} + static void notification_format_message(struct notification *n) { g_clear_pointer(&n->msg, g_free); diff --git a/src/notification.h b/src/notification.h index fc69216..7db5f8c 100644 --- a/src/notification.h +++ b/src/notification.h @@ -2,6 +2,7 @@ #ifndef DUNST_NOTIFICATION_H #define DUNST_NOTIFICATION_H +#include #include #include @@ -56,6 +57,7 @@ struct notification { char *category; enum urgency urgency; + GdkPixbuf *icon; char *iconname; /**< plain icon information (may be a path or just a name) */ struct raw_image *raw_icon; /**< passed icon data of notification, takes precedence over icon */ diff --git a/test/dbus.c b/test/dbus.c index a98a9eb..88db471 100644 --- a/test/dbus.c +++ b/test/dbus.c @@ -796,6 +796,8 @@ gpointer run_threaded_tests(gpointer data) SUITE(suite_dbus) { + settings.icon_path = ""; + GTestDBus *dbus_bus; g_test_dbus_unset(); queues_init(); @@ -813,6 +815,8 @@ SUITE(suite_dbus) g_object_unref(dbus_bus); g_thread_unref(thread_tests); g_main_loop_unref(loop); + + settings.icon_path = NULL; } /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/test/queues.c b/test/queues.c index 1ba8216..67e7651 100644 --- a/test/queues.c +++ b/test/queues.c @@ -698,6 +698,8 @@ TEST test_queues_timeout_before_paused(void) SUITE(suite_queues) { + settings.icon_path = ""; + RUN_TEST(test_datachange_beginning_empty); RUN_TEST(test_datachange_endless); RUN_TEST(test_datachange_endless_agethreshold); @@ -722,6 +724,8 @@ SUITE(suite_queues) RUN_TEST(test_queues_update_seeping); RUN_TEST(test_queues_update_xmore); RUN_TEST(test_queues_timeout_before_paused); + + settings.icon_path = NULL; } /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */