| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | iDIR="$HOME/.config/swaync/icons" |
| 6 | |
| 7 | |
| 8 | get_kbd_backlight() { |
| 9 | echo $(brightnessctl -d '*::kbd_backlight' -m | cut -d, -f4) |
| 10 | } |
| 11 | |
| 12 | |
| 13 | get_icon() { |
| 14 | current=$(get_kbd_backlight | sed 's/%//') |
| 15 | if [ "$current" -le "20" ]; then |
| 16 | icon="$iDIR/brightness-20.png" |
| 17 | elif [ "$current" -le "40" ]; then |
| 18 | icon="$iDIR/brightness-40.png" |
| 19 | elif [ "$current" -le "60" ]; then |
| 20 | icon="$iDIR/brightness-60.png" |
| 21 | elif [ "$current" -le "80" ]; then |
| 22 | icon="$iDIR/brightness-80.png" |
| 23 | else |
| 24 | icon="$iDIR/brightness-100.png" |
| 25 | fi |
| 26 | } |
| 27 | |
| 28 | notify_user() { |
| 29 | notify-send -e -h string:x-canonical-private-synchronous:brightness_notif -h int:value:$current -u low -i "$icon" "Keyboard" "Brightness:$current%" |
| 30 | } |
| 31 | |
| 32 | |
| 33 | change_kbd_backlight() { |
| 34 | brightnessctl -d *::kbd_backlight set "$1" && get_icon && notify_user |
| 35 | } |
| 36 | |
| 37 | |
| 38 | case "$1" in |
| 39 | "--get") |
| 40 | get_kbd_backlight |
| 41 | ;; |
| 42 | "--inc") |
| 43 | change_kbd_backlight "+30%" |
| 44 | ;; |
| 45 | "--dec") |
| 46 | change_kbd_backlight "30%-" |
| 47 | ;; |
| 48 | *) |
| 49 | get_kbd_backlight |
| 50 | ;; |
| 51 | esac |