Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link

moutasem1989 commented May 6, 2019

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
You can’t perform that action at this time.