diff options
author | Ian Fan <ianfan0@gmail.com> | 2019-02-16 11:01:15 +0000 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-02-16 21:49:16 +0100 |
commit | 26d6360febeb364a9c7e20844ad03c796e4f08c3 (patch) | |
tree | 9d2f0ec0189ffb443fffd24465c93e88c6a1adc4 /swaybar | |
parent | Check layout before getting pointer surface coords (diff) | |
download | sway-26d6360febeb364a9c7e20844ad03c796e4f08c3.tar.gz sway-26d6360febeb364a9c7e20844ad03c796e4f08c3.tar.zst sway-26d6360febeb364a9c7e20844ad03c796e4f08c3.zip |
tray: when a service is lost, remove all matching items
Before, only the first matching item would be removed, which could leave
stale items.
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/tray/watcher.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/swaybar/tray/watcher.c b/swaybar/tray/watcher.c index 38151071..432837d0 100644 --- a/swaybar/tray/watcher.c +++ b/swaybar/tray/watcher.c | |||
@@ -18,10 +18,6 @@ static int cmp_id(const void *item, const void *cmp_to) { | |||
18 | return strcmp(item, cmp_to); | 18 | return strcmp(item, cmp_to); |
19 | } | 19 | } |
20 | 20 | ||
21 | static int cmp_service(const void *item, const void *cmp_to) { | ||
22 | return strncmp(item, cmp_to, strlen(cmp_to)); | ||
23 | } | ||
24 | |||
25 | static int handle_lost_service(sd_bus_message *msg, | 21 | static int handle_lost_service(sd_bus_message *msg, |
26 | void *data, sd_bus_error *error) { | 22 | void *data, sd_bus_error *error) { |
27 | char *service, *old_owner, *new_owner; | 23 | char *service, *old_owner, *new_owner; |
@@ -33,18 +29,23 @@ static int handle_lost_service(sd_bus_message *msg, | |||
33 | 29 | ||
34 | if (!*new_owner) { | 30 | if (!*new_owner) { |
35 | struct swaybar_watcher *watcher = data; | 31 | struct swaybar_watcher *watcher = data; |
36 | int idx = list_seq_find(watcher->items, | 32 | for (int idx = 0; idx < watcher->items->length; ++idx) { |
37 | using_standard_protocol(watcher) ? cmp_id : cmp_service, service); | ||
38 | if (idx != -1) { | ||
39 | char *id = watcher->items->items[idx]; | 33 | char *id = watcher->items->items[idx]; |
40 | sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id); | 34 | int cmp_res = using_standard_protocol(watcher) ? |
41 | list_del(watcher->items, idx); | 35 | cmp_id(id, service) : strncmp(id, service, strlen(service)); |
42 | sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface, | 36 | if (cmp_res == 0) { |
43 | "StatusNotifierItemUnregistered", "s", id); | 37 | sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id); |
44 | free(id); | 38 | list_del(watcher->items, idx--); |
39 | sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface, | ||
40 | "StatusNotifierItemUnregistered", "s", id); | ||
41 | free(id); | ||
42 | if (using_standard_protocol(watcher)) { | ||
43 | break; | ||
44 | } | ||
45 | } | ||
45 | } | 46 | } |
46 | 47 | ||
47 | idx = list_seq_find(watcher->hosts, cmp_id, service); | 48 | int idx = list_seq_find(watcher->hosts, cmp_id, service); |
48 | if (idx != -1) { | 49 | if (idx != -1) { |
49 | sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service); | 50 | sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service); |
50 | free(watcher->hosts->items[idx]); | 51 | free(watcher->hosts->items[idx]); |