From d95e84a49934373f2364289402e9544199a6f1a0 Mon Sep 17 00:00:00 2001 From: Chris Chamberlain Date: Sun, 27 Mar 2022 23:04:46 +1100 Subject: [PATCH] waybar integration: emit an array of classses rather than a single class (#103) * emit an array of classses rather than a single class turns out waybar doesn't like: "class": "foo bar" intead it wants: "class": ["foo", "bar"] * only print once --- src/client.vala | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client.vala b/src/client.vala index 1d0e39f..6d7a2e2 100644 --- a/src/client.vala +++ b/src/client.vala @@ -62,15 +62,20 @@ private void print_subscribe () { private void on_subscribe_waybar (uint count, bool dnd, bool cc_open) { string state = (dnd ? "dnd-" : "") + (count > 0 ? "notification" : "none"); - if (cc_open) state += " cc-open"; string tooltip = ""; if (count > 0) { tooltip = @"$(count) Notification" + (count > 1 ? "s" : ""); } - print ("{\"text\": \"\", \"alt\": \"%s\", \"tooltip\": \"%s\", \"class\": \"%s\"}\n", - state, tooltip, state); + string _class = @"\"$(state)\""; + if (cc_open) { + _class = @"[$(_class), \"cc-open\"]"; + } + + print ( + "{\"text\": \"\", \"alt\": \"%s\", \"tooltip\": \"%s\", \"class\": %s}\n", + state, tooltip, _class); } private void print_subscribe_waybar () {