The slowest step is: xrandr --verbose. So if you didn't have to fetch brightness using xrandr --verbose every time you try adjusting your brightness, the problem will be solved.
This can be achieved by the following workflow:
- Export the current brightness one-time (preferably, at start-up) using:
echoxrandr --verbose | grep -m 1 -i brightness | cut -f2 -d ' '`xrandr --verbose | grep -m 1 -i brightness | cut -f2 -d ' '` > brightness.txt - And every time you need the brightness read it from
brightness.txt - And every time you update the brightness also update the value at
brightness.txt
For example this is how I update my brightness:
#!/bin/bash
# BRIGHT=`xrandr --verbose | grep -m 1 -i brightness | cut -f2 -d ' '`
BRIGHT=`cat brightness.txt`
if [ "$1" = '+' ]; then
NEWBRIGHT=$(echo "$BRIGHT + 0.05" | bc)
if [ "$(echo "$NEWBRIGHT > 1.0" | bc)" -eq 1 ]; then
NEWBRIGHT='1.0'
fi
elif [ "$1" = '-' ]; then
NEWBRIGHT=$(echo "$BRIGHT - 0.05" | bc)
if [ "$(echo "$NEWBRIGHT < 0.0" | bc)" -eq 1 ]; then
NEWBRIGHT='0.0'
fi
fi
xrandr --output eDP-1 --brightness "$NEWBRIGHT"
echo "${NEWBRIGHT}" > brightness.txt