aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/tray/host.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/tray/host.c')
-rw-r--r--swaybar/tray/host.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c
index ddf2416d..eea2caa5 100644
--- a/swaybar/tray/host.c
+++ b/swaybar/tray/host.c
@@ -10,6 +10,7 @@
10#include "swaybar/tray/tray.h" 10#include "swaybar/tray/tray.h"
11#include "list.h" 11#include "list.h"
12#include "log.h" 12#include "log.h"
13#include "stringop.h"
13 14
14static const char *watcher_path = "/StatusNotifierWatcher"; 15static const char *watcher_path = "/StatusNotifierWatcher";
15 16
@@ -138,12 +139,10 @@ static int handle_new_watcher(sd_bus_message *msg,
138 139
139bool init_host(struct swaybar_host *host, char *protocol, 140bool init_host(struct swaybar_host *host, char *protocol,
140 struct swaybar_tray *tray) { 141 struct swaybar_tray *tray) {
141 size_t len = snprintf(NULL, 0, "org.%s.StatusNotifierWatcher", protocol) + 1; 142 host->watcher_interface = format_str("org.%s.StatusNotifierWatcher", protocol);
142 host->watcher_interface = malloc(len);
143 if (!host->watcher_interface) { 143 if (!host->watcher_interface) {
144 return false; 144 return false;
145 } 145 }
146 snprintf(host->watcher_interface, len, "org.%s.StatusNotifierWatcher", protocol);
147 146
148 sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL; 147 sd_bus_slot *reg_slot = NULL, *unreg_slot = NULL, *watcher_slot = NULL;
149 int ret = sd_bus_match_signal(tray->bus, &reg_slot, host->watcher_interface, 148 int ret = sd_bus_match_signal(tray->bus, &reg_slot, host->watcher_interface,
@@ -173,13 +172,10 @@ bool init_host(struct swaybar_host *host, char *protocol,
173 } 172 }
174 173
175 pid_t pid = getpid(); 174 pid_t pid = getpid();
176 size_t service_len = snprintf(NULL, 0, "org.%s.StatusNotifierHost-%d", 175 host->service = format_str("org.%s.StatusNotifierHost-%d", protocol, pid);
177 protocol, pid) + 1;
178 host->service = malloc(service_len);
179 if (!host->service) { 176 if (!host->service) {
180 goto error; 177 goto error;
181 } 178 }
182 snprintf(host->service, service_len, "org.%s.StatusNotifierHost-%d", protocol, pid);
183 ret = sd_bus_request_name(tray->bus, host->service, 0); 179 ret = sd_bus_request_name(tray->bus, host->service, 0);
184 if (ret < 0) { 180 if (ret < 0) {
185 sway_log(SWAY_DEBUG, "Failed to acquire service name: %s", strerror(-ret)); 181 sway_log(SWAY_DEBUG, "Failed to acquire service name: %s", strerror(-ret));