dotfiles/eww/scripts/toggle-brightness.sh

38 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# The Brightness (Before Turning Brightness Off)
STATUS_FILE="$HOME/.config/eww/scripts/.previous-brightness"
# Whether or not Brightness is Currently Off
STATUS_FILE2="$HOME/.config/eww/scripts/.brightness-off"
# The Brightness when Pressing the Button
BRIGHTNESS=$(brightnessctl | head -2 | tail +2 | awk '{print $4}' | tr -cd '[[:digit:]]')
# If Brightness is Turned off,
# Then Set the Brightnes to the
# Brightness at the time the Brightness was Turned Off
if $(cat $STATUS_FILE2); then
doas /usr/bin/brightnessctl s $(cat $STATUS_FILE)%
# Then Update the Value that is seen by Eww (Eww will now display than amount)
eww update brightness=$(cat $STATUS_FILE)
# If Eww Does not think think that the brightness is zero,
# Then make sure that the minimum slider width is 7px.
# If The Brightness (Before Turning Brighness off is zero, then leave the slider empty.
if [ $(eww get brightness) -ne 0 ]; then
eww update metric-brightness="non-zero"
fi
# The Brightness is no longer turned off.
# Next time the button is pressed, the other path will be taken.
echo false > $STATUS_FILE2
# If Brightness is not off, turn it off
else
eww update brightness=0
# Make the slider empty
eww update metric-brightness="zero"
# Send the Brightness when pressing the button to the status file,
# so that the program sets that value next time.
echo $BRIGHTNESS > $STATUS_FILE
# Tell the program that Brightness is Turned Off
echo true > $STATUS_FILE2
# Set the Brightness to 0
doas /usr/bin/brightnessctl s 0%
fi