diff options
| author | Ja.KooLit <85185940+JaKooLit@users.noreply.github.com> | 2024-07-02 12:15:26 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-02 12:15:26 +0900 |
| commit | 4e4cafd8d5e0dfc9ea0aa3485c96e319c55bd82b (patch) | |
| tree | 601cf5007fa908d71b9e920c8c1da854d204a0a0 /config/hypr | |
| parent | fdeb6c069a8786eafd4eb813037288bac5e7f172 (diff) | |
| parent | 24d18bef5a9353a94fbda43f5b09f151c3a82a17 (diff) | |
Merge pull request #358 from Eccys/main
Adjusted Brightness.sh to add step option and fixed rounding error.
Diffstat (limited to 'config/hypr')
| -rwxr-xr-x | config/hypr/scripts/Brightness.sh | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/config/hypr/scripts/Brightness.sh b/config/hypr/scripts/Brightness.sh index 8f9fbf22..c42837f2 100755 --- a/config/hypr/scripts/Brightness.sh +++ b/config/hypr/scripts/Brightness.sh @@ -4,15 +4,16 @@ iDIR="$HOME/.config/swaync/icons" notification_timeout=1000 +step=10 # INCREASE/DECREASE BY THIS VALUE # Get brightness get_backlight() { - echo $(brightnessctl -m | cut -d, -f4) + brightnessctl -m | cut -d, -f4 | sed 's/%//' } # Get icons get_icon() { - current=$(get_backlight | sed 's/%//') + current=$(get_backlight) if [ "$current" -le "20" ]; then icon="$iDIR/brightness-20.png" elif [ "$current" -le "40" ]; then @@ -33,7 +34,27 @@ notify_user() { # Change brightness change_backlight() { - brightnessctl set "$1" -n && get_icon && notify_user + local current_brightness + current_brightness=$(get_backlight) + + # Calculate new brightness + if [[ "$1" == "+${step}%" ]]; then + new_brightness=$((current_brightness + step)) + elif [[ "$1" == "${step}%-" ]]; then + new_brightness=$((current_brightness - step)) + fi + + # Ensure new brightness is within valid range + if (( new_brightness < 0 )); then + new_brightness=0 + elif (( new_brightness > 100 )); then + new_brightness=100 + fi + + brightnessctl set "${new_brightness}%" + get_icon + current=$new_brightness + notify_user } # Execute accordingly @@ -42,10 +63,10 @@ case "$1" in get_backlight ;; "--inc") - change_backlight "+10%" + change_backlight "+${step}%" ;; "--dec") - change_backlight "10%-" + change_backlight "${step}%-" ;; *) get_backlight |
