Skip to content

Instantly share code, notes, and snippets.

@jackinloadup
Created April 1, 2018 05:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jackinloadup/c98682416f0363b9a6c6d4daf13c6c32 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Smooth brightness control
readonly PROGNAME="$(basename "$0")"
readonly PROGDIR="$(readlink -m "$(dirname "$0")")"
readonly ARGS="$@"
function main {
export DISPLAY=$(who | grep ':' | awk '{print $2}')
local USER=$(who | grep ':' | awk '{print $1}')
local USER_ID=$(id -u lriutzel)
if [ -f run/user/$USER_ID/gdm/Xauthority ]; then
export XAUTHORITY=/run/user/$USER_ID/gdm/Xauthority
else
export XAUTHORITY=/home/$USER/.Xauthority
fi
OLED_BR=`xrandr --verbose | grep -i brightness | cut -f2 -d ' '`
CURR=`LC_ALL=C /usr/bin/printf "%.*f" 1 $OLED_BR`
MIN=0
MAX=1.2
if [ "$1" == "up" ]; then
VAL=`echo "scale=1; $CURR+0.1" | bc`
else
VAL=`echo "scale=1; $CURR-0.1" | bc`
fi
if (( `echo "$VAL < $MIN" | bc -l` )); then
VAL=$MIN
elif (( `echo "$VAL > $MAX" | bc -l` )); then
VAL=$MAX
else
if [ "$1" == "up" ]; then
for I in {1..10..1}; do xrandr --output eDP1 --brightness `echo "scale=2; $I/100+$CURR" | bc` 2>&1 >/dev/null | logger -t oled-brightness; done
else
for I in {1..10..1}; do xrandr --output eDP1 --brightness `echo "scale=2; $CURR-$I/100" | bc` 2>&1 >/dev/null | logger -t oled-brightness; done
fi
fi
# Set Intel backlight to fake value
# to sync OSD brightness indicator to actual brightness
INTEL_PANEL="/sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight"
if [ -d "$INTEL_PANEL" ]; then
PERCENT=`echo "scale=4; $VAL/$MAX" | bc -l`
INTEL_MAX=$(cat "$INTEL_PANEL/max_brightness")
INTEL_BRIGHTNESS=`echo "scale=4; $PERCENT*$INTEL_MAX" | bc -l`
INTEL_BRIGHTNESS=`LC_ALL=C /usr/bin/printf "%.*f" 0 $INTEL_BRIGHTNESS`
echo $INTEL_BRIGHTNESS > "$INTEL_PANEL/brightness"
fi
}
main $ARGS
@moutasem1989
Copy link

unfortunately, Xrandr is no longer supported on Chromium OS. are there any alternatives?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment