From 9a543cd81eebe9d8572ee45cf3b33486a5d03626 Mon Sep 17 00:00:00 2001 From: Ecys <73040912+Eccys@users.noreply.github.com> Date: Tue, 2 Jul 2024 02:21:51 +0000 Subject: [PATCH 1/2] Fixed inconsistent brightness Fixed brightness script not inc/dec in increments of 5 --- config/hypr/scripts/Brightness.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/config/hypr/scripts/Brightness.sh b/config/hypr/scripts/Brightness.sh index 8f9fbf2..5c455ef 100755 --- a/config/hypr/scripts/Brightness.sh +++ b/config/hypr/scripts/Brightness.sh @@ -7,12 +7,12 @@ notification_timeout=1000 # 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 +33,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" == "+5%" ]]; then + new_brightness=$((current_brightness + 5)) + elif [[ "$1" == "5%-" ]]; then + new_brightness=$((current_brightness - 5)) + 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 +62,10 @@ case "$1" in get_backlight ;; "--inc") - change_backlight "+10%" + change_backlight "+5%" ;; "--dec") - change_backlight "10%-" + change_backlight "5%-" ;; *) get_backlight From 24d18bef5a9353a94fbda43f5b09f151c3a82a17 Mon Sep 17 00:00:00 2001 From: Ecys <73040912+Eccys@users.noreply.github.com> Date: Tue, 2 Jul 2024 02:34:48 +0000 Subject: [PATCH 2/2] Added options to Brightness.sh Fixed error where you couldn't change the step value. Also added option to change step value to your liking. --- config/hypr/scripts/Brightness.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/hypr/scripts/Brightness.sh b/config/hypr/scripts/Brightness.sh index 5c455ef..c42837f 100755 --- a/config/hypr/scripts/Brightness.sh +++ b/config/hypr/scripts/Brightness.sh @@ -4,6 +4,7 @@ iDIR="$HOME/.config/swaync/icons" notification_timeout=1000 +step=10 # INCREASE/DECREASE BY THIS VALUE # Get brightness get_backlight() { @@ -37,10 +38,10 @@ change_backlight() { current_brightness=$(get_backlight) # Calculate new brightness - if [[ "$1" == "+5%" ]]; then - new_brightness=$((current_brightness + 5)) - elif [[ "$1" == "5%-" ]]; then - new_brightness=$((current_brightness - 5)) + 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 @@ -62,10 +63,10 @@ case "$1" in get_backlight ;; "--inc") - change_backlight "+5%" + change_backlight "+${step}%" ;; "--dec") - change_backlight "5%-" + change_backlight "${step}%-" ;; *) get_backlight