Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hints: Support 'sound-file' and 'sound-name' hints in makoctl list #470

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions dbus/mako.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ 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_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;
Expand Down
16 changes: 16 additions & 0 deletions dbus/xdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ 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, "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);
Expand Down
1 change: 1 addition & 0 deletions include/criteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct mako_notification {

char *app_name;
char *app_icon;
char *sound_file;
char *sound_name;
char *summary;
char *body;
int32_t requested_timeout;
Expand Down
1 change: 1 addition & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mako.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ 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);
Expand All @@ -57,6 +59,8 @@ 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("");
Expand Down Expand Up @@ -97,6 +101,8 @@ 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);
Expand Down
2 changes: 2 additions & 0 deletions types.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down