aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2019-02-16 11:01:15 +0000
committerDrew DeVault <sir@cmpwn.com>2019-02-18 15:11:48 -0500
commit8dbd4b98f7b0c8c1c15fc7045b49a2957b993165 (patch)
tree2e7335a5b6962c4deca0afaab4d02a1a75ca5b65
parentc07d91ca96d9362f2dfe2757ddba31f3c812b63c (diff)
downloadsway-8dbd4b98f7b0c8c1c15fc7045b49a2957b993165.zip
sway-8dbd4b98f7b0c8c1c15fc7045b49a2957b993165.tar.gz
sway-8dbd4b98f7b0c8c1c15fc7045b49a2957b993165.tar.bz2
tray: when a service is lost, remove all matching items
Before, only the first matching item would be removed, which could leave stale items.
-rw-r--r--swaybar/tray/watcher.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/swaybar/tray/watcher.c b/swaybar/tray/watcher.c
index 3815107..432837d 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) {
return strcmp(item, cmp_to);
}
-static int cmp_service(const void *item, const void *cmp_to) {
- return strncmp(item, cmp_to, strlen(cmp_to));
-}
-
static int handle_lost_service(sd_bus_message *msg,
void *data, sd_bus_error *error) {
char *service, *old_owner, *new_owner;
@@ -33,18 +29,23 @@ static int handle_lost_service(sd_bus_message *msg,
if (!*new_owner) {
struct swaybar_watcher *watcher = data;
- int idx = list_seq_find(watcher->items,
- using_standard_protocol(watcher) ? cmp_id : cmp_service, service);
- if (idx != -1) {
+ for (int idx = 0; idx < watcher->items->length; ++idx) {
char *id = watcher->items->items[idx];
- sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id);
- list_del(watcher->items, idx);
- sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
- "StatusNotifierItemUnregistered", "s", id);
- free(id);
+ int cmp_res = using_standard_protocol(watcher) ?
+ cmp_id(id, service) : strncmp(id, service, strlen(service));
+ if (cmp_res == 0) {
+ sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id);
+ list_del(watcher->items, idx--);
+ sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
+ "StatusNotifierItemUnregistered", "s", id);
+ free(id);
+ if (using_standard_protocol(watcher)) {
+ break;
+ }
+ }
}
- idx = list_seq_find(watcher->hosts, cmp_id, service);
+ int idx = list_seq_find(watcher->hosts, cmp_id, service);
if (idx != -1) {
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service);
free(watcher->hosts->items[idx]);