#!/bin/bash BRIGHTNESS_INCREMENT=.1 R_INCREMENT=0 G_INCREMENT=.1 B_INCREMENT=.2 xrandr_settings_of_display () { if [ "$#" -ne 1 ] ; then echo "Usage : xrandr_settings_of_display " >&2 exit 1 fi out="$(xrandr --verbose | sed -e "1,/^$1/d" | sed '/^ /,$d')" if [ -z "$out" ] ; then echo "ERROR, empty output for command: xrandr_settings_of_display $@" >&2 exit 1 fi echo "$out" } brigthness_of_display () { if [ "$#" -ne 1 ] ; then echo "Usage : brigthness_of_display " >&2 exit 1 fi xrandr_settings_of_display "$1" | grep -Po 'Brightness: \K.*' } raw_gamma_of_display () { if [ "$#" -ne 1 ] ; then echo "Usage : raw_gamma_of_display " >&2 exit 1 fi xrandr_settings_of_display "$1" | grep -Po 'Gamma: \K.*' | tr ':' ' ' } gamma_of_display () { if [ "$#" -ne 1 ] ; then echo "Usage : gamma_of_display " >&2 exit 1 fi read r g b <<< "$(raw_gamma_of_display "$1")" echo "$r $g $b -> $(invert $r) $(invert $g) $(invert $b)" >&2 echo "$(invert $r) $(invert $g) $(invert $b)" } invert () { if [ "$#" -ne 1 ] ; then echo "Usage : invert " >&2 exit 1 fi echo "1/$1" | bc -l | grep -o '.*\...' } ############### Args if [ "$#" -ne 2 ] ; then echo "Usage : $0 +|-|=" >&2 exit 1 fi property="$1" action="$2" if [ ! "$action" = - ] && [ ! "$action" = + ] && [ ! "$action" = '=' ] ; then echo "Bad action '$action'. Expected + - or =." exit 1 fi i=0 xrandr --listactivemonitors | tail -n +2 | cut -d ' ' -f 6 | while read monitor ; do args='' if [ "$i" -eq 0 ] ; then brightness="$(brigthness_of_display "$monitor")" read r g b <<< "$(gamma_of_display "$monitor")" ((i=i+1)) case "$property" in brightness) if [ "$action" = '=' ] ; then brightness=1 else brightness="$( echo "$brightness $action $BRIGHTNESS_INCREMENT" | bc -l )" fi ;; redness) if [ "$action" = '=' ] ; then r=1 g=1 b=1 else r="$( echo "$r $action $R_INCREMENT" | bc -l )" g="$( echo "$g $action $G_INCREMENT" | bc -l )" b="$( echo "$b $action $B_INCREMENT" | bc -l )" #echo "from $r:$g:$b to $rnew:$gnew:$bnew" fi ;; *) echo "Invalid property $property" exit 1 esac # Build command line args from variables args="--brightness $brightness --gamma $r:$g:$b" else args="--same-as $monitor" fi xrandr --output "$monitor" $args echo xrandr --output "$monitor" $args done