Skip to content
Merged
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
47 changes: 38 additions & 9 deletions dbus/mako.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,16 @@ static int handle_restore_action(sd_bus_message *msg, void *data,
return sd_bus_reply_method_return(msg, "");
}

static int handle_list(sd_bus_message *msg, struct wl_list *list) {
static int handle_list_for_each(sd_bus_message *reply, struct wl_list *list) {

sd_bus_message *reply = NULL;
int ret = sd_bus_message_new_method_return(msg, &reply);
if (ret < 0) {
return ret;
}

ret = sd_bus_message_open_container(reply, 'a', "a{sv}");
int ret = sd_bus_message_open_container(reply, 'a', "a{sv}");
if (ret < 0) {
return ret;
}

struct mako_notification *notif;
wl_list_for_each(notif, list, link) {
ret = sd_bus_message_open_container(reply, 'a', "{sv}");
int ret = sd_bus_message_open_container(reply, 'a', "{sv}");
if (ret < 0) {
return ret;
}
Expand Down Expand Up @@ -258,6 +252,21 @@ static int handle_list(sd_bus_message *msg, struct wl_list *list) {
return ret;
}

return 0;
}

static int handle_list(sd_bus_message *msg, struct wl_list *list) {
sd_bus_message *reply = NULL;
int ret = sd_bus_message_new_method_return(msg, &reply);
if (ret < 0) {
return ret;
}

ret = handle_list_for_each(reply, list);
if (ret < 0) {
return ret;
}

ret = sd_bus_send(NULL, reply, NULL);
if (ret < 0) {
return ret;
Expand Down Expand Up @@ -462,6 +471,25 @@ void emit_modes_changed(struct mako_state *state) {
sd_bus_emit_properties_changed(state->bus, service_path, service_interface, "Modes", NULL);
}


static int get_notifications(sd_bus *bus, const char *path,
const char *interface, const char *property,
sd_bus_message *reply, void *data,
sd_bus_error *ret_error) {
struct mako_state *state = data;

int ret = handle_list_for_each(reply, &state->notifications);
if (ret < 0) {
return ret;
}

return 0;
}

void emit_notifications_changed(struct mako_state *state) {
sd_bus_emit_properties_changed(state->bus, service_path, service_interface, "Notifications", NULL);
}

static const sd_bus_vtable service_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("DismissNotifications", "a{sv}", "", handle_dismiss, SD_BUS_VTABLE_UNPRIVILEGED),
Expand All @@ -474,6 +502,7 @@ static const sd_bus_vtable service_vtable[] = {
SD_BUS_METHOD("ListModes", "", "as", handle_list_modes, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetModes", "as", "", handle_set_modes, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_PROPERTY("Modes", "as", get_modes, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
SD_BUS_PROPERTY("Notifications", "aa{sv}", get_notifications, 0, SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
SD_BUS_VTABLE_END
};

Expand Down
2 changes: 2 additions & 0 deletions include/dbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ int init_dbus_xdg(struct mako_state *state);

void emit_modes_changed(struct mako_state *state);

void emit_notifications_changed(struct mako_state *state);

int init_dbus_mako(struct mako_state *state);

#endif
4 changes: 4 additions & 0 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ void close_notification(struct mako_notification *notif,
} else {
destroy_notification(notif);
}

emit_notifications_changed(notif->state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notif has already been freed here in case you don't want it added to the history.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed in 30d36f2.

}

struct mako_notification *get_notification(struct mako_state *state,
Expand Down Expand Up @@ -503,6 +505,8 @@ void insert_notification(struct mako_state *state, struct mako_notification *not
}

wl_list_insert(insert_node, &notif->link);

emit_notifications_changed(state);
}

// Iterate through all of the current notifications and group any that share
Expand Down