Closed thyeun closed 2 years ago
I was about to come submit a question, but this sounds roughly like what I am trying to do. Custom module which dynamically changes its appearance somehow (I was thinking of whether its possible to change the set of active classes, and then style them differently with css). Will watch this issue with interest.
@hossbeast prefer when toggle with key-binding, the appearance on the waybar (custom module) will change the color or when it format-disable
the color will change same like the on used on network
.
I see #network
and #network.disconnected
have different background-color
properties. But how does the #network
element gain and lose that .disconnected
class? Since network is a builtin module, I assume the code for the network module is doing it. But how can a custom module gain and lose classes dynamically? Perhaps in response to a signal?
Keybinding does not work for my case, the change I have in mind is not something initiated by the user (similar to how network connected -> disconnected is not initiated by the user, its just reacting to the state of the system)
@hossbeast your ideal might not work for my case, since i need an input to trigger (custom module) than only it will changing the state from on to off.
Any how, you build it out, and i will tester it, to find out the outcome. :))
You can use "return-type": "json"
and a script to supply the format and assign custom CSS classes to your modules. See https://github.com/Alexays/Waybar/wiki/Module:-Custom#module-custom-config-return-type and scroll down for ideas.
@thyeun Every 5 seconds this will check if wf-recorder
is running. The default style under #custom-recorder
will always apply to Off-air
. When wf-recorder
is running, format will return On-air
and #custom-recorder.enabled
will trigger. When wf-recorder
exits, the module will return Off-air
with the default style after the next script interval.
If you still need this to trigger on keybind, you can do so with signals. e.g. in Sway: bindsym <key> exec --no-startup-id "<command>; pkill -x -RTMIN+12 waybar"
which will run the command and also immediately run the script to update the module.
"custom/recorder": {
"format": "{}",
"exec": "~/.config/waybar/scripts/recorder",
"return-type": "json",
"signal": 12,
"interval": 5, // execute script every n seconds; adjust as desired
}
#!/bin/sh
if pgrep -x wf-recorder >/dev/null; then
printf '{"text":" On-air","class":"enabled"}';
else
printf '{"text":" Off-air"}';
fi
#custom-recorder {
/* default module style */
}
#custom-recorder.enabled {
color: red;
}
@hossbeast This might also be suitable for your case. You should be able to feed the module a custom format and CSS class for anything you can return via script.
@BoomerangNebula will try it out, and will feedback to you. thanks
Below are the code to appear the recording on-air and off-air. Stuck on the off-air part.
For the on-air part, once i trigger the keybinding of the recording, the
On-air
will appear withred color
on the waybar (this one working fine). The only part that cant possible to make it work, is the part Off-air
, if not trigger by the keybinding of the recording. it should stay on the waybar withblack color
, instead that, it hide from the bar.Below are the code (config & style.css)
With recording triggering
Without/Stop recording triggering