aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorloner <2788892716@qq.com>2025-06-25 16:30:27 +0800
committerloner <2788892716@qq.com>2025-06-25 16:30:27 +0800
commit22193a572b2672f982fde74e8544c8881caccb6d (patch)
tree4f2cf8640c972f598a940d743e95b2fbb034b368
parentd96b5df977fdb452103db65df8e69a9bd2b95d23 (diff)
fix brightness
The brightness adjustment response is slow
-rwxr-xr-xconfig/hypr/scripts/Brightness.sh101
1 files changed, 48 insertions, 53 deletions
diff --git a/config/hypr/scripts/Brightness.sh b/config/hypr/scripts/Brightness.sh
index 8e5d525a..3e283c11 100755
--- a/config/hypr/scripts/Brightness.sh
+++ b/config/hypr/scripts/Brightness.sh
@@ -6,69 +6,64 @@ iDIR="$HOME/.config/swaync/icons"
notification_timeout=1000
step=10 # INCREASE/DECREASE BY THIS VALUE
-# Get brightness
-get_backlight() {
- brightnessctl -m | cut -d, -f4 | sed 's/%//'
+# Get current brightness as an integer (without %)
+get_brightness() {
+ brightnessctl -m | cut -d, -f4 | tr -d '%'
}
-# Get icons
-get_icon() {
- current=$(get_backlight)
- if [ "$current" -le "20" ]; then
- icon="$iDIR/brightness-20.png"
- elif [ "$current" -le "40" ]; then
- icon="$iDIR/brightness-40.png"
- elif [ "$current" -le "60" ]; then
- icon="$iDIR/brightness-60.png"
- elif [ "$current" -le "80" ]; then
- icon="$iDIR/brightness-80.png"
- else
- icon="$iDIR/brightness-100.png"
- fi
+# Determine the icon based on brightness level
+get_icon_path() {
+ local brightness=$1
+ local level=$(( (brightness + 19) / 20 * 20 )) # Round up to next 20
+ if (( level > 100 )); then
+ level=100
+ fi
+ echo "$ICON_DIR/brightness-${level}.png"
}
-# Notify
-notify_user() {
- notify-send -e -h string:x-canonical-private-synchronous:brightness_notif -h int:value:$current -u low -i $icon "Screen" "Brightness:$current%"
+# Send notification
+send_notification() {
+ local brightness=$1
+ local icon_path=$2
+
+ notify-send -e \
+ -h string:x-canonical-private-synchronous:brightness_notif \
+ -h int:value:"$brightness" \
+ -u low \
+ -i "$icon_path" \
+ "Screen" "Brightness: ${brightness}%"
}
-# Change brightness
-change_backlight() {
- local current_brightness
- current_brightness=$(get_backlight)
+# Change brightness and notify
+change_brightness() {
+ local delta=$1
+ local current new icon
+
+ current=$(get_brightness)
+ new=$((current + delta))
- # Calculate new brightness
- if [[ "$1" == "+${step}%" ]]; then
- new_brightness=$((current_brightness + step))
- elif [[ "$1" == "${step}%-" ]]; then
- new_brightness=$((current_brightness - step))
- fi
+ # Clamp between 5 and 100
+ (( new < 5 )) && new=5
+ (( new > 100 )) && new=100
- # Ensure new brightness is within valid range
- if (( new_brightness < 5 )); then
- new_brightness=5
- elif (( new_brightness > 100 )); then
- new_brightness=100
- fi
+ brightnessctl set "${new}%"
- brightnessctl set "${new_brightness}%"
- get_icon
- current=$new_brightness
- notify_user
+ icon=$(get_icon_path "$new")
+ send_notification "$new" "$icon"
}
-# Execute accordingly
+# Main
case "$1" in
- "--get")
- get_backlight
- ;;
- "--inc")
- change_backlight "+${step}%"
- ;;
- "--dec")
- change_backlight "${step}%-"
- ;;
- *)
- get_backlight
- ;;
+ "--get")
+ get_brightness
+ ;;
+ "--inc")
+ change_brightness "$STEP"
+ ;;
+ "--dec")
+ change_brightness "-$STEP"
+ ;;
+ *)
+ get_brightness
+ ;;
esac
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage