From 854c9a26e6b42a3f5950bd44ad51e6e74d1713be Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Mon, 24 Jul 2023 19:53:31 -0400 Subject: [PATCH 1/3] Hints: Support 'sound-file' hint in makoctl list --- dbus/mako.c | 6 ++++++ dbus/xdg.c | 8 ++++++++ include/notification.h | 1 + notification.c | 3 +++ 4 files changed, 18 insertions(+) diff --git a/dbus/mako.c b/dbus/mako.c index 9fc0b01..808e71c 100644 --- a/dbus/mako.c +++ b/dbus/mako.c @@ -208,6 +208,12 @@ static int handle_list(sd_bus_message *msg, struct wl_list *list) { return ret; } + ret = sd_bus_message_append(reply, "{sv}", "sound-file", + "s", notif->sound_file); + if (ret < 0) { + return ret; + } + ret = sd_bus_message_open_container(reply, 'e', "sv"); if (ret < 0) { return ret; diff --git a/dbus/xdg.c b/dbus/xdg.c index acff6e5..8de626b 100644 --- a/dbus/xdg.c +++ b/dbus/xdg.c @@ -229,6 +229,14 @@ static int handle_notify(sd_bus_message *msg, void *data, } free(notif->desktop_entry); notif->desktop_entry = strdup(desktop_entry); + } else if (strcmp(hint, "sound-file") == 0) { + const char *sound_file = NULL; + ret = sd_bus_message_read(msg, "v", "s", &sound_file); + if (ret < 0) { + return ret; + } + free(notif->sound_file); + notif->sound_file = strdup(sound_file); } else if (strcmp(hint, "value") == 0) { int32_t progress = 0; ret = sd_bus_message_read(msg, "v", "i", &progress); diff --git a/include/notification.h b/include/notification.h index 43e4ff4..6f1712d 100644 --- a/include/notification.h +++ b/include/notification.h @@ -34,6 +34,7 @@ struct mako_notification { char *app_name; char *app_icon; + char *sound_file; char *summary; char *body; int32_t requested_timeout; diff --git a/notification.c b/notification.c index a9f7d7c..dcf174f 100644 --- a/notification.c +++ b/notification.c @@ -45,6 +45,7 @@ void reset_notification(struct mako_notification *notif) { free(notif->app_name); free(notif->app_icon); + free(notif->sound_file); free(notif->summary); free(notif->body); free(notif->category); @@ -57,6 +58,7 @@ void reset_notification(struct mako_notification *notif) { notif->app_name = strdup(""); notif->app_icon = strdup(""); + notif->sound_file = strdup(""); notif->summary = strdup(""); notif->body = strdup(""); notif->category = strdup(""); @@ -97,6 +99,7 @@ void destroy_notification(struct mako_notification *notif) { free(notif->app_name); free(notif->app_icon); + free(notif->sound_file); free(notif->summary); free(notif->body); free(notif->category); From ff34988f068e88d2df2545fce7cdafb0e7b1a7c9 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Wed, 26 Jul 2023 17:00:48 -0400 Subject: [PATCH 2/3] Hints: Support 'sound-name' hint in makoctl list --- dbus/mako.c | 6 ++++++ dbus/xdg.c | 8 ++++++++ include/notification.h | 1 + notification.c | 3 +++ 4 files changed, 18 insertions(+) diff --git a/dbus/mako.c b/dbus/mako.c index 808e71c..b8b99fe 100644 --- a/dbus/mako.c +++ b/dbus/mako.c @@ -214,6 +214,12 @@ static int handle_list(sd_bus_message *msg, struct wl_list *list) { return ret; } + ret = sd_bus_message_append(reply, "{sv}", "sound-name", + "s", notif->sound_name); + if (ret < 0) { + return ret; + } + ret = sd_bus_message_open_container(reply, 'e', "sv"); if (ret < 0) { return ret; diff --git a/dbus/xdg.c b/dbus/xdg.c index 8de626b..a3fc199 100644 --- a/dbus/xdg.c +++ b/dbus/xdg.c @@ -237,6 +237,14 @@ static int handle_notify(sd_bus_message *msg, void *data, } free(notif->sound_file); notif->sound_file = strdup(sound_file); + } else if (strcmp(hint, "sound-name") == 0) { + const char *sound_name = NULL; + ret = sd_bus_message_read(msg, "v", "s", &sound_name); + if (ret < 0) { + return ret; + } + free(notif->sound_name); + notif->sound_name = strdup(sound_name); } else if (strcmp(hint, "value") == 0) { int32_t progress = 0; ret = sd_bus_message_read(msg, "v", "i", &progress); diff --git a/include/notification.h b/include/notification.h index 6f1712d..682767c 100644 --- a/include/notification.h +++ b/include/notification.h @@ -35,6 +35,7 @@ struct mako_notification { char *app_name; char *app_icon; char *sound_file; + char *sound_name; char *summary; char *body; int32_t requested_timeout; diff --git a/notification.c b/notification.c index dcf174f..f55d75c 100644 --- a/notification.c +++ b/notification.c @@ -46,6 +46,7 @@ void reset_notification(struct mako_notification *notif) { free(notif->app_name); free(notif->app_icon); free(notif->sound_file); + free(notif->sound_name); free(notif->summary); free(notif->body); free(notif->category); @@ -59,6 +60,7 @@ void reset_notification(struct mako_notification *notif) { notif->app_name = strdup(""); notif->app_icon = strdup(""); notif->sound_file = strdup(""); + notif->sound_name = strdup(""); notif->summary = strdup(""); notif->body = strdup(""); notif->category = strdup(""); @@ -100,6 +102,7 @@ void destroy_notification(struct mako_notification *notif) { free(notif->app_name); free(notif->app_icon); free(notif->sound_file); + free(notif->sound_name); free(notif->summary); free(notif->body); free(notif->category); From 10abe3cac45aaf08d2ffebfca67623ea187fe3ff Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Wed, 26 Jul 2023 17:33:43 -0400 Subject: [PATCH 3/3] Criteria: Add sound-name criteria --- criteria.c | 10 ++++++++++ include/criteria.h | 1 + include/types.h | 1 + mako.5.scd | 1 + types.c | 2 ++ 5 files changed, 15 insertions(+) diff --git a/criteria.c b/criteria.c index e435711..326eacc 100644 --- a/criteria.c +++ b/criteria.c @@ -35,6 +35,7 @@ void destroy_criteria(struct mako_criteria *criteria) { free(criteria->app_icon); free(criteria->category); free(criteria->desktop_entry); + free(criteria->sound_name); free(criteria->summary); regfree(&criteria->summary_pattern); free(criteria->body); @@ -108,6 +109,11 @@ bool match_criteria(struct mako_criteria *criteria, return false; } + if (spec.sound_name && + strcmp(criteria->sound_name, notif->sound_name) != 0) { + return false; + } + if (spec.summary && strcmp(criteria->summary, notif->summary) != 0) { return false; @@ -326,6 +332,10 @@ bool apply_criteria_field(struct mako_criteria *criteria, char *token) { } criteria->spec.group_index = true; return true; + } else if (strcmp(key, "sound-name") == 0) { + criteria->sound_name = strdup(value); + criteria->spec.sound_name = true; + return true; } else if (strcmp(key, "summary") == 0) { criteria->summary = strdup(value); criteria->spec.summary = true; diff --git a/include/criteria.h b/include/criteria.h index 2f03514..1426824 100644 --- a/include/criteria.h +++ b/include/criteria.h @@ -28,6 +28,7 @@ struct mako_criteria { enum mako_notification_urgency urgency; char *category; char *desktop_entry; + char *sound_name; char *summary; regex_t summary_pattern; char *body; diff --git a/include/types.h b/include/types.h index a42d80d..10d0343 100644 --- a/include/types.h +++ b/include/types.h @@ -50,6 +50,7 @@ struct mako_criteria_spec { bool urgency; bool category; bool desktop_entry; + bool sound_name; bool summary; bool summary_pattern; bool body; diff --git a/mako.5.scd b/mako.5.scd index b08dc81..0df82b1 100644 --- a/mako.5.scd +++ b/mako.5.scd @@ -303,6 +303,7 @@ The following fields are available in criteria: - _urgency_ (one of "low", "normal", "critical") - _category_ (string) - _desktop-entry_ (string) +- _sound-name_ (string) - _actionable_ (boolean) - _expiring_ (boolean) - _mode_ (string) diff --git a/types.c b/types.c index 9612d0f..9d59098 100644 --- a/types.c +++ b/types.c @@ -204,6 +204,8 @@ bool parse_criteria_spec(const char *string, struct mako_criteria_spec *out) { out->category = true; } else if (strcmp(token, "desktop-entry") == 0) { out->desktop_entry = true; + } else if (strcmp(token, "sound-name") == 0) { + out->sound_name = true; } else if (strcmp(token, "summary") == 0) { out->summary = true; } else if (strcmp(token, "body") == 0) {