Here's the code:
#!/bin/bash
blDir='/sys/class/backlight/intel_backlight'
brightness=$(cat $blDir/brightness) # current brightness
max=$(cat $blDir/max_brightness) # maximum brightness
percentage=$(echo "scale=3; ($brightness/$max)*100" | bc | awk '{print int($1+0.5)}')
case $BLOCK_BUTTON in
# brightness up %5
4) echo $(( $brightness + ( $max / 20 ) )) > $blDir/brightness ;;
# brightness down %5
5) echo $(( $brightness - ( $max / 20 ) )) > $blDir/brightness ;;
esac
if (( $percentage >= 5 )); then
# output current brightness
echo "☀ $percentage%"
else
# output '0%' instead of '%'
echo "☀ 0%"
fi
This is a script to display and let me adjust the backlight brightness in my window manager's status bar. Whatever I echo from this script is what appears in the status bar. The asterisk-looking thing in the output is just a unicode sun icon. $BLOCK_BUTTON is the button that I press while the cursor is hovered over it, with 4 representing scroll-up and 5 representing scroll-down. It displays the current brighness just fine. Whenever I scroll up, it brings the brightness up from 0% to 55% in incraments of 5%. Then it goes to 59%, 64%, 69%, 74%, etc. Why is it doing this? Is this some sort of rounding error? How can I fix it so that it goes in incraments of 5% up to 100%.
- - , .
برچسب:
نویسنده: استخدام کار