| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | iDIR="$HOME/.config/swaync/icons" |
| 6 | notification_timeout=1000 |
| 7 | step=10 |
| 8 | |
| 9 | |
| 10 | get_backlight() { |
| 11 | brightnessctl -m | cut -d, -f4 | sed 's/%//' |
| 12 | } |
| 13 | |
| 14 | |
| 15 | get_icon() { |
| 16 | current=$(get_backlight) |
| 17 | if [ "$current" -le "20" ]; then |
| 18 | icon="$iDIR/brightness-20.png" |
| 19 | elif [ "$current" -le "40" ]; then |
| 20 | icon="$iDIR/brightness-40.png" |
| 21 | elif [ "$current" -le "60" ]; then |
| 22 | icon="$iDIR/brightness-60.png" |
| 23 | elif [ "$current" -le "80" ]; then |
| 24 | icon="$iDIR/brightness-80.png" |
| 25 | else |
| 26 | icon="$iDIR/brightness-100.png" |
| 27 | fi |
| 28 | } |
| 29 | |
| 30 | |
| 31 | notify_user() { |
| 32 | notify-send -e -h string:x-canonical-private-synchronous:brightness_notif -h int:value:$current -u low -i $icon "Screen" "Brightness:$current%" |
| 33 | } |
| 34 | |
| 35 | |
| 36 | change_backlight() { |
| 37 | local current_brightness |
| 38 | current_brightness=$(get_backlight) |
| 39 | |
| 40 | |
| 41 | if [[ "$1" == "+${step}%" ]]; then |
| 42 | new_brightness=$((current_brightness + step)) |
| 43 | elif [[ "$1" == "${step}%-" ]]; then |
| 44 | new_brightness=$((current_brightness - step)) |
| 45 | fi |
| 46 | |
| 47 | |
| 48 | if (( new_brightness < 5 )); then |
| 49 | new_brightness=5 |
| 50 | elif (( new_brightness > 100 )); then |
| 51 | new_brightness=100 |
| 52 | fi |
| 53 | |
| 54 | brightnessctl set "${new_brightness}%" |
| 55 | get_icon |
| 56 | current=$new_brightness |
| 57 | notify_user |
| 58 | } |
| 59 | |
| 60 | |
| 61 | case "$1" in |
| 62 | "--get") |
| 63 | get_backlight |
| 64 | ;; |
| 65 | "--inc") |
| 66 | change_backlight "+${step}%" |
| 67 | ;; |
| 68 | "--dec") |
| 69 | change_backlight "${step}%-" |
| 70 | ;; |
| 71 | *) |
| 72 | get_backlight |
| 73 | ;; |
| 74 | esac |