ErikReider / SwayNotificationCenter

A simple GTK based notification daemon for SwayWM
GNU General Public License v3.0
1.3k stars 62 forks source link

Waybar subscription missed opportunity #141

Closed carlosV2 closed 2 years ago

carlosV2 commented 2 years ago

Hi,

I just replaced mako with swaync and, so far, I love it.

I think there is tho a missed opportunity on the waybar subscription. You see, this is the output I'm getting:

$ swaync-client -swb
{"text": "", "alt": "none", "tooltip": "", "class": "none"}
{"text": "", "alt": "notification", "tooltip": "1 Notification", "class": "notification"}
{"text": "", "alt": "notification", "tooltip": "2 Notifications", "class": "notification"}
{"text": "", "alt": "notification", "tooltip": "3 Notifications", "class": "notification"}
{"text": "", "alt": "notification", "tooltip": "4 Notifications", "class": "notification"}

This is really cool but I would like to have the number of notifications displayed in the waybar too and it would be as easy as including the number only in the text field too. Ultimately, it is up to the user to show the number or not. If the README example is followed as is, it would still not show the number as {} is missing in the format field.

I'll try to add the number there with a bash/python script although I'm pretty sure it should be pretty straight forward to return it from the swaync-client too. If you point me to the right files, I can attempt a PR (provided you like this option, of course).

Thanks for a great project!

carlosV2 commented 2 years ago

If anyone is interested on this, I've managed to compose a jq query that does exacly this:

$ swaync-client -swb | jq '.text=(.tooltip|match("\\d+").string//"0")'

If you are planning to plug this command into waybar, you need to add the following flags to jq:

Here is a working and minimal waybar configuration with all this in mind:

"custom/notifications": {
   "format": "{}",
   "return-type": "json",
    "exec": "swaync-client -swb | jq -c -M --unbuffered '.text=(.tooltip|match(\"\\\\d+\").string//\"0\")'",
}
ErikReider commented 2 years ago

Great suggestion! I don't think that I'll have any time to add this but here's the swaync-client file src/client.vala specifically these lines: https://github.com/ErikReider/SwayNotificationCenter/blob/440ca813c78424e933977fec87d007f1c6fee0c9/src/client.vala#L77-L93

carlosV2 commented 2 years ago

Hi @ErikReider,

Thanks for your help. I've just created a PR with this silly change.

Thank you!