ashish-yadav11 / dwmblocks

Rewrite of dwmblocks with added features including clickability, cursor hinting and color.
ISC License
212 stars 30 forks source link

Updates the state of the block when the block is changed #18

Closed Infinemen closed 3 years ago

Infinemen commented 3 years ago

Hi , thank you for your great job.

I don't think the system sound needs to be updated from time to time. So I want to send a signal to update the block at the same time as I change the sound. The block is not updated at other times.

The first try is: In my configuration, left mouse click on the sound block will mute the system. I want to have the block show the mute icon at the same time.

Hear are the blocks.h file and volume setting file (Copied from Luke, modify little by yourself)

/*      pathu                                                pathc                           interval                           signal */
 { PATH("volume_dwm"),           PATH("volume_button"),          0,                                4},
case $1 in
1) pactl set-sink-mute @DEFAULT_SINK@ toggle && sigdwmblocks 4;;
esac
[ $(pulsemixer --get-mute) = "1" ] && echo 🔇 && exit

vol="$(pulsemixer --get-volume | awk '{print $1}' )"

if [ "$vol" -gt "70" ]; then
    icon="🔊"
elif [ "$vol" -lt "30" ]; then
    icon="🔈"
else
    icon="🔉"
fi

echo "$icon$vol "

The final version I want is to update the sound block once whenever I increase or decrease volume not just the icon. Usually I used to use shortcut keys to adjust the sound. I don't know what to do in this situation. Any suggestions would be highly appreciated, thanks in advance.

ashish-yadav11 commented 3 years ago

FYI the volume block is only updated on events related to sound change, like on changing volume, muting/unmuting, plugging/unplugging headphones, etc. This is achieved through the provided pulse_daemon.sh which listens for those events and notifies dwmblocks to update when there is an event. The problem with your approach will be that suppose the volume is changed by some means other than your keybindings, say be running pactl on the terminal or when plugging/unplugging headphones. Then the volume block will not show the changes. Anyway you can achieve what you want by adding a keybinding in dwm which is bound to a shell command which changes the volume and at the same time signals dwmblocks. By the way pulsemixer is very inefficient and you are using it twice. You can wrap up volume.sh provided in blocks folder. It will be much more efficient.