|
14 | 14 | static const char *service_path = "/fr/emersion/Mako";
|
15 | 15 | static const char *service_interface = "fr.emersion.Mako";
|
16 | 16 |
|
17 |
| -static int handle_dismiss_all_notifications(sd_bus_message *msg, void *data, |
| 17 | +static int handle_dismiss(sd_bus_message *msg, void *data, |
18 | 18 | sd_bus_error *ret_error) {
|
19 | 19 | struct mako_state *state = data;
|
20 | 20 |
|
21 |
| - close_all_notifications(state, MAKO_NOTIFICATION_CLOSE_DISMISSED); |
22 |
| - struct mako_surface *surface; |
23 |
| - |
24 |
| - wl_list_for_each(surface, &state->surfaces, link) { |
25 |
| - set_dirty(surface); |
26 |
| - } |
27 |
| - |
28 |
| - return sd_bus_reply_method_return(msg, ""); |
29 |
| -} |
30 |
| - |
31 |
| -static int handle_dismiss_group_notifications(sd_bus_message *msg, void *data, |
32 |
| - sd_bus_error *ret_error) { |
33 |
| - struct mako_state *state = data; |
| 21 | + uint32_t id = 0; |
| 22 | + int group = 0; |
| 23 | + int all = 0; |
| 24 | + int history = 1; // Keep history be default |
34 | 25 |
|
35 |
| - if (wl_list_empty(&state->notifications)) { |
36 |
| - goto done; |
| 26 | + int ret = sd_bus_message_enter_container(msg, 'a', "{sv}"); |
| 27 | + if (ret < 0) { |
| 28 | + return ret; |
37 | 29 | }
|
38 | 30 |
|
39 |
| - struct mako_notification *notif = |
40 |
| - wl_container_of(state->notifications.next, notif, link); |
41 |
| - |
42 |
| - struct mako_surface *surface = notif->surface; |
43 |
| - close_group_notifications(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED); |
44 |
| - set_dirty(surface); |
| 31 | + while (true) { |
| 32 | + ret = sd_bus_message_enter_container(msg, 'e', "sv"); |
| 33 | + if (ret < 0) { |
| 34 | + return ret; |
| 35 | + } else if (ret == 0) { |
| 36 | + break; |
| 37 | + } |
45 | 38 |
|
46 |
| -done: |
47 |
| - return sd_bus_reply_method_return(msg, ""); |
48 |
| -} |
| 39 | + const char *key = NULL; |
| 40 | + ret = sd_bus_message_read(msg, "s", &key); |
| 41 | + if (ret < 0) { |
| 42 | + return ret; |
| 43 | + } |
49 | 44 |
|
50 |
| -static int handle_dismiss_last_notification(sd_bus_message *msg, void *data, |
51 |
| - sd_bus_error *ret_error) { |
52 |
| - struct mako_state *state = data; |
| 45 | + if (strcmp(key, "id") == 0) { |
| 46 | + ret = sd_bus_message_read(msg, "v", "u", &id); |
| 47 | + } else if (strcmp(key, "group") == 0) { |
| 48 | + ret = sd_bus_message_read(msg, "v", "b", &group); |
| 49 | + } else if (strcmp(key, "history") == 0) { |
| 50 | + ret = sd_bus_message_read(msg, "v", "b", &history); |
| 51 | + } else if (strcmp(key, "all") == 0) { |
| 52 | + ret = sd_bus_message_read(msg, "v", "b", &all); |
| 53 | + } else { |
| 54 | + ret = sd_bus_message_skip(msg, "v"); |
| 55 | + } |
| 56 | + if (ret < 0) { |
| 57 | + return ret; |
| 58 | + } |
53 | 59 |
|
54 |
| - if (wl_list_empty(&state->notifications)) { |
55 |
| - goto done; |
| 60 | + ret = sd_bus_message_exit_container(msg); |
| 61 | + if (ret < 0) { |
| 62 | + return ret; |
| 63 | + } |
56 | 64 | }
|
57 | 65 |
|
58 |
| - struct mako_notification *notif = |
59 |
| - wl_container_of(state->notifications.next, notif, link); |
60 |
| - struct mako_surface *surface = notif->surface; |
61 |
| - close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true); |
62 |
| - set_dirty(surface); |
63 |
| - |
64 |
| -done: |
65 |
| - return sd_bus_reply_method_return(msg, ""); |
66 |
| -} |
67 |
| - |
68 |
| -static int handle_dismiss_notification(sd_bus_message *msg, void *data, |
69 |
| - sd_bus_error *ret_error) { |
70 |
| - struct mako_state *state = data; |
71 |
| - |
72 |
| - uint32_t id = 0; |
73 |
| - int dismiss_group = 0; |
74 |
| - int ret = sd_bus_message_read(msg, "ub", &id, &dismiss_group); |
75 |
| - if (ret < 0) { |
76 |
| - return ret; |
| 66 | + // These don't make sense together |
| 67 | + if (all && group) { |
| 68 | + return -EINVAL; |
| 69 | + } else if ((all || group) && id != 0) { |
| 70 | + return -EINVAL; |
77 | 71 | }
|
78 | 72 |
|
79 | 73 | struct mako_notification *notif;
|
80 | 74 | wl_list_for_each(notif, &state->notifications, link) {
|
81 | 75 | if (notif->id == id || id == 0) {
|
82 | 76 | struct mako_surface *surface = notif->surface;
|
83 |
| - if (dismiss_group) { |
84 |
| - close_group_notifications(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED); |
| 77 | + if (group) { |
| 78 | + close_group_notifications(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, history); |
| 79 | + } else if (all) { |
| 80 | + close_all_notifications(state, MAKO_NOTIFICATION_CLOSE_DISMISSED, history); |
85 | 81 | } else {
|
86 |
| - close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, true); |
| 82 | + close_notification(notif, MAKO_NOTIFICATION_CLOSE_DISMISSED, history); |
87 | 83 | }
|
88 | 84 | set_dirty(surface);
|
89 | 85 | break;
|
@@ -468,10 +464,7 @@ void emit_modes_changed(struct mako_state *state) {
|
468 | 464 |
|
469 | 465 | static const sd_bus_vtable service_vtable[] = {
|
470 | 466 | SD_BUS_VTABLE_START(0),
|
471 |
| - SD_BUS_METHOD("DismissAllNotifications", "", "", handle_dismiss_all_notifications, SD_BUS_VTABLE_UNPRIVILEGED), |
472 |
| - SD_BUS_METHOD("DismissGroupNotifications", "", "", handle_dismiss_group_notifications, SD_BUS_VTABLE_UNPRIVILEGED), |
473 |
| - SD_BUS_METHOD("DismissLastNotification", "", "", handle_dismiss_last_notification, SD_BUS_VTABLE_UNPRIVILEGED), |
474 |
| - SD_BUS_METHOD("DismissNotification", "ub", "", handle_dismiss_notification, SD_BUS_VTABLE_UNPRIVILEGED), |
| 467 | + SD_BUS_METHOD("DismissNotifications", "a{sv}", "", handle_dismiss, SD_BUS_VTABLE_UNPRIVILEGED), |
475 | 468 | SD_BUS_METHOD("InvokeAction", "us", "", handle_invoke_action, SD_BUS_VTABLE_UNPRIVILEGED),
|
476 | 469 | SD_BUS_METHOD("RestoreNotification", "", "", handle_restore_action, SD_BUS_VTABLE_UNPRIVILEGED),
|
477 | 470 | SD_BUS_METHOD("ListNotifications", "", "aa{sv}", handle_list_notifications, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
0 commit comments