Nicer waybar notifications (paired with .dotfiles commit)

This commit is contained in:
John Mertz 2024-01-31 21:20:58 -07:00
parent 25e3e809b4
commit 1cd1f72809
2 changed files with 109 additions and 0 deletions

52
waybar/waybar-backlight.sh Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash
LOCK=/tmp/brightness-lock
if [ -e $LOCK ]; then
exit
fi
touch $LOCK
if [ -z $1 ]; then
ACTION="info"
elif [ $1 == 'up' ]; then
ACTION="set +1%"
elif [ $1 == 'down' ]; then
ACTION="set 1%-"
else
echo "Invalid argument $1"
fi
if [ -e /tmp/brightness-notification ]; then
NOTIFY_ID=$(cat /tmp/brightness-notification)
if [ -z /tmp/brightness-notification ]; then
rm /tmp/brightness-notification
fi
fi
BRIGHTNESS=$(brightnessctl info | grep Current | sed -r 's/.*\((1?[0-9]?[0-9])%\).*/\1/')
if [[ $ACTION != 'set +1%' ]] && [[ $BRIGHTNESS -eq 1 ]]; then
ACTION="info"
else
BRIGHTNESS=$(brightnessctl $ACTION | grep Current | sed -r 's/.*\((1?[0-9]?[0-9])%\).*/\1/')
if [[ $BRIGHTNESS -le 20 ]]; then
ICON='-low'
elif [[ $BRIGHTNESS -le 40 ]]; then
ICON='-low'
elif [[ $BRIGHTNESS -le 60 ]]; then
ICON='-medium'
elif [[ $BRIGHTNESS -le 80 ]]; then
ICON='-high'
else
ICON='-full'
fi
fi
if [ -n $NOTIFY_ID ]; then
NOTIFY_ID=$(notify-send --category=backlight --urgency=low --hint=int:value:$BRIGHTNESS --icon=${HOME}/.icons/Gruvbox/48x48@2x/status/notification-display-brightness${ICON}.svg -p -t 1000 -r $NOTIFY_ID Backlight ${BRIGHTNESS}%)
else
NOTIFY_ID=$(notify-send --category=backlight --urgency=low --hint=int:value:$BRIGHTNESS --icon=${HOME}/.icons/Gruvbox/48x48@2x/devices/notification-display-brightness${ICON}.svg -p -t 1000 Backlight ${BRIGHTNESS}%)
fi
echo $NOTIFY_ID > /tmp/brightness-notification
echo $BRIGHTNESS > ${HOME}/.spool/last_brightness
rm $LOCK

57
waybar/waybar-volume.sh Executable file
View File

@ -0,0 +1,57 @@
#!/bin/bash
LOCK=/tmp/volume-lock
if [ -e $LOCK ]; then
exit
fi
touch $LOCK
SINK=$(pactl get-default-sink)
if [ -z $1 ]; then
ACTION="get-sink-volume $SINK"
elif [ $1 == 'up' ]; then
ACTION="set-sink-volume $SINK +1%"
elif [ $1 == 'down' ]; then
ACTION="set-sink-volume $SINK -1%"
else
echo "Invalid argument $1"
fi
if [ -e /tmp/volume-notification ]; then
NOTIFY_ID=$(cat /tmp/volume-notification)
if [ -z /tmp/volume-notification ]; then
rm /tmp/volume-notification
fi
fi
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
if [[ $ACTION != "set-sink-volume $SINK +1%" ]] && [[ $VOLUME -eq 0 ]]; then
echo $VOLUME > ${HOME}/.spool/last_volume
elif [[ $ACTION != "set-sink-volume $SINK -1%" ]] && [[ $VOLUME -eq 150 ]]; then
echo $VOLUME > ${HOME}/.spool/last_volume
elif [[ $ACTION != "get-sink-volume $SINK" ]]; then
pactl $ACTION
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
fi
if [[ $VOLUME -eq 0 ]]; then
ICON='-off'
elif [[ $VOLUME -le 34 ]]; then
ICON='-low'
elif [[ $VOLUME -le 67 ]]; then
ICON='-medium'
else
ICON='-high'
fi
if [[ -z $NOTIFY_ID ]]; then
NOTIFY_ID=$(notify-send --category=volume --urgency=low --hint=int:value:$VOLUME --icon=${HOME}/.icons/Gruvbox/48x48@2x/devices/notification-audio-volume${ICON}.svg -p -t 1000 Volume ${VOLUME}%)
else
NOTIFY_ID=$(notify-send --category=volume --urgency=low --hint=int:value:$VOLUME --icon=${HOME}/.icons/Gruvbox/48x48@2x/status/notification-audio-volume${ICON}.svg -p -r $NOTIFY_ID -t 1000 Volume ${VOLUME}%)
fi
VOLUME=$(pactl get-sink-volume $SINK | grep Volume | sed -r 's/.* (1?[0-9]?[0-9])% \/.*/\1/')
echo $NOTIFY_ID > /tmp/volume-notification
echo $VOLUME > ${HOME}/.spool/last_volume
rm /tmp/volume-lock