mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 20:44:01 +01:00
tray: when a service is lost, remove all matching items
Before, only the first matching item would be removed, which could leave stale items.
This commit is contained in:
parent
c07d91ca96
commit
8dbd4b98f7
@ -18,10 +18,6 @@ static int cmp_id(const void *item, const void *cmp_to) {
|
|||||||
return strcmp(item, 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,
|
static int handle_lost_service(sd_bus_message *msg,
|
||||||
void *data, sd_bus_error *error) {
|
void *data, sd_bus_error *error) {
|
||||||
char *service, *old_owner, *new_owner;
|
char *service, *old_owner, *new_owner;
|
||||||
@ -33,18 +29,23 @@ static int handle_lost_service(sd_bus_message *msg,
|
|||||||
|
|
||||||
if (!*new_owner) {
|
if (!*new_owner) {
|
||||||
struct swaybar_watcher *watcher = data;
|
struct swaybar_watcher *watcher = data;
|
||||||
int idx = list_seq_find(watcher->items,
|
for (int idx = 0; idx < watcher->items->length; ++idx) {
|
||||||
using_standard_protocol(watcher) ? cmp_id : cmp_service, service);
|
|
||||||
if (idx != -1) {
|
|
||||||
char *id = watcher->items->items[idx];
|
char *id = watcher->items->items[idx];
|
||||||
|
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);
|
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id);
|
||||||
list_del(watcher->items, idx);
|
list_del(watcher->items, idx--);
|
||||||
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
|
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,
|
||||||
"StatusNotifierItemUnregistered", "s", id);
|
"StatusNotifierItemUnregistered", "s", id);
|
||||||
free(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) {
|
if (idx != -1) {
|
||||||
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service);
|
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Host '%s'", service);
|
||||||
free(watcher->hosts->items[idx]);
|
free(watcher->hosts->items[idx]);
|
||||||
|
Loading…
Reference in New Issue
Block a user