modules/custom: Allow json fields as format specifiers
This PR changes the custom module in a (hopefully) backwards compatible way to allow using JSON fields as format specifiers.
As #404 and #676 have both been closed as non-working and I reeeaaally wanted this feature I spent a bit of time trying to figure out how to implement it. That's what I've come up with. There are probably some weird bugs caused by this code. Disclaimer: I am not a C++ developer.
For example
"custom/spotify": {
"format-alt": "{status_icon}",
"format-alt-click": "click-middle",
"exec": "/usr/bin/python3 ~/.config/waybar/scripts/mediaplayer.py --player spotify",
"format": "{status_icon} {artist} - {title}",
"return-type": "json",
"escape": true,
},
which currently outputs the following JSON as a single line, where text is only provided as a fallback and not necessary.
{
"player_name": "spotify",
"player_icon": "\uf1bc",
"artist": "Demoartist",
"title": "totally a real song",
"status": "Playing",
"status_icon": "\uf144",
"class": [
"spotify",
"playing"
],
"text": "Demoartist - totally a real song"
}
What has been tested:
- classes still work
- alt format works
- tooltips work
Percentage Icons are currently untested as I don't have a use case for those. I'd enjoy if somebody could test if they still work or provide a working example.
resolves #432
I'm really interested, this feature could open the doors to printing different "format" outputs like format-tooltip or format-alt in the future, isn't it?
@alohl669 With a small change to L140 (adding the formatting engine there) this should be possible I think.