aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/tray
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/tray')
-rw-r--r--swaybar/tray/dbus.c8
-rw-r--r--swaybar/tray/icon.c2
-rw-r--r--swaybar/tray/sni.c10
-rw-r--r--swaybar/tray/sni_watcher.c14
-rw-r--r--swaybar/tray/tray.c17
5 files changed, 39 insertions, 12 deletions
diff --git a/swaybar/tray/dbus.c b/swaybar/tray/dbus.c
index 22531aa6..8e719fd9 100644
--- a/swaybar/tray/dbus.c
+++ b/swaybar/tray/dbus.c
@@ -1,4 +1,4 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 700
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <stdint.h> 4#include <stdint.h>
@@ -108,7 +108,7 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *_data) {
108 108
109 timer_settime(*timer, 0, &time, NULL); 109 timer_settime(*timer, 0, &time, NULL);
110 110
111 dbus_timeout_set_data(timeout, timer, free); 111 dbus_timeout_set_data(timeout, timer, NULL);
112 112
113 sway_log(L_DEBUG, "Adding DBus timeout. Interval: %ds %dms", interval_sec, interval_msec); 113 sway_log(L_DEBUG, "Adding DBus timeout. Interval: %ds %dms", interval_sec, interval_msec);
114 add_timer(*timer, dispatch_timeout, timeout); 114 add_timer(*timer, dispatch_timeout, timeout);
@@ -121,6 +121,8 @@ static void remove_timeout(DBusTimeout *timeout, void *_data) {
121 121
122 if (timer) { 122 if (timer) {
123 remove_timer(*timer); 123 remove_timer(*timer);
124 timer_delete(*timer);
125 free(timer);
124 } 126 }
125} 127}
126 128
@@ -136,7 +138,7 @@ static void dispatch_status(DBusConnection *connection, DBusDispatchStatus new_s
136/* Public functions below */ 138/* Public functions below */
137 139
138void dispatch_dbus() { 140void dispatch_dbus() {
139 if (!should_dispatch) { 141 if (!should_dispatch || !conn) {
140 return; 142 return;
141 } 143 }
142 144
diff --git a/swaybar/tray/icon.c b/swaybar/tray/icon.c
index 1c69ba72..c146bf32 100644
--- a/swaybar/tray/icon.c
+++ b/swaybar/tray/icon.c
@@ -1,4 +1,4 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 700
2#define _POSIX_C_SOURCE 200809L 2#define _POSIX_C_SOURCE 200809L
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
diff --git a/swaybar/tray/sni.c b/swaybar/tray/sni.c
index 0c46d5c0..c9d00657 100644
--- a/swaybar/tray/sni.c
+++ b/swaybar/tray/sni.c
@@ -160,6 +160,7 @@ static void reply_icon(DBusPendingCall *pending, void *_data) {
160 dirty = true; 160 dirty = true;
161 161
162 dbus_message_unref(reply); 162 dbus_message_unref(reply);
163 dbus_pending_call_unref(pending);
163 return; 164 return;
164 } else { 165 } else {
165 sway_log(L_ERROR, "Could not create image surface"); 166 sway_log(L_ERROR, "Could not create image surface");
@@ -170,6 +171,7 @@ bail:
170 if (reply) { 171 if (reply) {
171 dbus_message_unref(reply); 172 dbus_message_unref(reply);
172 } 173 }
174 dbus_pending_call_unref(pending);
173 sway_log(L_ERROR, "Could not get icon from item"); 175 sway_log(L_ERROR, "Could not get icon from item");
174 return; 176 return;
175} 177}
@@ -266,6 +268,7 @@ static void reply_icon_name(DBusPendingCall *pending, void *_data) {
266 dirty = true; 268 dirty = true;
267 269
268 dbus_message_unref(reply); 270 dbus_message_unref(reply);
271 dbus_pending_call_unref(pending);
269 return; 272 return;
270 } 273 }
271 274
@@ -273,6 +276,7 @@ bail:
273 if (reply) { 276 if (reply) {
274 dbus_message_unref(reply); 277 dbus_message_unref(reply);
275 } 278 }
279 dbus_pending_call_unref(pending);
276 // Now try the pixmap 280 // Now try the pixmap
277 send_icon_msg(item); 281 send_icon_msg(item);
278 return; 282 return;
@@ -413,6 +417,12 @@ static void get_unique_name(struct StatusNotifierItem *item) {
413} 417}
414 418
415struct StatusNotifierItem *sni_create(const char *name) { 419struct StatusNotifierItem *sni_create(const char *name) {
420 // Make sure `name` is well formed
421 if (!dbus_validate_bus_name(name, NULL)) {
422 sway_log(L_INFO, "Name (%s) is not a bus name. We cannot create an item.", name);
423 return NULL;
424 }
425
416 struct StatusNotifierItem *item = malloc(sizeof(struct StatusNotifierItem)); 426 struct StatusNotifierItem *item = malloc(sizeof(struct StatusNotifierItem));
417 item->name = strdup(name); 427 item->name = strdup(name);
418 item->unique_name = NULL; 428 item->unique_name = NULL;
diff --git a/swaybar/tray/sni_watcher.c b/swaybar/tray/sni_watcher.c
index 388e181d..86453e70 100644
--- a/swaybar/tray/sni_watcher.c
+++ b/swaybar/tray/sni_watcher.c
@@ -150,10 +150,14 @@ static void register_item(DBusConnection *connection, DBusMessage *message) {
150 sway_log(L_ERROR, "Error parsing method args: %s\n", error.message); 150 sway_log(L_ERROR, "Error parsing method args: %s\n", error.message);
151 } 151 }
152 152
153 name = strdup(name);
154 sway_log(L_INFO, "RegisterStatusNotifierItem called with \"%s\"\n", name); 153 sway_log(L_INFO, "RegisterStatusNotifierItem called with \"%s\"\n", name);
155 154
156 // Don't add duplicate or not real item 155 // Don't add duplicate or not real item
156 if (!dbus_validate_bus_name(name, NULL)) {
157 sway_log(L_INFO, "This item is not valid, we cannot keep track of it.");
158 return;
159 }
160
157 if (list_seq_find(items, (int (*)(const void *, const void *))strcmp, name) != -1) { 161 if (list_seq_find(items, (int (*)(const void *, const void *))strcmp, name) != -1) {
158 return; 162 return;
159 } 163 }
@@ -161,7 +165,7 @@ static void register_item(DBusConnection *connection, DBusMessage *message) {
161 return; 165 return;
162 } 166 }
163 167
164 list_add(items, name); 168 list_add(items, strdup(name));
165 item_registered_signal(connection, name); 169 item_registered_signal(connection, name);
166 170
167 // It's silly, but xembedsniproxy wants a reply for this function 171 // It's silly, but xembedsniproxy wants a reply for this function
@@ -184,6 +188,12 @@ static void register_host(DBusConnection *connection, DBusMessage *message) {
184 sway_log(L_INFO, "RegisterStatusNotifierHost called with \"%s\"\n", name); 188 sway_log(L_INFO, "RegisterStatusNotifierHost called with \"%s\"\n", name);
185 189
186 // Don't add duplicate or not real host 190 // Don't add duplicate or not real host
191 if (!dbus_validate_bus_name(name, NULL)) {
192 sway_log(L_INFO, "This item is not valid, we cannot keep track of it.");
193 return;
194 }
195
196
187 if (list_seq_find(hosts, (int (*)(const void *, const void *))strcmp, name) != -1) { 197 if (list_seq_find(hosts, (int (*)(const void *, const void *))strcmp, name) != -1) {
188 return; 198 return;
189 } 199 }
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c
index 00f1a44f..91c3af06 100644
--- a/swaybar/tray/tray.c
+++ b/swaybar/tray/tray.c
@@ -1,4 +1,4 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 700
2#include <unistd.h> 2#include <unistd.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
@@ -90,13 +90,16 @@ static void get_items_reply(DBusPendingCall *pending, void *_data) {
90 90
91 struct StatusNotifierItem *item = sni_create(name); 91 struct StatusNotifierItem *item = sni_create(name);
92 92
93 sway_log(L_DEBUG, "Item registered with host: %s", name); 93 if (item) {
94 list_add(tray->items, item); 94 sway_log(L_DEBUG, "Item registered with host: %s", name);
95 dirty = true; 95 list_add(tray->items, item);
96 dirty = true;
97 }
96 } 98 }
97 99
98bail: 100bail:
99 dbus_message_unref(reply); 101 dbus_message_unref(reply);
102 dbus_pending_call_unref(pending);
100 return; 103 return;
101} 104}
102static void get_items() { 105static void get_items() {
@@ -141,8 +144,10 @@ static DBusHandlerResult signal_handler(DBusConnection *connection,
141 if (list_seq_find(tray->items, sni_str_cmp, name) == -1) { 144 if (list_seq_find(tray->items, sni_str_cmp, name) == -1) {
142 struct StatusNotifierItem *item = sni_create(name); 145 struct StatusNotifierItem *item = sni_create(name);
143 146
144 list_add(tray->items, item); 147 if (item) {
145 dirty = true; 148 list_add(tray->items, item);
149 dirty = true;
150 }
146 } 151 }
147 152
148 return DBUS_HANDLER_RESULT_HANDLED; 153 return DBUS_HANDLER_RESULT_HANDLED;