Commit 7e704f08 authored by sebt3's avatar sebt3

Improved brightness script

parent f0381a86
#!/bin/sh
if [ $1 = "screen" ]; then
if [ $2 = "set" ]; then
minbright=1
maxbright="$(cat /sys/devices/platform/backlight/backlight/backlight/max_brightness)"
curbright="$(cat /sys/devices/platform/backlight/backlight/backlight/actual_brightness)"
if [ ! $3 ]; then
newbright=$(zenity --scale --text "pick a number" --min-value=$minbright --max-value=$maxbright --value=$curbright --step 1);
else
newbright=$3
fi
if [ $newbright ]; then
if [ $newbright -le $minbright ]; then newbright=$minbright; fi
if [ $newbright -ge $maxbright ]; then newbright=$maxbright; fi
echo $newbright > /sys/devices/platform/backlight/backlight/backlight/brightness
fi
elif [ $2 = "up" ]; then
maxbright="$(cat /sys/devices/platform/backlight/backlight/backlight/max_brightness)"
curbright="$(cat /sys/devices/platform/backlight/backlight/backlight/actual_brightness)"
if [ ! $3 ]; then
if [ $curbright = $maxbright ]; then
newbright=$maxbright
else
newbright=$(($curbright+1))
fi
else
newbright=$(($curbright+$3))
if [ $newbright -gt $maxbright ]; then
newbright=$maxbright
fi
fi
echo $newbright > /sys/devices/platform/backlight/backlight/backlight/brightness
elif [ $2 = "down" ]; then
minbright=0
curbright="$(cat /sys/devices/platform/backlight/backlight/backlight/actual_brightness)"
if [ ! $3 ]; then
if [ "$curbright" = "$minbright" ]; then
newbright=$minbright
else
newbright=$(($curbright-1))
fi
else
newbright=$(($curbright-$3))
if [ $newbright -lt $minbright ]; then
newbright=$minbright
fi
fi
echo $newbright > /sys/devices/platform/backlight/backlight/backlight/brightness
elif [ $2 = "toggle" ]; then
curbright="$(cat /sys/devices/platform/backlight/backlight/backlight/actual_brightness)"
if [ $curbright = 0 ]; then
newbright="$( cat /var/lib/pyra/screen-toggle-value)"
else
echo $curbright > /var/lib/pyra/screen-toggle-value
newbright=0
fi
echo $newbright > /sys/devices/platform/backlight/backlight/backlight/brightness
help() {
cat <<ENDHELP
$0 {screen|keyboard} {up|down|set|toggle} [value]
ENDHELP
}
case "$1" in
screen|[sS][Cc][rR]*)
FTOG="/var/lib/pyra/screen-toggle-value"
FPAT="/sys/devices/platform/backlight/backlight/backlight"
minbright=1;;
keyboard|[kK][eE][yY]*)
FTOG="/var/lib/pyra/keyboard-toggle-value"
FPAT="/sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight"
minbright=0;;
*) help "$0"
exit 1;;
esac
FCUR="$FPAT/actual_brightness"
FMAX="$FPAT/max_brightness"
FSET="$FPAT/brightness"
curbright="$(cat "$FCUR")"
maxbright="$(cat "$FMAX")"
newbright=$curbright
case "$2" in
set|[sS][eE][tT])
if [ ! $3 ]; then
newbright=$(zenity --scale --text "pick a number" "--min-value=$minbright" "--max-value=$maxbright" "--value=$curbright" --step 1);
else
newbright=$3
fi
elif [ $1 = "keyboard" ]; then
if [ $2 = "set" ]; then
minbright=0
maxbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/max_brightness)"
curbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/actual_brightness)"
if [ ! $3 ]; then
newbright=$(zenity --scale --text "pick a number" --min-value=$minbright --max-value=$maxbright --value=$curbright --step 1);
else
newbright=$3
fi
if [ $newbright ]; then
if [ $newbright -le $minbright ]; then newbright=$minbright; fi
if [ $newbright -ge $maxbright ]; then newbright=$maxbright; fi
echo $newbright > /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/brightness
fi
elif [ $2 = "up" ]; then
maxbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/max_brightness)"
curbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/actual_brightness)"
if [ ! $3 ]; then
if [ $curbright = $maxbright ]; then
newbright=$maxbright
else
newbright=$(($curbright+1))
fi
else
newbright=$(($curbright+$3))
if [ $newbright -gt $maxbright ]; then
newbright=$maxbright
fi
fi
echo $newbright > /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/brightness
elif [ $2 = "down" ]; then
if [ ! $newbright ]; then
exit 0
fi;;
up|[uU][pP])
if [ ! $3 ]; then
newbright=$(($curbright+1))
else
newbright=$(($curbright+$3))
fi;;
down|[dD][oO][wW][nN])
if [ ! $3 ]; then
newbright=$(($curbright-1))
else
newbright=$(($curbright-$3))
fi;;
toggle|[tT][oO][gG]*)
if [ $curbright = 0 ]; then
newbright="$( cat $FTOG)"
else
echo $curbright > $FTOG
minbright=0
curbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/actual_brightness)"
if [ ! $3 ]; then
if [ "$curbright" = "$minbright" ]; then
newbright=$minbright
else
newbright=$(($curbright-1))
fi
else
newbright=$(($curbright-$3))
if [ $newbright -lt $minbright ]; then
newbright=$minbright
fi
fi
echo $newbright > /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/brightness
elif [ $2 = "toggle" ]; then
curbright="$(cat /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/actual_brightness)"
if [ $curbright = 0 ]; then
newbright="$( cat /var/lib/pyra/keyboard-toggle-value)"
else
echo $curbright > /var/lib/pyra/keyboard-toggle-value
newbright=0
fi
echo $newbright > /sys/devices/platform/keyboard-backlight/backlight/keyboard-backlight/brightness
fi
fi
newbright=0
fi;;
*)
help "$0"
exit 1;;
esac
[ $newbright -le $minbright ] && newbright=$minbright
[ $newbright -ge $maxbright ] && newbright=$maxbright
echo $newbright > $FSET
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment