| 1 | #!/usr/bin/env sh |
| 2 | # Source: https://github.com/albertnis/hypr-brightness |
| 3 | # Install ddcutil, and then enable access to i2c for your user |
| 4 | |
| 5 | # sudo gpasswd -a $USER i2c |
| 6 | # sudo modprobe i2c-dev |
| 7 | # echo i2c-dev | sudo tee /etc/modules-load.d/i2c-dev.conf |
| 8 | |
| 9 | set +e |
| 10 | |
| 11 | usage="Usage: $0 [+] or [-]" |
| 12 | |
| 13 | if [ "$#" -ne 1 ]; then |
| 14 | echo "No direction parameter provided" |
| 15 | echo "$usage" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | arg="$1" |
| 20 | |
| 21 | if [ "$arg" == "help" ] || [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then |
| 22 | echo "$usage" |
| 23 | exit 0 |
| 24 | fi |
| 25 | |
| 26 | if [ "$arg" != "+" ] && [ "$arg" != "-" ]; then |
| 27 | echo "Direction parameter must be '+' or '-'" |
| 28 | echo $usage |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | direction=$arg |
| 33 | |
| 34 | monitor_data=$(hyprctl monitors -j) |
| 35 | focused_name=$(echo $monitor_data | jq -r '.[] | select(.focused == true) | .name') |
| 36 | |
| 37 | if [ "$focused_name" == "eDP-1" ]; then |
| 38 | if [ "$direction" == "-" ]; then |
| 39 | brightnessctl -e4 -n2 set 5%- |
| 40 | else |
| 41 | brightnessctl -e4 -n2 set 5%+ |
| 42 | fi |
| 43 | else |
| 44 | focused_id=$(echo $monitor_data | jq -r '.[] | select(.focused == true) | .id') |
| 45 | ddcutil --enable-dynamic-sleep --display=$focused_id setvcp 10 $direction 15 |
| 46 | fi |