aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2019-01-04 11:57:31 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2019-01-08 16:03:16 +0000
commitf87628e2abd98348a218de581ca93271a99d1591 (patch)
tree28709c3c22f084654c310778ac54182485c6e675 /swaybar
parentswaybar: handle SNI signals better (diff)
downloadsway-f87628e2abd98348a218de581ca93271a99d1591.tar.gz
sway-f87628e2abd98348a218de581ca93271a99d1591.tar.zst
sway-f87628e2abd98348a218de581ca93271a99d1591.zip
swaybar: improve tray logging
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/main.c2
-rw-r--r--swaybar/tray/host.c4
-rw-r--r--swaybar/tray/item.c57
3 files changed, 32 insertions, 31 deletions
diff --git a/swaybar/main.c b/swaybar/main.c
index 06238c62..fa99b1ba 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -76,7 +76,7 @@ int main(int argc, char **argv) {
76 if (debug) { 76 if (debug) {
77 wlr_log_init(WLR_DEBUG, NULL); 77 wlr_log_init(WLR_DEBUG, NULL);
78 } else { 78 } else {
79 wlr_log_init(WLR_ERROR, NULL); 79 wlr_log_init(WLR_INFO, NULL);
80 } 80 }
81 81
82 if (!swaybar.id) { 82 if (!swaybar.id) {
diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c
index 30339fec..cc8dd188 100644
--- a/swaybar/tray/host.c
+++ b/swaybar/tray/host.c
@@ -21,7 +21,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
21static void add_sni(struct swaybar_tray *tray, char *id) { 21static void add_sni(struct swaybar_tray *tray, char *id) {
22 int idx = list_seq_find(tray->items, cmp_sni_id, id); 22 int idx = list_seq_find(tray->items, cmp_sni_id, id);
23 if (idx == -1) { 23 if (idx == -1) {
24 wlr_log(WLR_DEBUG, "Registering Status Notifier Item '%s'", id); 24 wlr_log(WLR_INFO, "Registering Status Notifier Item '%s'", id);
25 struct swaybar_sni *sni = create_sni(id, tray); 25 struct swaybar_sni *sni = create_sni(id, tray);
26 if (sni) { 26 if (sni) {
27 list_add(tray->items, sni); 27 list_add(tray->items, sni);
@@ -54,7 +54,7 @@ static int handle_sni_unregistered(sd_bus_message *msg, void *data,
54 struct swaybar_tray *tray = data; 54 struct swaybar_tray *tray = data;
55 int idx = list_seq_find(tray->items, cmp_sni_id, id); 55 int idx = list_seq_find(tray->items, cmp_sni_id, id);
56 if (idx != -1) { 56 if (idx != -1) {
57 wlr_log(WLR_DEBUG, "Unregistering Status Notifier Item '%s'", id); 57 wlr_log(WLR_INFO, "Unregistering Status Notifier Item '%s'", id);
58 destroy_sni(tray->items->items[idx]); 58 destroy_sni(tray->items->items[idx]);
59 list_del(tray->items, idx); 59 list_del(tray->items, idx);
60 set_bar_dirty(tray->bar); 60 set_bar_dirty(tray->bar);
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c
index 44fd876c..0833dcb9 100644
--- a/swaybar/tray/item.c
+++ b/swaybar/tray/item.c
@@ -35,11 +35,12 @@ static int read_pixmap(sd_bus_message *msg, struct swaybar_sni *sni,
35 const char *prop, list_t **dest) { 35 const char *prop, list_t **dest) {
36 int ret = sd_bus_message_enter_container(msg, 'a', "(iiay)"); 36 int ret = sd_bus_message_enter_container(msg, 'a', "(iiay)");
37 if (ret < 0) { 37 if (ret < 0) {
38 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, strerror(-ret)); 38 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
39 return ret; 39 return ret;
40 } 40 }
41 41
42 if (sd_bus_message_at_end(msg, 0)) { 42 if (sd_bus_message_at_end(msg, 0)) {
43 wlr_log(WLR_DEBUG, "%s %s no. of icons = 0", sni->watcher_id, prop);
43 return ret; 44 return ret;
44 } 45 }
45 46
@@ -51,14 +52,14 @@ static int read_pixmap(sd_bus_message *msg, struct swaybar_sni *sni,
51 while (!sd_bus_message_at_end(msg, 0)) { 52 while (!sd_bus_message_at_end(msg, 0)) {
52 ret = sd_bus_message_enter_container(msg, 'r', "iiay"); 53 ret = sd_bus_message_enter_container(msg, 'r', "iiay");
53 if (ret < 0) { 54 if (ret < 0) {
54 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, strerror(-ret)); 55 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
55 goto error; 56 goto error;
56 } 57 }
57 58
58 int size; 59 int size;
59 ret = sd_bus_message_read(msg, "ii", NULL, &size); 60 ret = sd_bus_message_read(msg, "ii", NULL, &size);
60 if (ret < 0) { 61 if (ret < 0) {
61 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, strerror(-ret)); 62 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
62 goto error; 63 goto error;
63 } 64 }
64 65
@@ -66,7 +67,7 @@ static int read_pixmap(sd_bus_message *msg, struct swaybar_sni *sni,
66 size_t npixels; 67 size_t npixels;
67 ret = sd_bus_message_read_array(msg, 'y', &pixels, &npixels); 68 ret = sd_bus_message_read_array(msg, 'y', &pixels, &npixels);
68 if (ret < 0) { 69 if (ret < 0) {
69 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, strerror(-ret)); 70 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
70 goto error; 71 goto error;
71 } 72 }
72 73
@@ -80,6 +81,8 @@ static int read_pixmap(sd_bus_message *msg, struct swaybar_sni *sni,
80 } 81 }
81 list_free_items_and_destroy(*dest); 82 list_free_items_and_destroy(*dest);
82 *dest = pixmaps; 83 *dest = pixmaps;
84 wlr_log(WLR_DEBUG, "%s %s no. of icons = %d", sni->watcher_id, prop,
85 pixmaps->length);
83 86
84 return ret; 87 return ret;
85error: 88error:
@@ -104,15 +107,15 @@ static int get_property_callback(sd_bus_message *msg, void *data,
104 107
105 int ret; 108 int ret;
106 if (sd_bus_message_is_method_error(msg, NULL)) { 109 if (sd_bus_message_is_method_error(msg, NULL)) {
107 sd_bus_error err = *sd_bus_message_get_error(msg); 110 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop,
108 wlr_log(WLR_DEBUG, "Failed to get property %s: %s", prop, err.message); 111 sd_bus_message_get_error(msg)->message);
109 ret = -sd_bus_error_get_errno(&err); 112 ret = sd_bus_message_get_errno(msg);
110 goto cleanup; 113 goto cleanup;
111 } 114 }
112 115
113 ret = sd_bus_message_enter_container(msg, 'v', type); 116 ret = sd_bus_message_enter_container(msg, 'v', type);
114 if (ret < 0) { 117 if (ret < 0) {
115 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, strerror(-ret)); 118 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
116 goto cleanup; 119 goto cleanup;
117 } 120 }
118 121
@@ -128,12 +131,17 @@ static int get_property_callback(sd_bus_message *msg, void *data,
128 131
129 ret = sd_bus_message_read(msg, type, dest); 132 ret = sd_bus_message_read(msg, type, dest);
130 if (ret < 0) { 133 if (ret < 0) {
131 wlr_log(WLR_DEBUG, "Failed to read property %s: %s", prop, 134 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
132 strerror(-ret));
133 goto cleanup; 135 goto cleanup;
134 } else if (*type == 's' || *type == 'o') { 136 }
137
138 if (*type == 's' || *type == 'o') {
135 char **str = dest; 139 char **str = dest;
136 *str = strdup(*str); 140 *str = strdup(*str);
141 wlr_log(WLR_DEBUG, "%s %s = '%s'", sni->watcher_id, prop, *str);
142 } else if (*type == 'b') {
143 wlr_log(WLR_DEBUG, "%s %s = %s", sni->watcher_id, prop,
144 *(bool *)dest ? "true" : "false");
137 } 145 }
138 } 146 }
139 147
@@ -157,7 +165,7 @@ static void sni_get_property_async(struct swaybar_sni *sni, const char *prop,
157 sni->path, "org.freedesktop.DBus.Properties", "Get", 165 sni->path, "org.freedesktop.DBus.Properties", "Get",
158 get_property_callback, data, "ss", sni->interface, prop); 166 get_property_callback, data, "ss", sni->interface, prop);
159 if (ret < 0) { 167 if (ret < 0) {
160 wlr_log(WLR_DEBUG, "Failed to get property %s: %s", prop, strerror(-ret)); 168 wlr_log(WLR_ERROR, "%s %s: %s", sni->watcher_id, prop, strerror(-ret));
161 } 169 }
162} 170}
163 171
@@ -210,12 +218,12 @@ static int handle_new_status(sd_bus_message *msg, void *data, sd_bus_error *erro
210 char *status; 218 char *status;
211 int r = sd_bus_message_read(msg, "s", &status); 219 int r = sd_bus_message_read(msg, "s", &status);
212 if (r < 0) { 220 if (r < 0) {
213 wlr_log(WLR_ERROR, "Failed to read new status message: %s", strerror(-ret)); 221 wlr_log(WLR_ERROR, "%s new status error: %s", sni->watcher_id, strerror(-ret));
214 ret = r; 222 ret = r;
215 } else { 223 } else {
216 free(sni->status); 224 free(sni->status);
217 sni->status = strdup(status); 225 sni->status = strdup(status);
218 wlr_log(WLR_DEBUG, "%s has new status: %s", sni->watcher_id, status); 226 wlr_log(WLR_DEBUG, "%s has new status = '%s'", sni->watcher_id, status);
219 set_sni_dirty(sni); 227 set_sni_dirty(sni);
220 } 228 }
221 } else { 229 } else {
@@ -230,7 +238,7 @@ static void sni_match_signal(struct swaybar_sni *sni, sd_bus_slot **slot,
230 int ret = sd_bus_match_signal(sni->tray->bus, slot, sni->service, sni->path, 238 int ret = sd_bus_match_signal(sni->tray->bus, slot, sni->service, sni->path,
231 sni->interface, signal, callback, sni); 239 sni->interface, signal, callback, sni);
232 if (ret < 0) { 240 if (ret < 0) {
233 wlr_log(WLR_DEBUG, "Failed to subscribe to signal %s: %s", signal, 241 wlr_log(WLR_ERROR, "Failed to subscribe to signal %s: %s", signal,
234 strerror(-ret)); 242 strerror(-ret));
235 } 243 }
236} 244}
@@ -322,18 +330,11 @@ static void handle_click(struct swaybar_sni *sni, int x, int y,
322 char *orientation = (dir = 'U' || dir == 'D') ? "vertical" : "horizontal"; 330 char *orientation = (dir = 'U' || dir == 'D') ? "vertical" : "horizontal";
323 int sign = (dir == 'U' || dir == 'L') ? -1 : 1; 331 int sign = (dir == 'U' || dir == 'L') ? -1 : 1;
324 332
325 int ret = sd_bus_call_method_async(sni->tray->bus, NULL, sni->service, 333 sd_bus_call_method_async(sni->tray->bus, NULL, sni->service, sni->path,
326 sni->path, sni->interface, "Scroll", NULL, NULL, "is", 334 sni->interface, "Scroll", NULL, NULL, "is", delta*sign, orientation);
327 delta*sign, orientation);
328 if (ret < 0) {
329 wlr_log(WLR_DEBUG, "Failed to scroll on SNI: %s", strerror(-ret));
330 }
331 } else { 335 } else {
332 int ret = sd_bus_call_method_async(sni->tray->bus, NULL, sni->service, 336 sd_bus_call_method_async(sni->tray->bus, NULL, sni->service, sni->path,
333 sni->path, sni->interface, method, NULL, NULL, "ii", x, y); 337 sni->interface, method, NULL, NULL, "ii", x, y);
334 if (ret < 0) {
335 wlr_log(WLR_DEBUG, "Failed to click on SNI: %s", strerror(-ret));
336 }
337 } 338 }
338} 339}
339 340
@@ -345,7 +346,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
345static enum hotspot_event_handling icon_hotspot_callback( 346static enum hotspot_event_handling icon_hotspot_callback(
346 struct swaybar_output *output, struct swaybar_hotspot *hotspot, 347 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
347 int x, int y, enum x11_button button, void *data) { 348 int x, int y, enum x11_button button, void *data) {
348 wlr_log(WLR_DEBUG, "Clicked on Status Notifier Item '%s'", (char *)data); 349 wlr_log(WLR_DEBUG, "Clicked on %s", (char *)data);
349 350
350 struct swaybar_tray *tray = output->bar->tray; 351 struct swaybar_tray *tray = output->bar->tray;
351 int idx = list_seq_find(tray->items, cmp_sni_id, data); 352 int idx = list_seq_find(tray->items, cmp_sni_id, data);
@@ -359,7 +360,7 @@ static enum hotspot_event_handling icon_hotspot_callback(
359 int global_y = output->output_y + (top_bar ? config->gaps.top + y: 360 int global_y = output->output_y + (top_bar ? config->gaps.top + y:
360 (int) output->output_height - config->gaps.bottom - y); 361 (int) output->output_height - config->gaps.bottom - y);
361 362
362 wlr_log(WLR_DEBUG, "Guessing click at (%d, %d)", global_x, global_y); 363 wlr_log(WLR_DEBUG, "Guessing click position at (%d, %d)", global_x, global_y);
363 handle_click(sni, global_x, global_y, button, 1); // TODO get delta from event 364 handle_click(sni, global_x, global_y, button, 1); // TODO get delta from event
364 return HOTSPOT_IGNORE; 365 return HOTSPOT_IGNORE;
365 } else { 366 } else {