From 2fd41fe9c85a866173fc2770ed7669871258bced Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:40:45 +0000 Subject: [PATCH] swaybar: set bar dirty on SNI event --- include/swaybar/bar.h | 2 ++ swaybar/bar.c | 2 +- swaybar/tray/host.c | 2 ++ swaybar/tray/item.c | 13 +++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index ad9422428..e377b8de7 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -88,6 +88,8 @@ bool bar_setup(struct swaybar *bar, const char *socket_path); void bar_run(struct swaybar *bar); void bar_teardown(struct swaybar *bar); +void set_bar_dirty(struct swaybar *bar); + /* * Determines whether the bar should be visible and changes it to be so. * If the current visibility of the bar is the different to what it should be, diff --git a/swaybar/bar.c b/swaybar/bar.c index ebb9bc124..4fd9c4888 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -124,7 +124,7 @@ static void destroy_layer_surface(struct swaybar_output *output) { output->frame_scheduled = false; } -static void set_bar_dirty(struct swaybar *bar) { +void set_bar_dirty(struct swaybar *bar) { struct swaybar_output *output; wl_list_for_each(output, &bar->outputs, link) { set_output_dirty(output); diff --git a/swaybar/tray/host.c b/swaybar/tray/host.c index 8ab896d4c..c5756f17c 100644 --- a/swaybar/tray/host.c +++ b/swaybar/tray/host.c @@ -4,6 +4,7 @@ #include #include #include +#include "swaybar/bar.h" #include "swaybar/tray/host.h" #include "swaybar/tray/item.h" #include "swaybar/tray/tray.h" @@ -56,6 +57,7 @@ static int handle_sni_unregistered(sd_bus_message *msg, void *data, wlr_log(WLR_DEBUG, "Unregistering Status Notifier Item '%s'", id); destroy_sni(tray->items->items[idx]); list_del(tray->items, idx); + set_bar_dirty(tray->bar); } return ret; } diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index 450b68828..98d3dc1f7 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c @@ -24,6 +24,13 @@ static bool sni_ready(struct swaybar_sni *sni) { sni->icon_name || sni->icon_pixmap); } +static void set_sni_dirty(struct swaybar_sni *sni) { + if (sni_ready(sni)) { + sni->min_size = sni->max_size = 0; // invalidate previous icon + set_bar_dirty(sni->tray->bar); + } +} + static int read_pixmap(sd_bus_message *msg, struct swaybar_sni *sni, const char *prop, list_t **dest) { int ret = sd_bus_message_enter_container(msg, 'a', "(iiay)"); @@ -124,6 +131,11 @@ static int get_property_callback(sd_bus_message *msg, void *data, *str = strdup(*str); } } + + if (strcmp(prop, "Status") == 0 || (sni->status && (sni->status[0] == 'N' ? + prop[0] == 'A' : strncmp(prop, "Icon", 4) == 0))) { + set_sni_dirty(sni); + } cleanup: free(data); return ret; @@ -185,6 +197,7 @@ static int handle_new_status(sd_bus_message *msg, void *data, sd_bus_error *erro free(sni->status); sni->status = strdup(status); wlr_log(WLR_DEBUG, "%s has new Status '%s'", sni->watcher_id, status); + set_sni_dirty(sni); } return ret; }