Skip to content

Commit

Permalink
Allow create_notification outside handle_notify
Browse files Browse the repository at this point in the history
This is a little bit wasteful but makes it safe to use notifications
created outside handle_notify without remembering to fill in all the
string fields.
  • Loading branch information
vilhalmer authored and emersion committed May 3, 2021
1 parent 1f6880d commit 4dc382e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dbus/xdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ static int handle_notify(sd_bus_message *msg, void *data,
return -1;
}

free(notif->app_name);
free(notif->app_icon);
free(notif->summary);
free(notif->body);
notif->app_name = strdup(app_name);
notif->app_icon = strdup(app_icon);
notif->summary = strdup(summary);
notif->body = strdup(body);

// These fields may not be filled, so make sure they're valid strings.
notif->category = strdup("");
notif->desktop_entry = strdup("");

ret = sd_bus_message_enter_container(msg, 'a', "s");
if (ret < 0) {
return ret;
Expand Down
14 changes: 8 additions & 6 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ void reset_notification(struct mako_notification *notif) {
free(notif->image_data);
}

notif->app_name = NULL;
notif->app_icon = NULL;
notif->summary = NULL;
notif->body = NULL;
notif->category = NULL;
notif->desktop_entry = NULL;
notif->app_name = strdup("");
notif->app_icon = strdup("");
notif->summary = strdup("");
notif->body = strdup("");
notif->category = strdup("");
notif->desktop_entry = strdup("");

notif->image_data = NULL;

destroy_icon(notif->icon);
Expand All @@ -73,6 +74,7 @@ struct mako_notification *create_notification(struct mako_state *state) {
++state->last_id;
notif->id = state->last_id;
wl_list_init(&notif->actions);
wl_list_init(&notif->link);
reset_notification(notif);

// Start ungrouped.
Expand Down

0 comments on commit 4dc382e

Please sign in to comment.