123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #!/bin/bash
- # This script increases/decreases brightness by a fixed increment specified in step.
- # This script relies on the script notify-send-improved.
- # i3-brightness-toggle - Increase and decrease brightness.
- # Copyright (C) 2017 Fabrizio Romano Genovese <egonigredo@gmail.com>
- # This copyrighted material is made available to anyone wishing to use,
- # modify, copy, or redistribute it subject to the terms and conditions of
- # the GNU General Public License v.2, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful, but WITHOUT
- # ANY WARRANTY expressed or implied, including the implied warranties of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- # Public License for more details.
- # You should have received a copy of the
- # GNU General Public License along with this program; if not,
- # see <http://www.gnu.org/licenses/>
- # Put this file in /bin/ or in /usr/bin. Do not forget to give
- # sudo chmod +x i3-blur
- # to make it executable.
- version=1.0
- step=10
- # Check if xbacklight and notify-send-improved are installed
- check_installed()
- {
- if [ ! -f /bin/notify-send-improved -a -f /bin/xbacklight ]; then
- echo "Notify-send-improved and/or xbacklight not present."
- echo "Please install them."
- exit 2
- fi
- }
- #Here we display the help messages and change the brightness using xbacklight
- if [[ "$#" -ge 2 ]]; then
- echo "Usage: $0 {-v, --version | -h --help}"
- exit 2
- elif [[ $# -le 1 ]]; then
- case $1 in
- -v | --version)
- echo "$0 - Version $version"
- exit 0
- ;;
- -h | --help)
- echo "- v, --version Display current version"
- echo "-h, --help Display this message"
- echo "up Increase brightness by $step%"
- echo "down Decrease brightness by $step%"
- exit 0
- ;;
- "up")
- check_installed
- xbacklight -steps 1 -time 0 -inc $step
- ;;
- "down")
- check_installed
- xbacklight -steps 1 -time 0 -dec $step
- ;;
- *)
- echo "Usage: $0 {up|down| -v, --version | -h, --help}"
- exit 2
- esac
- fi
- # Here we get the current brightness status from xbacklight
- # awk is necessary because xbacklight is not precise and the
- # resulting brightness number is always slightly less than it should,
- # by ~0.05 usually. If we were to use cut instead of awk the result would
- # then be aesthetically unpleasant.
- brightness=`xbacklight | awk '{printf("%d\n", $0+=$0<0?0:0.9)}'`
- # Selects the right icon for the notification
- # If the icon is not present it will not be displayed.
- brightnessicon="/usr/share/icons/Adwaita/32x32/status/display-brightness-symbolic.symbolic.png"
- # Here we read the notification id from a temporary file.
- # If the file doesn't exist, we initialize it the notification to 0
- # Then we send the notification out and we reassign the notification
- # id to the current one using tee
- #If the file exists, we just replace that notification id, that will
- # then stay the same and not increment.
- if [ ! -f "/tmp/brightness_notification_id.dat" ]; then
- notification_id="0"
- notification_id=$(notify-send-improved "Brightness Control" -i $muteicon --print-id -t 1000 "Brightness: $brightness" | tee /dev/tty)
- else
- notification_id=`cat /tmp/volume_notification_id.dat`
- notify-send-improved "Brightness Control" -i $brightnessicon --print-id --replace=$notification_id -t 1000 "Brightness: $brightness\%"
- fi
- # Here we write the notification id to a file. Next time we use this
- # script it will know if the notification has to be overwritten or not
- echo "${notification_id}" > /tmp/brightness_notification_id.dat
|