summaryrefslogtreecommitdiffstats
path: root/swaybar/tray/host.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/tray/host.c')
-rw-r--r--swaybar/tray/host.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c
index c5756f17..30339fec 100644
--- a/swaybar/tray/host.c
+++ b/swaybar/tray/host.c
@@ -115,6 +115,25 @@ static bool register_to_watcher(struct swaybar_host *host) {
115 return ret >= 0; 115 return ret >= 0;
116} 116}
117 117
118static int handle_new_watcher(sd_bus_message *msg,
119 void *data, sd_bus_error *error) {
120 char *service, *old_owner, *new_owner;
121 int ret = sd_bus_message_read(msg, "sss", &service, &old_owner, &new_owner);
122 if (ret < 0) {
123 wlr_log(WLR_ERROR, "Failed to parse owner change message: %s", strerror(-ret));
124 return ret;
125 }
126
127 if (!*old_owner) {
128 struct swaybar_host *host = data;
129 if (strcmp(service, host->watcher_interface) == 0) {
130 register_to_watcher(host);
131 }
132 }
133
134 return 0;
135}
136
118bool init_host(struct swaybar_host *host, char *protocol, 137bool init_host(struct swaybar_host *host, char *protocol,
119 struct swaybar_tray *tray) { 138 struct swaybar_tray *tray) {
120 size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1; 139 size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1;
@@ -124,7 +143,7 @@ bool init_host(struct swaybar_host *host, char *protocol,
124 } 143 }
125 snprintf(host->watcher_interface, len, "org.%s.StatusNotifierWatcher", protocol); 144 snprintf(host->watcher_interface, len, "org.%s.StatusNotifierWatcher", protocol);
126 145
127 sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL; 146 sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL;
128 int ret = sd_bus_match_signal(tray->bus, &reg_slot, host->watcher_interface, 147 int ret = sd_bus_match_signal(tray->bus, &reg_slot, host->watcher_interface,
129 watcher_path, host->watcher_interface, 148 watcher_path, host->watcher_interface,
130 "StatusNotifierItemRegistered", handle_sni_registered, tray); 149 "StatusNotifierItemRegistered", handle_sni_registered, tray);
@@ -142,6 +161,15 @@ bool init_host(struct swaybar_host *host, char *protocol,
142 goto error; 161 goto error;
143 } 162 }
144 163
164 ret = sd_bus_match_signal(tray->bus, &watcher_slot, "org.freedesktop.DBus",
165 "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
166 handle_new_watcher, host);
167 if (ret < 0) {
168 wlr_log(WLR_ERROR, "Failed to subscribe to unregistering events: %s",
169 strerror(-ret));
170 goto error;
171 }
172
145 pid_t pid = getpid(); 173 pid_t pid = getpid();
146 size_t service_len = snprintf(NULL, 0, "org.%s.StatusNotifierHost-%d", 174 size_t service_len = snprintf(NULL, 0, "org.%s.StatusNotifierHost-%d",
147 protocol, pid) + 1; 175 protocol, pid) + 1;
@@ -163,12 +191,14 @@ bool init_host(struct swaybar_host *host, char *protocol,
163 191
164 sd_bus_slot_set_floating(reg_slot, 1); 192 sd_bus_slot_set_floating(reg_slot, 1);
165 sd_bus_slot_set_floating(unreg_slot, 1); 193 sd_bus_slot_set_floating(unreg_slot, 1);
194 sd_bus_slot_set_floating(watcher_slot, 1);
166 195
167 wlr_log(WLR_DEBUG, "Registered %s", host->service); 196 wlr_log(WLR_DEBUG, "Registered %s", host->service);
168 return true; 197 return true;
169error: 198error:
170 sd_bus_slot_unref(reg_slot); 199 sd_bus_slot_unref(reg_slot);
171 sd_bus_slot_unref(unreg_slot); 200 sd_bus_slot_unref(unreg_slot);
201 sd_bus_slot_unref(watcher_slot);
172 finish_host(host); 202 finish_host(host);
173 return false; 203 return false;
174} 204}