diff options
| author | Victor Kareh <[email protected]> | 2025-10-15 08:51:45 -0400 |
|---|---|---|
| committer | Victor Kareh <[email protected]> | 2026-03-17 09:30:52 -0400 |
| commit | ae99a1d79fb1891c5f7b71daa7eaa3e92ba088e6 (patch) | |
| tree | 11154a2af69e551235da9c3a9b20c3c94c45bf79 | |
| parent | 20b9beb93bfa8bac61b85f282dd3e51a1ab4b21b (diff) | |
| download | mate-notification-daemon-daemon-icons.tar.bz2 mate-notification-daemon-daemon-icons.tar.xz | |
daemon: Refactor icon resolution to use fallback chaindaemon-icons
Change icon resolution to separate if clauses. This allows each fallback
method to attempt icon loading regardless of whether previous parameters
were provided but failed to resolve.
For example, previously if an application provided an empty or invalid
icon parameter, the daemon would skip all other checks and no icon would
be resolved, even if the other checks would have succeeded in resolving
an icon.
| -rw-r--r-- | src/daemon/daemon.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index eb87a38..3ee36f2 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -1638,36 +1638,47 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, * 3. icon (which falls back to the desktop entry) * 4. icon_data (for backward compatibility) */ - if (g_variant_lookup(hints, "image-data", "@(iiibiiay)", &data)) + if (pixbuf == NULL && g_variant_lookup(hints, "image-data", "@(iiibiiay)", &data)) { pixbuf = _notify_daemon_pixbuf_from_data_hint (data); g_variant_unref(data); } - else if (g_variant_lookup(hints, "image_data", "@(iiibiiay)", &data)) + + if (pixbuf == NULL && g_variant_lookup(hints, "image_data", "@(iiibiiay)", &data)) { pixbuf = _notify_daemon_pixbuf_from_data_hint (data); g_variant_unref(data); } - else if (g_variant_lookup(hints, "image-path", "@s", &data)) + + if (pixbuf == NULL && g_variant_lookup(hints, "image-path", "@s", &data)) { const char *path = g_variant_get_string (data, NULL); pixbuf = _notify_daemon_pixbuf_from_path (path); - resolved_icon = g_strdup(path); + if (pixbuf != NULL) { + resolved_icon = g_strdup(path); + } g_variant_unref(data); } - else if (g_variant_lookup(hints, "image_path", "@s", &data)) + + if (pixbuf == NULL && g_variant_lookup(hints, "image_path", "@s", &data)) { const char *path = g_variant_get_string (data, NULL); pixbuf = _notify_daemon_pixbuf_from_path (path); - resolved_icon = g_strdup(path); + if (pixbuf != NULL) { + resolved_icon = g_strdup(path); + } g_variant_unref(data); } - else if (*icon != '\0') + + if (pixbuf == NULL && icon != NULL && *icon != '\0') { pixbuf = _notify_daemon_pixbuf_from_path (icon); - resolved_icon = g_strdup(icon); + if (pixbuf != NULL) { + resolved_icon = g_strdup(icon); + } } - else if (desktop_entry != NULL && *desktop_entry != '\0') + + if (pixbuf == NULL && desktop_entry != NULL && *desktop_entry != '\0') { /* Use desktop-entry to resolve application icon as fallback */ gchar *desktop_file = g_strdup_printf("%s.desktop", desktop_entry); @@ -1693,7 +1704,7 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, { pixbuf = _notify_daemon_pixbuf_from_path (icon_name); - if (!resolved_icon && (*icon == '\0' || icon == NULL)) { + if (pixbuf != NULL && !resolved_icon) { resolved_icon = g_strdup(icon_name); } @@ -1703,9 +1714,10 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, g_key_file_free(key_file); g_free(desktop_file); } - else if (app_name != NULL && *app_name != '\0') + + if (pixbuf == NULL && app_name != NULL && *app_name != '\0') { - /* Fallback: Try to find icon from desktop key file based on the app_name */ + /* Fallback: Try to derive desktop entry from app_name */ gchar *desktop_key = g_ascii_strdown(app_name, -1); for (gchar *p = desktop_key; *p != '\0'; p++) { if (*p == ' ') *p = '-'; @@ -1725,7 +1737,7 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, if (icon_info != NULL) { pixbuf = gtk_icon_info_load_icon(icon_info, NULL); - if (pixbuf != NULL && !resolved_icon && (*icon == '\0' || icon == NULL)) { + if (pixbuf != NULL && !resolved_icon) { resolved_icon = g_strdup(g_icon_to_string(gicon)); } g_object_unref(icon_info); @@ -1737,7 +1749,8 @@ static gboolean notify_daemon_notify_handler(NotifyDaemonNotifications *object, g_free(desktop_id); g_free(desktop_key); } - else if (g_variant_lookup(hints, "icon_data", "@(iiibiiay)", &data)) + + if (pixbuf == NULL && g_variant_lookup(hints, "icon_data", "@(iiibiiay)", &data)) { g_warning("\"icon_data\" hint is deprecated, please use \"image_data\" instead"); pixbuf = _notify_daemon_pixbuf_from_data_hint (data); |
